Advertisement
pleasedontcode

"Temperature Monitor" rev_01

Mar 24th, 2024
46
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 Monitor"
  13.     - Source Code compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2024-03-25 02:46:26
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* // ### LOAD REQUIRED ARDUINO LIBRARIES ### */
  21.     /* #include <OneWire.h> // Library by&nbsp;Jim Studt */
  22.     /* etc. #include <DallasTemperature.h> // Library */
  23.     /* by&nbsp;Miles Burton etc.  // ### INITIALISE ### */
  24.     /* // ## INITIALISE ONE WIRE BU ## // Define pin D5 */
  25.     /* of the Ardui */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <OneWire.h> // Library by Jim Studt
  30. #include <DallasTemperature.h> // Library by Miles Burton
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t temp_DS18B20_DQ_PIN_D5 = 5; // Change the pin to D5
  38.  
  39. /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
  40. OneWire oneWire(temp_DS18B20_DQ_PIN_D5); // Initialize the OneWire object
  41. DallasTemperature sensors(&oneWire); // Initialize the DallasTemperature object
  42.  
  43. /****** DEFINITION OF TEMPERATURE ALARM THRESHOLDS *****/
  44. const int LOW_ALARM = 20; // Set the low temperature alarm threshold
  45. const int HIGH_ALARM = 25; // Set the high temperature alarm threshold
  46.  
  47. void setup(void)
  48. {
  49.   // put your setup code here, to run once:
  50.   Serial.begin(9600); // Initialize Serial communication
  51.  
  52.   sensors.begin(); // Initialize the DallasTemperature library
  53.  
  54.   // Get the address of the sensor
  55.   DeviceAddress address;
  56.   sensors.getAddress(address, 0);
  57.  
  58.   // Set the high and low temperature alarms
  59.   sensors.setHighAlarmTemp(address, HIGH_ALARM);
  60.   sensors.setLowAlarmTemp(address, LOW_ALARM);
  61. }
  62.  
  63. void loop(void)
  64. {
  65.   // put your main code here, to run repeatedly:
  66.   sensors.requestTemperatures(); // Send the command to read temperatures
  67.  
  68.   float temperatureC = sensors.getTempCByIndex(0); // Read the temperature in Celsius
  69.  
  70.   if (sensors.hasAlarm())
  71.   {
  72.     Serial.print("Warning! Temperature is ");
  73.     Serial.print(temperatureC);
  74.     Serial.println(" C");
  75.   }
  76.  
  77.   delay(10000); // Wait for 10 seconds
  78. }
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement