ESP32 C3 Super Mini - DHT22 - LCD

This tutorial shows you how to use the ESP32 C3 Super Mini to read temperature and humidity from a DHT22 sensor and show them on an LCD I2C. It is a simple, friendly project, and you can read the room climate with no computer attached.

In this tutorial, you'll learn:

ESP32 C3 Super Mini - DHT22 - LCD

Hardware Preparation

1×ESP32 C3 Super Mini
1×USB Cable Type-A to Type-C (for USB-A PC)
1×USB Cable Type-C to Type-C (for USB-C PC)
1×LCD I2C Display 3.3V
1×DHT22 Temperature and Humidity Sensor
1×Alternatively, DHT22 Sensor
1×Breadboard
1×Jumper Wires
1×Optionally, DC Power Jack

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Buy Note: Most LCD I2C displays available on the market are 5V displays. They may work with this board, but it is unsafe and can damage the board. We strongly recommend using the 3.3V LCD I2C display recommended above.

Overview of DHT22 and LCD

The DHT22 is a digital sensor that measures temperature and humidity, and the LCD I2C is a display that shows text using only two data wires.

Key Features:

  • DHT22: Gives temperature and humidity over one data wire
  • LCD I2C: Shows 2 rows of text with 16 characters in each row
  • Few wires: The project uses only 3 signal wires in total

Technical Specifications:

  • DHT22 power: 3V to 5V
  • Humidity range: 0% to 100%, with ± 2% to 5% accuracy
  • Temperature range: -40°C to 80°C, with ± 0.5°C accuracy
  • Reading rate: One reading every 2 seconds
  • LCD I2C power: 5V
  • LCD I2C address: Usually 0x27 or 0x3F, depending on the manufacturer

We have a full tutorial for each part, with the pinout, how it works, wiring and code:

Pinout

The DHT22 module has 3 pins and the LCD I2C has 4 pins.

DHT22 module:

  • VCC (or +): Connect to 3.3V power
  • GND (or -): Connect to ground (0V)
  • DATA (or OUT): Sends the temperature and humidity readings to the board

LCD I2C:

  • VCC: Connect to 5V power
  • GND: Connect to ground (0V)
  • SDA: I2C data signal
  • SCL: I2C clock signal

Wiring Diagram

Connect both parts to the ESP32 C3 Super Mini as shown below.

  • Note: Unplug the USB cable before you change any wire.
  • Note: The DHT22 uses 3.3V, the LCD uses 5V, and both share the same GND.
The wiring diagram between ESP32 C3 Super Mini DHT22 LCD I2C

This image is created using Fritzing. Click to enlarge image

You can also build this circuit without a breadboard. Here is the same wiring:

The wiring diagram between ESP32 C3 Super Mini DHT22 LCD I2C  (No Breadboard)

This image is created using Fritzing. Click to enlarge image

DHT22 Pin ESP32 C3 Super Mini Pin
VCC 3.3V
GND GND
DATA GPIO4
LCD I2C Pin ESP32 C3 Super Mini Pin
VCC 5V
GND GND
SDA GPIO8
SCL GPIO9

ESP32 C3 Super Mini Code - DHT22 Sensor - LCD I2C

The code below reads the DHT22 sensor and shows temperature and humidity on the LCD.

What This Code Does:

  • Uses I2C: The LCD uses the default I2C pins of the board: GPIO8 (SDA) and GPIO9 (SCL)
  • Starts the parts: Starts the DHT22 on GPIO4 and turns on the LCD backlight
  • Reads the sensor: Gets the humidity and the temperature in Celsius
  • Shows the result: Prints temperature on row 1 and humidity on row 2
  • Handles errors: Shows "Failed" on the LCD if a reading does not work, and waits 2 seconds between readings
/* * This ESP32 C3 Super Mini code was developed by newbiely.com * * This ESP32 C3 Super Mini code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/esp32-c3/esp32-c3-super-mini-dht22-lcd */ #include <DHT.h> #include <DIYables_LCD_I2C.h> #define DHT22_PIN 4 // The ESP32 C3 SuperMini pin connected to DHT22 sensor DIYables_LCD_I2C lcd(0x27, 16, 2); // I2C address 0x27 (from DIYables LCD), 16 column and 2 rows DHT dht22(DHT22_PIN, DHT22); void setup() { dht22.begin(); // initialize the DHT22 sensor lcd.init(); // initialize the lcd lcd.backlight(); // open the backlight } void loop() { float humidity = dht22.readHumidity(); // read humidity float temperature = dht22.readTemperature(); // read temperature lcd.clear(); // check whether the reading is successful or not if (isnan(temperature) || isnan(humidity)) { lcd.setCursor(0, 0); lcd.print("Failed"); } else { lcd.setCursor(0, 0); // display position lcd.print("Temp: "); lcd.print(temperature); // display the temperature lcd.print((char)223); // display ° character lcd.print("C"); lcd.setCursor(0, 1); // display position lcd.print("Humi: "); lcd.print(humidity); // display the humidity lcd.print("%"); } // wait a 2 seconds between readings delay(2000); }

※ NOTE THAT:

The LCD I2C address can be different from each manufacturer. In the code, we used address of 0x27 that is specified by DIYables manufacturer

Detailed Instructions

Follow these bullets to run the project.

  • New to ESP32 C3 Super Mini? Complete our Getting Started with ESP32 C3 Super Mini tutorial first to set up your development environment.
  • Wire the parts: Connect the parts as shown in the wiring diagram.
  • Connect your board: Plug the ESP32 C3 Super Mini into your computer with a USB Type-C cable.
  • Open the IDE: Launch the Arduino IDE on your computer.
  • Select your board: Make sure ESP32 C3 Super Mini is selected in Tools > Board.
  • Select your port: Choose the matching COM port.
  • Open the Library Manager: Click the Libraries icon on the left bar of the Arduino IDE.
  • Search for the DHT library: Type “DHT” in the search box, then look for the DHT sensor library by Adafruit.
  • Install the DHT library: Click the Install button.
ESP32 C3 Super Mini DHT sensor library
  • Install the dependencies: A window asks you to install the dependencies for the library. Click the Install All button.
ESP32 C3 Super Mini Adafruit Unified sensor library
  • Search for the LCD library: Type “DIYables LCD I2C” in the search box, then look for the DIYables_LCD_I2C library by DIYables.
  • Install the LCD library: Click the Install button.
ESP32 C3 Super Mini DIYables LCD I2C library
  • Copy the code: Copy the code above and paste it into the Arduino IDE.
  • Upload the code: Click the Upload button to compile and upload the code to your ESP32 C3 Super Mini.
  • Test it: Make the sensor colder or hotter. For example, put the sensor near a hot cup of coffee.
  • See the result: Watch the temperature and humidity change on the LCD.
  • Pro Tip: If the LCD backlight is on but you see no text, turn the small contrast screw on the back of the LCD.

If LCD displays nothing, see Troubleshooting on LCD I2C

Line-by-line Code Explanation

The above ESP32 C3 Super Mini code contains line-by-line explanation. Please read the comments in the code!

Application and Project Ideas

You can use this ESP32 C3 Super Mini DHT22 LCD project as the base for many useful builds.

  • Room climate display: Show the temperature and humidity of a room on your desk
  • Greenhouse monitor: Check the air around your plants at a glance
  • Baby room monitor: Keep an eye on the climate in a nursery
  • Storage check: Watch humidity in a closet or a tool box
  • Incubator display: Show the conditions inside a small egg incubator
  • Pet home monitor: Show the climate inside a reptile tank

Challenge Yourself

Ready to do more with your ESP32 C3 Super Mini and LCD? Try these challenges.

  • Easy: Show the temperature in Fahrenheit instead of Celsius
  • Easy: Change the delay to read the DHT22 every 5 seconds
  • Medium: Show "Too hot!" on the second row when the temperature is above 30°C
  • Medium: Add a button that turns the LCD backlight on and off
  • Advanced: Show the lowest and highest temperature since the board started
  • Advanced: Average several readings to make the numbers on the LCD more stable

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!