ESP8266 temperature and humidity logger with deep sleep enabled
|
ESP8266 has made it possible for hobbyists and makers to develop IoT applications in simple and inexpensive ways. This article shows an example of making a very simple temperature and humidity logger using ESP8266 that uploads the data directly to a cloud service, such as ThingSpeak, and allows to visualize the data in real time. The ESP8266 module used in this project is WeMOS’ D1 Mini board. Because the D1 board comes with the CH340G USB to UART converter module and a micro USB connector preinstalled on board, all you need is an USB cable to upload your program to the ESP8266. For temperature and humidity measurements, the DHT22 sensor is used. The sensor circuit is soldered on a prototyping circuit board in the form of a shield that plugs directly into the D1 Mini board. Unlike many other similar projects on the internet, this article talks about how to put the ESP8266 into deep sleep mode and configure it to wake up automatically at regular intervals for sensor readings.
Circuit setup
The connection between the DHT22 and D1 Mini board is shown in the figure below. The DHT22 sensor is powered by the 3.3V power supply coming from the D1 Mini board. A 2.2K resistor pulls the DHT22 data pin to high at default. The DHT22 data pin goes to the D4 pin of WeMOS D1 Mini.
As I mentioned earlier, this project implements deep sleep mode of ESP8266 to save power as well as to get accurate temperature readings. ESP8266 is power hungry and dissipates considerable amount of heat during operation. I have noticed that if the ESP8266 is not put in to sleep during successive sensor readings, the heat radiated by the ESP8266 can easily affects the DHT22 outputs if the sensor is close to the ESP module. In this project, the DHT22 sensor lies on the top shield right above the ESP8266 chip, so it is very important to consider using the deep sleep mode feature. Without using this feature, I have found the temperature readings from DHT22 are 2-3 ºF higher than the actual values. ESP8266 can be put into deep sleep mode with a software instruction. But, in order for it to automatically wake up from sleep mode after a certain interval, the XPD (D0 in D1 Mini board) pin must be tied to the ESP8266’s reset line as shown in the circuit diagram above. The DHT22 circuit is built on a perf board in the form of a D1 Mini shield as shown below.
Software
The ESP8266 program for this project is developed using Arduino IDE. So, you need to install the ESP8266 core to enable the Arduino IDE for ESP8266 programming. Instructions can be found in the ESP8266 core github page. Similarly, you would also need to sign up for a ThingSpeak account and obtain a Write API Key, which is required to upload data to ThingSpeak. You can find instructions to do that online. The following Youtube video link is one example.
The complete ESP8266 code for this project can be downloaded from the following link:
Make sure you update the SSID, Wifi password, and ThingSpeak API to match with yours. The temperature and humidity readings are acquired from DHT22 in every 60 seconds and are uploaded to ThingSpeak server. Between two samples, the ESP8266 is put to sleep using ESP.deepSleep() function in Arduino IDE.
If everything worked fine, you would see the temperature and humidity measurements profiles on your ThingSpeak channel graphs.
|
Hi
I have the same setup an downloaded your code
Upload works very fine, also deepsleep mode, but after a time the Wemos mini cannot read data from the DHT 22
Any ideas
tnx Alex
Thanks for the tip on tying the D0 to the RST line. I had issues with deepsleep and the ESP8266 not waking up. This really solved it! Quite weird that the deepsleep software instruction does not work without special wiring though..