Warning: file_put_contents(/home/clients/81b51a55b78a35c5c4c50dd82cac1015/diyprojects/wp-content/uploads/wpo/images/wpo_logo_small.png.webp): failed to open stream: Disk quota exceeded in /home/clients/81b51a55b78a35c5c4c50dd82cac1015/diyprojects/wp-content/plugins/wp-optimize/vendor/rosell-dk/webp-convert/src/Convert/Converters/Gd.php on line 428
Shield Wemos D1 Mini DHT11 or DHT22: Arduino code - ESP Easy • DIY Projects
DIY Projects

Shield Wemos D1 Mini DHT11 or DHT22: Arduino code – ESP Easy

shield dht22 wemos d1 mini assembled stack

Wemos offers a wide range of expansion boards (Shield) for the D1 Mini. They are grouped in this article of presentation as they are released. In this quick tutorial, we will discover how to assemble the DHT22 shield and use it in an Arduino code or using the ESP Easy firmware.

Unpacking the DHT22 shield

Like all Wemos boards, this board comes with 3 types of connectors to be welded:

The board measures 36 (length) x 25 (width) x 9.6 (height) mm. It will be necessary to add a few additional millimeters according to the chosen connector.

Shield DHT22 for Wemos D1 Mini

Once assembled, this configuration is obtained, for example. It is still possible to stack other shields (OLED screen, power on battery …)

Shield DHT22 assembled on Wemos D1 Mini

The Shield embeds a DHT22 quite classic, the same one found in the many Arduino / Raspberry Pi learning kits. We will therefore be able to use the libraries already developed for the 2 platforms, or rather say the 3 platforms if The ESP8266 is considered a platform in its own right.

The DHT22 (or DHT11) is soldered to the expansion board. It is therefore not possible to choose the spindle. We will retrieve the measurements on pin D4, equivalent to the GPIO-2 of Arduino.

Arduino Code

Before you begin, you need to install the Adafruit library (most used). It is very easy to install from the Arduino IDE library manager.

Create a new sketch and paste this code. No need to change the Pin.

/* DHT Shield - Simple
 * Example testing sketch for various DHT humidity/temperature sensors
 * Written by ladyada, public domain
 * Depends on Adafruit DHT Arduino library
 * https://github.com/adafruit/DHT-sensor-library

#include "DHT.h"

#define DHTPIN D4     // what pin we're connected to

// Uncomment whatever type you're using!
#define DHTTYPE DHT12   // DHT 11
//#define DHTTYPE DHT22   // DHT 22  (AM2302)
//#define DHTTYPE DHT21   // DHT 21 (AM2301)

// Initialize DHT sensor.
// Note that older versions of this library took an optional third parameter to
// tweak the timings for faster processors.  This parameter is no longer needed
// as the current DHT reading algorithm adjusts itself to work on faster procs.

void setup() {
  Serial.println("DHTxx test!");


void loop() {
  // Wait a few seconds between measurements.

  // 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("Impossible de lire la sonde DHT!");

  // 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("Humidity: ");
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(" *C ");
  Serial.print(" *F\t");
  Serial.print("Heat index: ");
  Serial.print(" *C ");
  Serial.println(" *F");

Source : https://github.com/wemos/D1_mini_Examples/blob/master/examples/04.Shields/DHT_Shield/Simple/Simple.ino

Download the program to the Wemos and open the serial monitor to receive the measurements.

Several examples have been made available by Wemos on Github here

If you have only a small connected temperature sensor to be developed, ESP Easy will suffice. The DHT11 / DHT22 sensors are very well managed. If you are starting out with ESP Easy, follow this tutorial to install the firmware and configure the Wi-Fi connection of the Wemos D1 Mini.

Once connected, go to the Device tab and click on an Edit (any line). From the Devices list, choose Temperature & Humidity – DHT, and then adjust the settings like this

You can now easily integrate your probe to a home automation server (Jeedom, Domoticz) or retrieve the measurements with Node-RED to create graphics with Grafana.

Click to rate this post!
[Total: 0 Average: 0]
Exit mobile version