ESP8266 NodeMCU with ST7735 TFT and DHT11 Sensor

This post shows how to interface ESP8266 NodeMCU board (ESP-12E) with DHT11 (RHT01) digital humidity and temperature sensor.
The NodeMCU reads temperature (in °C) & humidity (in rH%) values from the DHT11 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

There are two types of the DHT11 sensor: old type (AOSONG) and new type (ASAIR). The differences between the 2 types are summarized below:


Seeed Studio provides a good module of the new DHT11 sensor (ASAIR version) named “Grove Temperature & Humidity Sensor”, more details in its official page:
Grove Temperature & Humidity Sensor

Hardware Required:

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

NodeMCU with ST7735 TFT and DHT11 sensor circuit:
The image below shows project circuit diagram.

The DHT11 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 DHT11 sensor has an open drain output.

ESP8266 NodeMCU ST7735 DHT11 RHT01 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 ST7735 TFT and DHT11 sensor 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 DHT11 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.

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 DHT11 sensor

One comment

  1. Hi,
    When I compile it on Arduino, I get the following error message. Why is this happening? My Arduino IDE version is 1.8.5 and the libraries are up to date (Adafruits).

    sketch_mar13b:68: error: ‘class Adafruit_ST7735’ has no member named ‘printf’

    tft.printf(“-%02u.%1u”, (abs(Temp)/10)%100, abs(Temp) % 10);

Leave a Reply

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