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

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);
}

Related Posts
Preview – INA3221 Power MonitorLink status: OK
Preview – Digitaler WägesensorLink status: OK
ESP32 Bluetooth GamepadLink status: OK
ESP01 – DHT11 Temperatur und Feuchte Sensor PlatinenLink status: OK
Temperature and humidity sensor DHT22Link status: OK
LM2596 Step Down Voltage ConverterLink status: OK
Preview – Strommessung mit dem ACS712Link status: OK
Preview – Omnidirectionales I²C MikrofonLink status: OK
D1 Mini Shield – PIR (Bewegungssensor)Link status: OK
D1 Mini Shield – SG30 LuftqualitätsmessungLink status: OK
Sources
DHT sensor in generalLink status: OK
Adafruit DHT LibraryLink status: OK
Adafruit Unified Sensor LibraryLink status: OK
| Date | Change | Author |
|---|---|---|
| 16.10.2026 | Beispielcode als Code-Block eingefügt (Einbettung über gist-it.appspot.com funktionierte nicht mehr) | Suffocation |
| 04.10.2026 | Rechtschreibung korrigiert: Tippfehler | Suffocation |
| 03.10.2026 | Log-Liste eingefügt | Suffocation |
| 23.02.2018 | Post created | Suffocation |
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
Hello Siegfried,
Thank you very much for your comment. There are also some projects that I'd really like to try out again. I also have a circuit board with a display here for a weather station. I started a post a few years ago and never finished it, which is a shame.
https://github.com/squix78/esp8266-weather-station-platformio-demo
http://www.instructables.com/id/Minitaure-Weather-Station-ESP8266/
Greetings Stefan