Wemos Mini and DHT Pro example

In this example we connect the DHT22 Single Bus Digital Temperature Humidity Sensor (DHT Pro shield) to our Wemos Mini , you can see this in the picture below which shows the shield

dht22
dht22

 

Code

There are basic examples , the code below is based on the example from https://github.com/wemos/D1_mini_Examples.git

#include "DHT.h"
#define DHTPIN D4     // what pin we're connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
 
DHT dht(DHTPIN, DHTTYPE);
 
void setup() 
{
  Serial.begin(9600);
  Serial.println("DHTxx test!");
  dht.begin();
}
 
void loop() 
{
  // Wait a few seconds between measurements.
  delay(2000);
 
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  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("Failed to read from DHT sensor!");
    return;
  }
 
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.println(" *F");
 
}

 

Output
Open the serial monitor with Ctrl+Shift M or Tools->Serial Monitor, and you should see the values for the humidity in percent as well as the temperature & heat index in Celcius and Fahrenheit. Here is my hardware running

dht22 wemos
dht22 wemos

 

Links

DHT22 Single Bus Digital Temperature Humidity Sensor Shield For WeMos D1 Mini

Wemos Mini DH11 shield example

I like the Wemos Mini and when I saw that there were some shields I decided to purchase some of them, in this first example we use one of our favourite sensors the DHT11.  Here is a picture of the DH11 shield.

dht11
dht11

Each shield comes with a choice of header you can solder if you want, as you will be able to see in the code example later the DHT11 connects to D4, one disadvantage of using a shield is this cannot be changed but for beginners and most people this is not an issue as the benefits of using the shield outweigh any drawbacks

Here you can see the DHT11 shield connected to a Wemos mini, again the headers I used allow you to stack another shield on top of the DHt11 such as logging shield or an OLED.

wemos and dht11
wemos and dht11

 

Code

#include "DHT.h"
 
#define DHTPIN D4     // what pin we're connected to
 
// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11
 
 
DHT dht(DHTPIN, DHTTYPE);
 
void setup() 
{
  Serial.begin(9600);
  Serial.println("DHT11 test!");
  dht.begin();
}
 
void loop() 
{
  // Wait a few seconds between measurements.
  delay(2000);
 
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  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("Failed to read from DHT sensor!");
    return;
  }
 
 
  Serial.print("Humidity: ");
  Serial.print(h);
  Serial.print(" %\t");
  Serial.print("Temperature: ");
  Serial.print(t);
  Serial.print(" *C ");
  Serial.print(f);
  Serial.println(" *F");
 
}

 

Output

Open the serial monitor and you should see something like this

dht11 output
dht11 output

 

Links
DHT11 Single Bus Digital Temperature Humidity Sensor Shield For WeMos D1 Min

Wemos mini shields

In a previous post I looked at the Wemos Mini – http://www.esp8266learning.com/wemos-d1-mini-hardware.php. I also noticed that there were a number of shields that you can purchase. Here is a picture of some of these shields that I purchased

wemos mini shields
wemos mini shields

 

DHT Shield is a digital temperature and humidity sensor shield based on the DHT11 sensor.

 

DHT ProShield is a digital temperature and humidity sensor shield based on the DHT22 (AM2302) sensor.

OLED Shield is a 64×48 pixels shield

1-Button Shield is a basic one button shield

Relay Shield is a relay that could be used for home automation

Micro SD Shield is a shield to use a Micro SD card in your projects

ProtoBoard Shield is a basic shield that can be used for prototyping

Wemos d1 mini hardware

Recently I purchased a Wemos D1 board, when I was browsing around recently I noticed that they also had a mini version. If you know your Arduino boards then this would be similar to the Arduino Nano. Here is a picture I took of one alongside an Arduino Nano

 

Wemos and Arduino nano
Wemos and Arduino nano

As you can see its nice and compact for any projects where space is an issue. Another great feature for ease of development is the ability to use the Arduino IDE or NodeMCU. this means you can get up and running quickly. The pin headers are located in a sensible layout, so it looks easy to create your own basic shields for the board

Lets look at some basic specs, the operating voltage and the input voltage to Analog are critical, remember this is a 3.3v board

Microcontroller ESP-8266EX
Operating Voltage 3.3V
Digital I/O Pins 11
Analog Input Pins 1(Max input: 3.2V)
Clock Speed 80MHz/160MHz
Flash 4M bytes

Here are the pin functions

Pin Function ESP-8266 Pin
TX TXD TXD
RX RXD RXD
A0 Analog input, max 3.3V input A0
D0 IO GPIO16
D1 IO, SCL GPIO5
D2 IO, SDA GPIO4
D3 IO, 10k Pull-up GPIO0
D4 IO, 10k Pull-up, BUILTIN_LED GPIO2
D5 IO, SCK GPIO14
D6 IO, MISO GPIO12
D7 IO, MOSI GPIO13
D8 IO, 10k Pull-down, SS GPIO15
G Ground GND
5V 5V
3V3 3.3V 3.3V
RST Reset RST

 

So to summarise, the Wemos D1 mini has

  • 11 digital input/output pins, all pins have interrupt/pwm/I2C/one-wire supported(except D0)
  • 1 analog input(3.2V max input)
  • a Micro USB connection
  • Compatible with Arduino
  • Compatible with nodemcu

 

Links

You can pick up one of these from about $5
D1 mini – Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos