// Arduino Mini Thermostat
// Made by: Vasco2020
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <DHT.h>
#include <RTClib.h>
#define DHTPIN 12 // digital pin for the DHT22 sensor
#define DHTTYPE DHT22 // DHT22 sensor
DHT dht(DHTPIN, DHTTYPE); // create a DHT object
RTC_DS1307 rtc; // create an RTC object
//LCD Stuff
LiquidCrystal_I2C lcd(0x27, 16, 2); //Display Resolution
void setup() {
Serial.begin(9600);
// start I2C communication
Wire.begin();
// start the DHT22 sensor
dht.begin();
// start the DS1307 RTC
rtc.begin();
// Start up the library
lcd.init(); //Start the display
lcd.backlight(); //Turn ON Display Light
}
void loop() {
// read the temperature and humidity from the DHT22 sensor
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
// check if the readTemperature() or readHumidity() functions returned a valid value
if (isnan(temperature) || isnan(humidity)) {
Serial.println("Error reading temperature or humidity from DHT22 sensor!");
return;
}
// read the time from the DS1307 RTC
DateTime now = rtc.now();
lcd.setCursor(0,0);
lcd.print("Time: ");
if (now.hour() <= 9) {
lcd.print("0");
};
lcd.print(now.hour());
lcd.print(":");
if (now.minute() <= 9) {
lcd.print("0");
};
lcd.print(now.minute());
lcd.print(":");
if (now.second() <= 9) {
lcd.print("0");
};
lcd.print(now.second());
// print the temperature, humidity, and time to the serial console
lcd.setCursor(0,1);
lcd.print("Temp: ");
lcd.print(temperature);
lcd.print("C ");
delay(100);
}