#include <Wire.h>
#include <RTClib.h>
#include <DHT.h>
#include <LiquidCrystal.h>
#define DHTPIN1 2 // Pin where the first DHT sensor is connected
#define DHTPIN2 3 // Pin where the second DHT sensor is connected
#define DHTTYPE DHT22 // Both are DHT22 sensors
RTC_DS1307 rtc;
DHT dht1(DHTPIN1, DHTTYPE);
DHT dht2(DHTPIN2, DHTTYPE);
LiquidCrystal lcd(12, 11, 10, 9, 8, 7); // Pins for the LCD
void setup() {
Serial.begin(9600);
lcd.begin(20, 4); // Initialize the LCD
dht1.begin(); // Initialize the first DHT sensor
dht2.begin(); // Initialize the second DHT sensor
if (!rtc.begin()) {
Serial.println("Couldn't find RTC");
while (1);
}
if (!rtc.isrunning()) {
Serial.println("RTC is NOT running, let's set the time!");
rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // Set the RTC to the date & time this sketch was compiled
}
}
void loop() {
DateTime now = rtc.now(); // Get current time
float h1 = dht1.readHumidity(); // Read humidity from the first sensor
float t1C = dht1.readTemperature(); // Read temperature from the first sensor in Celsius
float t1F = t1C * 1.8 + 32; // Convert Celsius to Fahrenheit
float h2 = dht2.readHumidity(); // Read humidity from the second sensor
float t2C = dht2.readTemperature(); // Read temperature from the second sensor in Celsius
float t2F = t2C * 1.8 + 32; // Convert Celsius to Fahrenheit
if (isnan(h1) || isnan(t1C) || isnan(h2) || isnan(t2C)) {
Serial.println("Failed to read from DHT sensor(s)!");
return;
}
lcd.clear();
lcd.setCursor(5, 0); // Display the date and time
lcd.print(now.year(), DEC);
lcd.print('/');
lcd.print(now.month(), DEC);
lcd.print('/');
lcd.print(now.day(), DEC);
lcd.setCursor(7, 1);
lcd.print(now.hour(), DEC);
lcd.print(':');
lcd.print(now.minute(), DEC);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0); // Display temperature and humidity from the first sensor
lcd.print("T1: ");
lcd.print(t1F);
lcd.print(" F");
lcd.setCursor(0, 1);
lcd.print("H1: ");
lcd.print(h1);
lcd.print(" %");
delay(5000);
lcd.clear();
lcd.setCursor(0, 0); // Display temperature and humidity from the second sensor
lcd.print("T2: ");
lcd.print(t2F);
lcd.print(" F");
lcd.setCursor(0, 1);
lcd.print("H2: ");
lcd.print(h2);
lcd.print(" %");
delay(5000);
}