Advertisement
pleasedontcode

"Temperature Alert" rev_02

Jun 28th, 2024
691
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: "Temperature Alert"
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-06-28 19:33:05
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Read sensor and print on serial monitor */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <DS18B20.h>  //https://github.com/matmunk/DS18B20
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30.  
  31. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  32. const uint8_t Sensor_DS18B20_DQ_PIN_D4 = 4;
  33.  
  34. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  35. DS18B20 ds(Sensor_DS18B20_DQ_PIN_D4);  // Initialize DS18B20 object with the pin number
  36.  
  37. /****** GLOBAL VARIABLES *****/
  38. #define LOW_ALARM 20
  39. #define HIGH_ALARM 25
  40. uint8_t address[] = {40, 250, 31, 218, 4, 0, 0, 52};  // Example address
  41.  
  42. void setup(void) {
  43.   // put your setup code here, to run once:
  44.   Serial.begin(9600);
  45.   pinMode(Sensor_DS18B20_DQ_PIN_D4, INPUT);
  46.  
  47.   if (ds.select(address)) {
  48.     ds.setAlarms(LOW_ALARM, HIGH_ALARM);
  49.   } else {
  50.     Serial.println("Device not found!");
  51.   }
  52. }
  53.  
  54. void loop(void) {
  55.   // put your main code here, to run repeatedly:
  56.   if (ds.select(address)) {
  57.     if (ds.hasAlarm()) {
  58.       Serial.print("Warning! Temperature is ");
  59.       Serial.print(ds.getTempC());
  60.       Serial.println(" C");
  61.     } else {
  62.       Serial.print("Temperature is ");
  63.       Serial.print(ds.getTempC());
  64.       Serial.println(" C");
  65.     }
  66.   } else {
  67.     Serial.println("Device not found!");
  68.   }
  69.  
  70.   delay(10000);
  71. }
  72.  
  73. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement