Overview
The DHT-11 is a environmental sensor capable of converting surrounding temperature and humidity. It is a digital sensor, implementing the One-Wire communication protocol. The master micro-controller just need on digital I/O pin to command and get sensor data from this device. Its One-Wire data packet is very easy decode using a simple 8-bit micro-controller. The data packet is 40-bit or 5 bytes, containing two bytes of temperature data, two bytes of humidity data, and one byte of error correction.
![]() |
| Sensor Data Reading |
This sensor is very low cost, widely available. It's popular among Arduino users, mini projects, etc. Using this sensor in agricultural or home garden is very popular. However it is not durable due to surrounding environment.
Arduino DHT Sensor Library
Adafruit has a lot of libraries and examples for their products. However I didn't buy any products. Some sensor are compatible in software. Install the DHT sensor library and open its example, DHTTester.ino sketch as shown below.

Open the DHTTester.ino Sketch
This example the master MCU will read the environmental data from DHT sensor. It support DHT11, DTH-21, and DHT-22. However some pins of the ESP-12E board doesn't work with this sensor because they are connected to other devices or have alternative function such as TWI, UART, etc.
ESP8266 Interfaces with DHT-11 Sensor and SH1106 OLED
I use this example, and added some OLED display function to read and display environmental data and the SH0016 124x64 OLED module. I use pin D3 of the ESP-12E module since other pin doesn't work with this one-wire sensor. You can test it by yourself.
It needs these libraries,
- DHT
- Wire
- Adafruit_GFX
- Adafruit_SH110X
- Adafruit_Sensor
Arduino Source Code
- #include "DHT.h"
- #include <Wire.h>
- #include <Adafruit_GFX.h>
- #include <Adafruit_SH110X.h>
- #define i2c_Address 0x3c
- /*initialize with the I2C addr 0x3D
- Typically Adafruit OLED's */
- //#define i2c_Address 0x3d
- #define SCREEN_WIDTH 128
- #define SCREEN_HEIGHT 64
- #define OLED_RESET -1
- Adafruit_SH1106G display =
- Adafruit_SH1106G
- (SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);
- // Digital pin connected to the DHT sensor
- #define DHTPIN D3
- #define DHTTYPE DHT11 // DHT 11
- DHT dht(DHTPIN, DHTTYPE);
- void setup() {
- // wait for the OLED to power up
- delay(250);
- // Address 0x3C default
- display.begin(i2c_Address, true);
- // Clear the buffer.
- display.clearDisplay();
- Serial.begin(9600);
- Serial.println(F("DHTxx test!"));
- dht.begin();
- display.setTextColor(SH110X_WHITE);
- display.setCursor(0, 8);
- display.setTextSize(3);
- display.println("ESP8266");
- display.println("NodeMCU");
- display.display();
- delay(5000);
- display.clearDisplay();
-
- display.setCursor(0, 0);
- display.setTextSize(3);
- display.println("SH1106");
- display.println("OLED");
- display.display();
- delay(5000);
- display.clearDisplay();
- display.setCursor(10, 8);
- display.setTextSize(3);
- display.println("DHT-11");
- display.println("Sensor");
- display.display();
- delay(5000);
- display.clearDisplay();
- }
- void loop() {
- // Wait a few seconds between measurements.
- delay(2000);
- /* Reading temperature or humidity takes
- about 250 milliseconds!
- Sensor readings may also be up to 2 seconds
- 'old' (its a very slow sensor)*/
- float h = dht.readHumidity();
- // Read temperature as Celsius (the default)
- float t = dht.readTemperature();
- // Read temperature as Fahrenheit (isFahrenheit = true)
- float f = dht.readTemperature(true);
- // Check if any reads failed and exit early (to try again).
- if (isnan(h) || isnan(t) || isnan(f)) {
- Serial.println(F("Failed to read from DHT sensor!"));
- return;
- }
- // Compute heat index in Fahrenheit (the default)
- float hif = dht.computeHeatIndex(f, h);
- // Compute heat index in Celsius (isFahreheit = false)
- float hic = dht.computeHeatIndex(t, h, false);
- Serial.print(F("Humidity: "));
- Serial.print(h);
- Serial.print(F("% Temperature: "));
- Serial.print(t);
- Serial.print(F("°C "));
- Serial.print(f);
- Serial.print(F("°F Heat index: "));
- Serial.print(hic);
- Serial.print(F("°C "));
- Serial.print(hif);
- Serial.println(F("°F"));
- display.clearDisplay();
- delay(1500);
- // Clear the buffer.
- display.clearDisplay();
- display.setTextColor(SH110X_WHITE);
- display.setCursor(32, 0);
- display.setTextSize(2);
- display.println("Temp:");
- display.println(" " + String(t) + "C");
- display.setCursor(0, 32);
- display.println(" Humidity:");
- display.println(" " + String(h) + "%");
- display.display();
- }
Connection
Connect all components as follow,
- SH1106 OLED

Table 1: ESP-12E and SH1106 Connection
- DHT-11 Sensor

Table 2: ESP-12E and DHT-11 Connection
Picture
I tested it using my DIY ESP8266 TWI Communication Board.
![]() |
ESP8266 Interfaces with DHT-11 Sensor and SH1106 OLED |
![]() |
ESP8266 Interfaces with DHT-11 Sensor and SH1106 OLED |
Video
I keep the video on YouTube.


