This project shows the Date, Time, Temperature, Humidity and Alerts you when the temperature breaks a threshold and gives you a timestamp of highest temperature reached.
Prerequisite Classes:
- Arduino – I2C 20 x 4 LCD Display
- Arduino Modules – Real Time Clock Setup (DS3231)
- Arduino Sensors – DHT11 Temperature/ Humidity Sensor Setup
Libraries:
- New Liquid Crystal Library – https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/Home
- Liquid Crystal I2C Library – https://www.arduinolibraries.info/libraries/liquid-crystal-i2-c
- Adafruit DHT Library – https://github.com/adafruit/DHT-sensor-library
- DS3231 Library – http://www.rinkydinkelectronics.com/library.php?id=73
Functional Parts in the Project:
- Arduino Uno – https://store.arduino.cc/usa/arduino-uno-rev3
- 20 x 4 I2C LCD Screen – https://amzn.to/2JVuKzn
- 560 Piece Jumper Wire Kit – https://amzn.to/2MsCLjL
- DHT11 Sensor – https://amzn.to/3fUOqST
- Breadboard Kit – https://amzn.to/2Xih5ei
- DS3231 Clock Modules – https://amzn.to/3brhqyd
- 3V Batteries – https://amzn.to/360DIGa
#include <DHT.h>
#include <DS3231.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
//Configure DHT11 Sensor
#define DHTPIN 2
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE);
//Configure I2C 20x4 LCD Display
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7);
//Configure DS321 Real Time Clock
DS3231 rtc(6, 7);
//Temp Variables
float maxTemp = 80;
int alert = 0;
float alertTemp;
String alertTime;
void setup()
{
//Start LCD Screen
lcd.begin(20, 4);
lcd.setBacklightPin(3, POSITIVE);
lcd.setBacklight(HIGH);
//Start Temperature Sensor
dht.begin();
//Start Clock
rtc.begin();
//The following lines can be uncommented to set the date and time
//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY
//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)
//rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014
}
void loop()
{
//2 Second Delay to Allow DHT11 to Calibrate
delay(2000);
//Is Temp above maxTemp? If So Set alertTemp to Highest Temp Value reached with Timestamp
if (dht.readTemperature(true) > maxTemp) {
alert = 1;
if (dht.readTemperature(true) > alertTemp) {
alertTemp = dht.readTemperature(true);
alertTime = rtc.getTimeStr();
}
}
//Standard LCD Print Out
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(rtc.getDOWStr());
lcd.setCursor(10,0);
lcd.print(rtc.getDateStr());
lcd.setCursor(6, 1);
lcd.print(rtc.getTimeStr());
lcd.setCursor(0, 2);
lcd.print("Temp ");
lcd.setCursor(5, 2);
lcd.print(dht.readTemperature(true));
lcd.setCursor(11, 2);
lcd.print("Hum ");
lcd.setCursor(15, 2);
lcd.print(dht.readHumidity());
//LCD Print Out Alert if maxTemp is Passed
if (alert == 1) {
lcd.setCursor(0, 3);
lcd.print("ALERT");
lcd.setCursor(6, 3);
lcd.print(alertTemp);
lcd.setCursor(12, 3);
lcd.print(alertTime);
}
}
Be the first to comment