Advertisement
pleasedontcode

Temperature Monitor rev_01

Feb 29th, 2024
89
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: Arduino Uno
  14.     - Source Code created on: 2024-03-01 04:50:20
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Turn on the  red LED when D2 is above a threshold */
  21.     /* , turn on green LED when D2 is below a threshold. */
  22. /****** SYSTEM REQUIREMENT 2 *****/
  23.     /* take D2 readings once a day */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Wire.h>
  28. #include <LiquidCrystal_I2C.h> //https://github.com/marcoschwartz/LiquidCrystal_I2C
  29. #include <DS18B20.h> //https://github.com/matmunk/DS18B20
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t moistureSens_DS18B20_DQ_PIN_D2 = 2;
  37.  
  38. /***** DEFINITION OF LED PINS *****/
  39. const uint8_t redLED_PIN = 3;
  40. const uint8_t greenLED_PIN = 4;
  41.  
  42. /***** DEFINITION OF I2C PINS *****/
  43. const uint8_t LCD_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
  44. const uint8_t LCD_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
  45. const uint8_t LCD_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
  46.  
  47. /****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
  48. LiquidCrystal_I2C lcd(LCD_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Initialize LiquidCrystal_I2C object with LCD address, number of columns, and number of rows
  49. DS18B20 ds(moistureSens_DS18B20_DQ_PIN_D2); // Initialize DS18B20 object with DQ pin
  50.  
  51. /****** SYSTEM REQUIREMENTS *****/
  52. /****** SYSTEM REQUIREMENT 1 *****/
  53. const float LOW_ALARM = 20.0; // Low temperature threshold
  54. const float HIGH_ALARM = 25.0; // High temperature threshold
  55.  
  56. /****** SYSTEM REQUIREMENT 2 *****/
  57. const unsigned long READ_INTERVAL = 86400000; // Read temperature once a day (24 hours)
  58.  
  59. void setup(void)
  60. {
  61.   pinMode(moistureSens_DS18B20_DQ_PIN_D2, INPUT);
  62.   pinMode(redLED_PIN, OUTPUT);
  63.   pinMode(greenLED_PIN, OUTPUT);
  64.  
  65.   lcd.begin(16, 2);        // Initialize the LCD
  66.   lcd.setBacklight(HIGH);  // Turn on the backlight
  67.   lcd.clear();             // Clear the LCD screen
  68.   lcd.print("Hello World!"); // Print a message on the LCD screen
  69. }
  70.  
  71. void loop(void)
  72. {
  73.   // Read temperature once a day
  74.   delay(READ_INTERVAL);
  75.  
  76.   float temperature = ds.getTempC();
  77.  
  78.   // Check if temperature is above threshold
  79.   if (temperature > HIGH_ALARM)
  80.   {
  81.     digitalWrite(redLED_PIN, HIGH); // Turn on the red LED
  82.     digitalWrite(greenLED_PIN, LOW); // Turn off the green LED
  83.   }
  84.   // Check if temperature is below threshold
  85.   else if (temperature < LOW_ALARM)
  86.   {
  87.     digitalWrite(redLED_PIN, LOW); // Turn off the red LED
  88.     digitalWrite(greenLED_PIN, HIGH); // Turn on the green LED
  89.   }
  90.   // Temperature is within the threshold
  91.   else
  92.   {
  93.     digitalWrite(redLED_PIN, LOW); // Turn off the red LED
  94.     digitalWrite(greenLED_PIN, LOW); // Turn off the green LED
  95.   }
  96. }
  97.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement