Skip to content

Instantly share code, notes, and snippets.

@elktros
Created March 27, 2021 14:37
Show Gist options
  • Save elktros/0a49ebb47a7415eb4cdf7d1c79cc5eab to your computer and use it in GitHub Desktop.
Save elktros/0a49ebb47a7415eb4cdf7d1c79cc5eab to your computer and use it in GitHub Desktop.
Code for Interfacing DHT11 with ESP32 and displaying result on I2C LCD.
#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#define DHT11PIN 16
DHT dht(DHT11PIN, DHT11);
LiquidCrystal_I2C lcd(0x3F, 16, 2);
byte degree_symbol[8] =
{
0b00111,
0b00101,
0b00111,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000
};
void setup()
{
/* Start the DHT11 Sensor */
dht.begin();
lcd.init();
lcd.backlight();
lcd.createChar(0, degree_symbol);
lcd.setCursor(0,0);
lcd.print(" DHT11 with ");
lcd.setCursor(0,1);
lcd.print(" ESP32 DevKit ");
delay(2000);
lcd.clear();
}
void loop()
{
int humi = dht.readHumidity();
float temp = dht.readTemperature();
lcd.setCursor(0,0);
lcd.print("Temp = ");
lcd.print(temp);
lcd.write(0);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("Humidity = ");
lcd.print(humi);
lcd.print("%");
delay(1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment