DHT11 with ESP8266 / ESP32

Last Updated on 16. October 2026 by SuffocationLink status: OK

Controlling a DHT11 sensor via the ESP8266 / ESP32

Foundations

Link to postLink status: OK

Structure

ESP8266 DHT11 Testschaltung
ESP8266 DHT11 Testschaltung

Programming

Libraries

The integration of the library can be seen in the following post:

Link to postLink status: OK

Adafruit DHT LibraryLink status: OK

Adafruit Unified Sensor LibraryLink status: OK

Test programme

Source code DHTTest.ino (GitHubLink status: OK)

/** DHT Test for ESP8266 and ESP 32
*/

// include adafruit dht lib
#include <DHT.h> // https://github.com/adafruit/DHT-sensor-library
// the unified sensor lib is also needed https://github.com/adafruit/Adafruit_Sensor


// define the pin for the dht sensor
#define DHT_PIN 16
#define DHT_TEMP_CALIBRATION_VALUE -8

// special pin for higrow board
#define POWER_CTRL          4


// define the type of dht sensor
#define DHT_TYPE DHT11
//#define DHT_TYPE DHT21
//#define DHT_TYPE DHT22

// creat a dht object
DHT dhtSensor(DHT_PIN, DHT_TYPE);


void setup() {

  // init serial interface
  Serial.begin(115200);


  //! Sensor power control pin for higrow, use deteced must set high
  //pinMode(POWER_CTRL, OUTPUT);
  //digitalWrite(POWER_CTRL, HIGH);
  //delay(1000);

  // start dht sensor
  dhtSensor.begin();

}


void loop() {
  // get some values
  // read temperture in Celsius
  float temp = dhtSensor.readTemperature() + DHT_TEMP_CALIBRATION_VALUE ;

  // read humidity in %
  float humi = dhtSensor.readHumidity();

  // ouptu the values
  Serial.printf("Temperatur %2.2f °C \t Humidity %3.0f\%\n", temp, humi);

  // wait a while
  delay(2000);
}

Test program output

Related Posts

 Sources

DHT sensor in generalLink status: OK

Adafruit DHT LibraryLink status: OK

Adafruit Unified Sensor LibraryLink status: OK

DateChangeAuthor
16.10.2026Beispielcode als Code-Block eingefügt (Einbettung über gist-it.appspot.com funktionierte nicht mehr)Suffocation
04.10.2026Rechtschreibung korrigiert: TippfehlerSuffocation
03.10.2026Log-Liste eingefügtSuffocation
23.02.2018Post createdSuffocation
Changelog

3 thoughts on “DHT11 mit ESP8266 / ESP32”

  1. Hello Stefan,

    I also tried this project and then got hooked on using an OLED, so I looked into using Openweathermap and have now managed to put the 3-day forecast onto the display.
    There are very helpful examples of this on GitHub.

    Good evening
    Siegfried

Leave a Reply

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