Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: "Smart Thermostat"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-11-03 08:12:39
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* Auto matic light ofg */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <DS18B20.h> //https://github.com/matmunk/DS18B20
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t Pratham_DS18B20_DQ_PIN_D2 = 2; // Data pin for DS18B20
- const uint8_t LIGHT_PIN = 13; // Define the pin for the automatic light (LED)
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of the DS18B20 class
- DS18B20 ds(Pratham_DS18B20_DQ_PIN_D2);
- // Define alarm temperature thresholds
- #define LOW_ALARM 20
- #define HIGH_ALARM 25
- // Define the address of the DS18B20 sensor
- uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};
- void setup(void)
- {
- // Initialize serial communication at 9600 baud rate
- Serial.begin(9600);
- // Set the data pin mode for the DS18B20 sensor
- pinMode(Pratham_DS18B20_DQ_PIN_D2, INPUT);
- // Set the light pin mode as output
- pinMode(LIGHT_PIN, OUTPUT);
- digitalWrite(LIGHT_PIN, LOW); // Ensure the light is off initially
- // Select the DS18B20 device using its address
- if (ds.select(address)) {
- // Set alarm thresholds for the temperature sensor
- ds.setAlarms(LOW_ALARM, HIGH_ALARM);
- } else {
- // Print an error message if the device is not found
- Serial.println("Device not found!");
- }
- }
- void loop(void)
- {
- // Check if the DS18B20 device is selected
- if (ds.select(address)) {
- // Check if the temperature alarm has been triggered
- if (ds.hasAlarm()) {
- // Print a warning message with the current temperature
- Serial.print("Warning! Temperature is ");
- Serial.print(ds.getTempC());
- Serial.println(" C");
- // Turn on the light (LED) if the temperature exceeds the high alarm threshold
- if (ds.getTempC() > HIGH_ALARM) {
- digitalWrite(LIGHT_PIN, HIGH); // Turn on the light
- }
- } else {
- // Turn off the light if the temperature is within the safe range
- digitalWrite(LIGHT_PIN, LOW); // Turn off the light
- }
- } else {
- // Print an error message if the device is not found
- Serial.println("Device not found!");
- }
- // Wait for 10 seconds before the next loop iteration
- delay(10000);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement