/********* 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: Temperature Monitor
- Source Code compiled for: Arduino Uno
- Source Code created on: 2024-03-01 04:50:20
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* Turn on the red LED when D2 is above a threshold */
/* , turn on green LED when D2 is below a threshold. */
/****** SYSTEM REQUIREMENT 2 *****/
/* take D2 readings once a day */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include //https://github.com/marcoschwartz/LiquidCrystal_I2C
#include //https://github.com/matmunk/DS18B20
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL INPUT PINS *****/
const uint8_t moistureSens_DS18B20_DQ_PIN_D2 = 2;
/***** DEFINITION OF LED PINS *****/
const uint8_t redLED_PIN = 3;
const uint8_t greenLED_PIN = 4;
/***** DEFINITION OF I2C PINS *****/
const uint8_t LCD_LCD1602I2C_I2C_PIN_SDA_A4 = A4;
const uint8_t LCD_LCD1602I2C_I2C_PIN_SCL_A5 = A5;
const uint8_t LCD_LCD1602I2C_I2C_SLAVE_ADDRESS = 39;
/****** DEFINITION OF LIBRARY CLASS INSTANCES*****/
LiquidCrystal_I2C lcd(LCD_LCD1602I2C_I2C_SLAVE_ADDRESS, 16, 2); // Initialize LiquidCrystal_I2C object with LCD address, number of columns, and number of rows
DS18B20 ds(moistureSens_DS18B20_DQ_PIN_D2); // Initialize DS18B20 object with DQ pin
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
const float LOW_ALARM = 20.0; // Low temperature threshold
const float HIGH_ALARM = 25.0; // High temperature threshold
/****** SYSTEM REQUIREMENT 2 *****/
const unsigned long READ_INTERVAL = 86400000; // Read temperature once a day (24 hours)
void setup(void)
{
pinMode(moistureSens_DS18B20_DQ_PIN_D2, INPUT);
pinMode(redLED_PIN, OUTPUT);
pinMode(greenLED_PIN, OUTPUT);
lcd.begin(16, 2); // Initialize the LCD
lcd.setBacklight(HIGH); // Turn on the backlight
lcd.clear(); // Clear the LCD screen
lcd.print("Hello World!"); // Print a message on the LCD screen
}
void loop(void)
{
// Read temperature once a day
delay(READ_INTERVAL);
float temperature = ds.getTempC();
// Check if temperature is above threshold
if (temperature > HIGH_ALARM)
{
digitalWrite(redLED_PIN, HIGH); // Turn on the red LED
digitalWrite(greenLED_PIN, LOW); // Turn off the green LED
}
// Check if temperature is below threshold
else if (temperature < LOW_ALARM)
{
digitalWrite(redLED_PIN, LOW); // Turn off the red LED
digitalWrite(greenLED_PIN, HIGH); // Turn on the green LED
}
// Temperature is within the threshold
else
{
digitalWrite(redLED_PIN, LOW); // Turn off the red LED
digitalWrite(greenLED_PIN, LOW); // Turn off the green LED
}
}