Arduino Projects – LCD Temperature/ Humidity Alert with Timestamp (DHT11, DS3231, I2C 20×4 LCD)

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:

Libraries:

Functional Parts in the Project:

#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

Leave a Reply