Advertisement
pleasedontcode

"Smart Thermostat" rev_01

Nov 3rd, 2024
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Smart Thermostat"
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-11-03 08:12:39
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Auto matic light ofg */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <DS18B20.h>    //https://github.com/matmunk/DS18B20
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29.  
  30. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  31. const uint8_t Pratham_DS18B20_DQ_PIN_D2     = 2; // Data pin for DS18B20
  32. const uint8_t LIGHT_PIN = 13; // Define the pin for the automatic light (LED)
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. // Create an instance of the DS18B20 class
  36. DS18B20 ds(Pratham_DS18B20_DQ_PIN_D2);
  37.  
  38. // Define alarm temperature thresholds
  39. #define LOW_ALARM 20
  40. #define HIGH_ALARM 25
  41.  
  42. // Define the address of the DS18B20 sensor
  43. uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};
  44.  
  45. void setup(void)
  46. {
  47.     // Initialize serial communication at 9600 baud rate
  48.     Serial.begin(9600);
  49.    
  50.     // Set the data pin mode for the DS18B20 sensor
  51.     pinMode(Pratham_DS18B20_DQ_PIN_D2, INPUT);
  52.    
  53.     // Set the light pin mode as output
  54.     pinMode(LIGHT_PIN, OUTPUT);
  55.     digitalWrite(LIGHT_PIN, LOW); // Ensure the light is off initially
  56.  
  57.     // Select the DS18B20 device using its address
  58.     if (ds.select(address)) {
  59.         // Set alarm thresholds for the temperature sensor
  60.         ds.setAlarms(LOW_ALARM, HIGH_ALARM);
  61.     } else {
  62.         // Print an error message if the device is not found
  63.         Serial.println("Device not found!");
  64.     }
  65. }
  66.  
  67. void loop(void)
  68. {
  69.     // Check if the DS18B20 device is selected
  70.     if (ds.select(address)) {
  71.         // Check if the temperature alarm has been triggered
  72.         if (ds.hasAlarm()) {
  73.             // Print a warning message with the current temperature
  74.             Serial.print("Warning! Temperature is ");
  75.             Serial.print(ds.getTempC());
  76.             Serial.println(" C");
  77.            
  78.             // Turn on the light (LED) if the temperature exceeds the high alarm threshold
  79.             if (ds.getTempC() > HIGH_ALARM) {
  80.                 digitalWrite(LIGHT_PIN, HIGH); // Turn on the light
  81.             }
  82.         } else {
  83.             // Turn off the light if the temperature is within the safe range
  84.             digitalWrite(LIGHT_PIN, LOW); // Turn off the light
  85.         }
  86.     } else {
  87.         // Print an error message if the device is not found
  88.         Serial.println("Device not found!");
  89.     }
  90.  
  91.     // Wait for 10 seconds before the next loop iteration
  92.     delay(10000);
  93. }
  94.  
  95. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement