Legal Info

When you visit any website, it may store or retrieve information on your browser, mostly in the form of 'cookies'. This information, which might be about you, your preferences, or your internet device (computer, tablet or mobile), is mostly used to make the site work as you expect it to. You can find out more about how we use cookies on this site, and prevent the setting of non-essential cookies, by clicking on the different category headings below. However, if you do this then it may impact your experience of the site and the services we are able to offer.

DHT11 Sensor using Wemos D1 mini board and send data by ThingSpeak channel 

In this small example, we would like to show you the potential of a Wemos D1 mini card, connecting a DHT11 temperature and humidity sensor and publishing all the measurements on our ThingSpeak channel, which will construct the graphs with the data provided from time to time.

Unlike an Arduino Micro, the Wemos D1 mini is equipped with WiFi hardware at a price that is more than excellent.

Wemos D1 Mini has 11 digital I / O pins, 1 analog input only and all I / O pins operate with a 3.3V supply voltage; the available memory is 4MB.

Wemos D1 Mini

DHT11 is a composite humidity and temperature sensor module. The output signal is calibrated and contains both temperature and humidity data. The application of digital data collection technology and temperature and humidity detection technology ensures that the product has high reliability and excellent long-term stability. The sensor includes a moisture-sensitive resistor and an NTC temperature sensor connected to an 8-bit microcontroller.

Usually DHT11 is used as a module already provided with resistance and can be connected directly to vdd or 3v3. The DHT11 module looks like the following image:

If we do not want to use the module, but the component, in the same way, we can use a link like the following adding us an adequate resistance.

Below are some photos of the circuit that we are going to build, I hope they are clear, however we have also included a scheme that you find further down

Wemos D1 Circuito

Wemos D1 Circuito

Wemos D1 Circuito

Schema collegamento Wemos D1 Sensore di temperatura e umidità DHT11 o DHT22

The PIN of the Wemos D1 Mini where we connected the DHT11 is the D5 that corresponds to the 14 (See Pinout in the picture and in the code below).

A brief description of the components and some photos of the three sensors that we are going to connect to our micro controller using a breadboard or 400 point breadboard.

400 points BREADBOARD

The breadboard or base, is the fundamental component to make your circuits because you do not need to weld anything as it allows you to detach and reattach the components using the small holes.

As shown in the photos below, the holes in the horizontal lines up to the split center line are electrically connected to each other, while the vertical strips along the base are usually used for ground (GND) and power (VCC) connections.

Breadboard basetta caratteristiche di funzionamento, piedinatura 

Breadboard basetta 400 punti collegamenti   



The DHT22 sensor also called AM2302 (PHOTO 4), detects the relative humidity and the temperature of an environment by digitally transmitting it through the "DATA" pin. Usually DHT22 sensors are already equipped with a resistor and can be connected directly to VCC but in case if it was not, for correct operation it is good practice to always add a resistance between 4.7K and 10Kohm between VCC and the DATA pin (PHOTO 7).

The humidity sensor is of the capacitive type, it uses a maximum of 2.5mA during the reading phase and allows to acquire at most a sample every 2 seconds.

Moisture measurement ranges from 0 to 100% with a typical accuracy of ± 2%.
Regarding the temperature, the DHT22 has a measurement range between -40 and + 80 ° C with an accuracy of ± 0.5 ° C thanks to the DS18B20 sensor integrated inside it.

DHT22 connections



To start, here is the shopping list, find everything on our site:

Now we will have to create an account on the thingspeak website - https://thingspeak.com. Once the account is created, we will have to configure a channel to display the data published by our device and create three fields, one for the temperature, the other for the humidity and the last for the dew point that we have calculated using a function that you see in the code below. Data fields detected by our DHT11 sensor. The screen will appear as follows:

Example Wemos D1 Mini Temperature Humidity ThingSpeak Channel Settings

You can also see the detections of our devices on our ThingSpeak - MR WATT Temperature Example channel

Source Code:

Below are the mapped pins:
Arduino = 0 -> WeMos = D3
Arduino = 1 -> WeMos= NC
Arduino = 2 -> WeMos= D4 (LED)
Arduino = 3 -> WeMos= NC
Arduino = 4 -> WeMos= D2
Arduino = 5 -> WeMos= D1
Arduino = 6 -> WeMos= Watchdog(4) Reset
Arduino = 7 -> WeMos= Watchdog(4) Reset
Arduino = 8 -> WeMos= Watchdog(4) Reset
Arduino = 9 -> WeMos= Watchdog(4) Reset
Arduino = 10 -> WeMos= NC
Arduino = 11 -> WeMos= Watchdog(4) Reset
Arduino = 12 -> WeMos= D7 low, D6 sporadic
Arduino = 13 -> WeMos= D0 high, D7 sporadic
Arduino = 14 -> WeMos= D0 high, D6 Low, D7 Low, D5 Sporadic
Arduino = 15 -> WeMos= High, D8 Sporadic
Arduino = 16 -> WeMos= D0
Arduino = 17 -> WeMos= NC
Arduino = 18 -> WeMos= NC
Arduino = 19 -> WeMos= NC
Arduino = 20 -> WeMos= Stack Trace and Pin-Based(2) Reset
Arduino = 21 -> WeMos= Stack Trace and Watchdog(4) Reset
Arduino = 22 -> WeMos= Stack Trace and Watchdog(4) Reset
Arduino = 23 -> WeMos= Stack Trace and Watchdog(4) Reset
Arduino = 24 -> WeMos= NC
Arduino = 25 -> WeMos= NC
Arduino = 26 -> WeMos= NC
Arduino = 27 -> WeMos= NC
Arduino = 28 -> WeMos= NC
Arduino = 29 -> WeMos= NC

#include <ESP8266WiFi.h>
#include <stdio.h>
#include <ThingSpeak.h>
#include <Wire.h>
#include <DHT.h>
#include <Arduino.h>
#include <ctype.h> // for isNumber check

// Wifi Settings
char ssid[] = "<XXXXXXXXXXXXXXX>"; // your network SSID (name)
char pass[] = "<XXXXXXXXXXXXXXX>"; // your network password

float dewpt=0; // dew point tempf

WiFiClient client;

//Initialize DHT22 Sensor
#define DHTPIN 14 // what digital pin we're connected to
// Uncomment whatever type you're using!
#define DHTTYPE DHT11 // DHT 11
//#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)

// Connect pin 1 (on the left) of the sensor to +5V
// NOTE: If using a board with 3.3V logic like an Arduino Due connect pin 1
// to 3.3V instead of 5V!
// Connect pin 2 of the sensor to whatever your DHTPIN is
// Connect pin 4 (on the right) of the sensor to GROUND
// Connect a 10K resistor from pin 2 (data) to pin 1 (power) of the sensor

// 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.

// ThingSpeak Settings

unsigned long myChannelNumber = <XXXXXXXXXX>; // Your ThingSpeak Chennel
const char * myWriteAPIKey = "<XXXXXXXXXXX>";

void setup() {
Serial.print("Sketch: "); Serial.println(__FILE__);
Serial.print("Uploaded: "); Serial.println(__DATE__);
Serial.println(" ");
Serial.println("WEATHER STATION - Temperature using Sensor DHT22 - Powered By MR WATT");

// We start by connecting to a WiFi network
Serial.print("Connecting to ");
WiFi.begin(ssid, pass);

while (WiFi.status() != WL_CONNECTED) {

Serial.println("WiFi connected");
Serial.println("IP address: ");

pinMode(LED_BUILTIN, OUTPUT); // Initialize the LED_BUILTIN pin as an output

// DHT22 Test
Serial.println("Initialize DHT22...");

// Initialize ThingSpeak


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

float temperature = dht.readTemperature();
float humidity = dht.readHumidity();
float dewpt = 0;

// Check if any reads failed and exit early (to try again).
if (isnan(humidity) || isnan(temperature)) {
Serial.println("Failed to read from DHT sensor!");
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(temperature, humidity, false);

dewpt = (dewPoint(temperature, humidity));

Serial.print("t Temperature DHT22: ");
Serial.print("C ");
Serial.print("t Humidity: ");
Serial.print("t Dew Point: ");

// Write to ThingSpeak
ThingSpeak.writeFields(myChannelNumber, myWriteAPIKey);



// This is section the function that the interrupt calls to increment the rotation count

// Functions

// Print Wifi Status

void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");

// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");

// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.println(" dBm");

// Dew Point function
double dewPoint(double temperature, double humidity) //Calculate dew Point
double A0= 373.15/(273.15 + temperature);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078);
return (241.88 * T) / (17.558-T);

Click here to find our code on GitHub


After a few minutes of operation of our device, we can see the following in our channel:

Thingspeak DHT11 Humidity Graph:

Wemos D1 Mini Grafico Umidità

ThingSpeak DHT11 - Temperature Graph:Wemos D1 Mini Graifco di Temperatura

ThingSpeak Dew Point Graph:

Wemos D1 Mini DHT11 Temperature Graph