Interfacing NodeMCU with DHT22 Sensor and ST7735 TFT

This post shows how to interface ESP8266 NodeMCU board (ESP-12E) with DHT22 (AM2302, RHT03) digital humidity and temperature sensor.
The NodeMCU microcontroller (ESP8266EX) reads temperature (in °C) & humidity (in rH%) values from the DHT22 sensor and print their values on ST7735 TFT display.
The ST7735 TFT used in this project is a color display which has a resolution of 128×160 pixel, it communicates with the master device using SPI protocol.

TFT: Thin-Film Transistor
SPI: Serial Peripheral Interface

To see how to interface the NodeMCU board with the ST7735 TFT display, visit this post:
Interfacing ESP8266 NodeMCU with ST7735 TFT

The DHT22 sensor has the following characteristics:

  • Humidity Range: 0 ~ 100% RH
  • Humidity Accuracy: ±2% RH (max ±5% RH)
  • Temperature Range: -40 ~ 80 °C
  • Temperature Accuracy: ±0.5 °C
  • Operating Voltage: 3.3V ~ 5.5V
  • Resolution = 0.1

Hardware Required:

  • NodeMCU development board
  • ST7735 TFT display module
  • DHT22 (AM2302, RHT03) humidity and temperature sensor   —->  datasheet
  • 4.7k ohm resistor
  • Micro USB cable (for programming and powering the whole circuit)
  • Breadboard
  • Jumper wires

NodeMCU with DHT22 sensor and ST7735 TFT display circuit:
Project circuit diagram is shown below.

The DHT22 sensor has 4 pins (from left to right):
Pin 1 is power supply pin, connected NodeMCU 3V3 pin,
Pin 2: data output pin, connected to NodeMCU digital pin 1 (D1),
Pin 3: not connected pin,
Pin 4: GND (ground), connected to NodeMCU GND pin.

A pull-up resistor of 4.7k ohm is required because the DHT22 sensor has an open drain output.

ESP8266 NodeMCU ST7735 DHT22 AM2302 RHT03 sensor circuit

The ST7735S shown in project circuit diagram has 8 pins: (from right to left): RST (reset), CE (chip enable), DC (or D/C: data/command), DIN (data in), CLK (clock), VCC, BL (back light) and Gnd (ground).

The ST7735 display is connected to the NodeMCU board as follows:
RST pin is connected to D4 (ESP8266EX GPIO2),
CS pin is connected to D3 (ESP8266EX GPIO0),
D/C pin is connected to D2 (ESP8266EX GPIO4),
DIN (MOSI) pin is connected to D7 (ESP8266EX GPIO13),
CLK (SCK) pin is connected to D5 (ESP8266EX GPIO14),
VCC and BL are connected to pin 3V3,
GND is connected to pin GND of the NodeMCU board.

Pins D5 (GPIO14) and D7 (GPIO13) are hardware SPI module pins of the ESP8266EX microcontroller respectively for SCK (serial clock) and MOSI (master-out slave-in).

NodeMCU with DHT22 sensor and ST7735 TFT display code:
The following Arduino code requires 3 libraries from Adafruit Industries:
The first library is a driver for the ST7735 TFT display, download link is below:
Adafruit ST7735 TFT library    —->  direct link

The 2nd library is Adafruit graphics library which can be downloaded from the following link
Adafruit graphics library             —->  direct link

The 3rd one is for the DHT22 sensor:
Adafruit DHT library                  —->   direct link

After the download, go to Arduino IDE —> Sketch —> Include Library —> Add .ZIP Library … and browse for the .zip file (previously downloaded).
The same thing for the other library files.

Hints:
The previous 3 libraries are included in the main code as follows:

The connection of ST7735 TFT display with the NodeMCU is as shown below where the display is connected to hardware SPI module of the NodeMCU (pins: SCK and MOSI):

Definition of sensor type, its data pin connection and the initialization of the DHT library:

Rest of code is described through comments.

Full Arduino code:

NodeMCU with ST7735S TFT and DHT22 sensor


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top