#include <DHT.h>
#include <LiquidCrystal_I2C.h>
#define DHT_SENSOR_PIN 15 // ESP32 pin GIOP23 connected to DHT22 sensor
#define DHT_SENSOR_TYPE DHT22
LiquidCrystal_I2C lcd(0x3F, 16, 2); // I2C address 0x3F, 16 column and 2 rows
DHT dht_sensor(DHT_SENSOR_PIN, DHT_SENSOR_TYPE);
void setup() {
dht_sensor.begin(); // initialize the DHT sensor
lcd.init(); // initialize the lcd
lcd.backlight(); // open the backlight
}
void loop() {
float humi = dht_sensor.readHumidity(); // read humidity
float tempC = dht_sensor.readTemperature(); // read temperature
lcd.clear();
// check whether the reading is successful or not
if (isnan(tempC) || isnan(humi)) {
lcd.setCursor(0, 0);
lcd.print("Failed");
} else {
lcd.setCursor(0, 0); // display position
lcd.print("Temp: ");
lcd.print(tempC); // display the temperature
lcd.print("°C");
lcd.setCursor(0, 1); // display position
lcd.print("Humi: ");
lcd.print(humi); // display the humidity
lcd.print("%");
}
// wait a 2 seconds between readings
delay(2000);
}
esp:VIN
esp:GND.2
esp:D13
esp:D12
esp:D14
esp:D27
esp:D26
esp:D25
esp:D33
esp:D32
esp:D35
esp:D34
esp:VN
esp:VP
esp:EN
esp:3V3
esp:GND.1
esp:D15
esp:D2
esp:D4
esp:RX2
esp:TX2
esp:D5
esp:D18
esp:D19
esp:D21
esp:RX0
esp:TX0
esp:D22
esp:D23
dht1:VCC
dht1:SDA
dht1:NC
dht1:GND
lcd1:GND
lcd1:VCC
lcd1:SDA
lcd1:SCL