#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <LiquidCrystal.h>
#include <RTClib.h>
#include <DHT.h>
#define DHTPIN 2 // Pin where the DHT22 is connected
#define DHTTYPE DHT22 // Type of DHT sensor
#define LEDRED 9
LiquidCrystal_I2C lcd(0x27, 20, 4); // Address for the LCD I2C module may vary
RTC_DS1307 rtc;
DHT dht(DHTPIN, DHTTYPE);
//custom text
byte degree[8] = {
B00110,
B01001,
B01001,
B00110,
B00000,
B00000,
B00000,
B00000
};
void setup() {
lcd.init(); // Initialize LCD
lcd.backlight(); // Turn on backlight
pinMode(LEDRED, OUTPUT);
Wire.begin();
rtc.begin();
dht.begin();
lcd.createChar(0, degree);
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running!");
// Uncomment the following line if you need to set the time
// rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
}
}
void loop() {
DateTime now = rtc.now(); // Get current time
// Print time in 12-hour format
lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.print(now.hour() > 12 ? now.hour() - 12 : now.hour()); // Convert to 12-hour format
lcd.print(':');
if (now.minute() < 10) lcd.print('0'); // Add leading zero for single-digit minutes
lcd.print(now.minute());
lcd.print(':');
if (now.second() < 10) lcd.print('0'); // Add leading zero for single-digit seconds
lcd.print(now.second());
lcd.print(' ');
lcd.print(now.hour() >= 12 ? "GABI" : "UMAGA"); // Print AM or PM based on the hour
// Read temperature from DHT22 sensor
float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
//Temperature
lcd.setCursor(0, 2);
lcd.print("Temperature: ");
lcd.print(temperature); // Print temperature as whole number
lcd.write(byte(0));
lcd.print(" ");
lcd.print("C"); // Celsius sign
//Humidity
lcd.setCursor(0, 3);
lcd.print("Humidity: ");
lcd.print(humidity); // Print temperature w/ decimal
//lcd.print(int(humidity)); // Print temperature as whole number
lcd.print(" ");
lcd.print("%"); // percent sign
// Print the day of the week in Tagalog
lcd.setCursor(0, 1);
switch (now.dayOfTheWeek()) {
case 1:
lcd.print("LUNES");
break;
case 2:
lcd.print("MARTES");
break;
case 3:
lcd.print("MIYERKULES");
break;
case 4:
lcd.print("HUWEBES");
break;
case 5:
lcd.print("BIYERNES");
break;
case 6:
lcd.print("SABADO");
break;
case 7:
lcd.print("LINGGO");
break;
}
if(temperature >= 41){
digitalWrite(LEDRED, HIGH); // turn the LED on (HIGH is the voltage level)
}
if(temperature <= 40.9){
digitalWrite(LEDRED, LOW); // turn the LED on (HIGH is the voltage level)
}
// Print the date (month and day)
lcd.print(' ');
if (now.month() < 10) lcd.print('0'); // Add leading zero for single-digit months
lcd.print(now.month());
lcd.print('/');
if (now.day() < 10) lcd.print('0'); // Add leading zero for single-digit days
lcd.print(now.day());
lcd.print('/');
if (now.year() < 10) lcd.print('0'); // Add leading zero for single-digit days
lcd.print(now.year());
delay(1000); // Delay for 1 second
}