#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DHT.h>
//SDA Pin 2
const int DHT_PIN = 2;
const int DHT_TYPE = DHT22;
DHT dht(DHT_PIN, DHT_TYPE);
//SDA Pin A4 and SCL Pin A5
// initialize the first LCD using the default address (0x27)
LiquidCrystal_I2C lcd1(0x27, 16, 2);
//SDA Pin A4 and SCL Pin A5
// initialize the second LCD using a different address (0x3F)
LiquidCrystal_I2C lcd2(0x25, 16, 2);
void setup() {
// start the serial communication at 9600 bits per second:
Serial.begin(9600);
// initialize the DHT sensor:
dht.begin();
// initialize the first LCD:
lcd1.init();
lcd1.backlight();
// initialize the second LCD:
lcd2.init();
lcd2.backlight();
}
void loop() {
// read the temperature from the DHT sensor:
float temperature = dht.readTemperature();
// read the humidity from the DHT sensor:
float humidity = dht.readHumidity();
// Check if any reads failed and exit early (to try again).
if (isnan(temperature) || isnan(humidity)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
Serial.print(F("Humidity: "));
Serial.print(humidity);
Serial.print(F("% Temperature: "));
Serial.print(temperature);
Serial.println(F(" C"));
// display the temperature on the first LCD:
lcd1.clear();
lcd1.setCursor(0, 0);
lcd1.print("Temp: ");
lcd1.print(temperature);
lcd1.print("C");
// display the humidity on the second LCD:
lcd2.clear();
lcd2.setCursor(0, 0);
lcd2.print("Humidity: ");
lcd2.print(humidity);
lcd2.print("%");
// wait for 2 seconds:
delay(2000);
}