ESP8266 WiFi module is becoming increasingly popular among electronic enthusiasts. It being used widely for different applications. In this article we concentrate on one such application.
Objective of this project is to provide a cost effective solution to transmit temperature and humidity data of a DHT11 sensor from a remote location (where the sensor is located at) to a computer located at a distant location. ESP8266 module’s WiFi technology and internet are used to achieve it.
What You Need to Start
ESP8266 ESP-12E WiFi module
Mounting plate for ESP8266 module
DHT11 temperature & humidity sensor
CP2102 USB-Serial converter
LD33V 3.3V regulator – 2 Nos
A desktop or laptop computer
A WiFi connection
ESP8266 is a small module consists of a microcontroller and a WiFi unit. It provides a complete in built wireless networking solution by using the WiFi unit. Since it includes a microcontroller it has can perform all the basic functions of a regular microcontroller. A user written Lua program can be used to control this module.
DHT11 is a digital temperature and humidity sensor. It consists of a 8-bit microcontroller, a capacitive humidity sensor and a thermistor to measure humidity and temperature of the surrounding air. It provides output data as a serial digital signal on the data pin. A single data transmission consists of 40 bits of data. The 40-bit signal consists of a 16-bit humidity value, a 16-bit temperature value and 8-bit value used for error checking purpose.
Features and specifications of DHT11 sensor are as follows.
Sampling period over 2 seconds
Humidity accuracy +-5%RH at 25oC
Humidity measuring range 20 – 90 %RH
Temperature accuracy +-2 oC at 25oC
Temperature measuring range 0 – 50 oC
NodeMCU is an open source firmware. It provides ability to use Lua scripting language in IOT (internet of things) platforms such as ESP8266.
You should download NodeMCU firmware into the ESP8266 module before downloading a user written Lua code. In this project NodeMCU Flasher software is used to download the NodeMCU Firmware. NodeMCU firmware version 0.9.2 Build 20141219 was used for this project.
Lua is the programming language used for programing ESP8266 module. The ESPlorer IDE was used for Lua coding and code downloading functions.
A USB to Serial converter based on PL-2303HX was used to download NodeMCU firmware and Lua program in to the ESP8266 module.
What it does
The ESP8266 module together with a DHT11 temperature and humidity sensor collects temperature and humidity readings at a remote location. The ESP8266 module is connected to a WiFi router located nearby so that data can be sent to internet. After collecting readings the ESP8266 module transmits readings to internet (to thingspeak.com website) so that the readings can be accessed and seen from anywhere in the world.
The Circuit Diagram
The ESP8266 module and DHT11 sensor were connected with other components as in the following circuit diagram.
About the Circuit
A power supply unit capable of supplying at least 2A current should be used to supply power to the circuit. Two separate LD33V 3.3V regulators were used to supply power to the ESP8266 module and the DHT11 sensor. It makes sure that the ESP8266 module gets enough current to operate. The LD33V regulator is capable of supplying maximum of 800mA current.
Power supply section was separated from the ESP8266 module and the DHT11 sensor to make sure power supply unit doesn’t impose any noise on the WiFi connectivity, ESP8266 module and the sensor.
The 10kOhm resistor was used as a pull up resistor.
Lua Codes & Their Functionality
There are two Lua codes used for this project named as “init.lua” and “dht11.lua”. The “init.lua” code is used to establish connectivity between ESP8266 module and WiFi router. Once the connectivity is established then it calls the “dht11.lua” code.
All other functions are performed in “dht11.lua” code. First the ESP8266 module is set to send a request to DHT11 sensor to read temperature and humidity values. The ESP8266 module does this by pulling down the connection between data pin of the DHT11 sensor and ESP8266 module for a predefined period of time.
Then after observing the acknowledge from the DHT11 sensor the ESP8266 module is set to read 40 bits of data stream from the DHT11 sensor. The first byte of the 40 bit data stream contains the integer value of humidity reading, second byte contains decimal value of humidity reading, third byte contains decimal value of temperature reading, fourth byte contains decimal value of temperature reading and fifth byte contains a value that is used for the error checking function.
Then the code calculates the error checking value manually and compares it with the error checking value received with the 40 bit data stream to check whether there are any errors occurred during data transmission. Those two values should be matched and any possible mismatch means errors were occurred.
Then the ESP8266 module is set to establishes a HTTP client connection with the thingspeak.com website. After that it send the temperature and humidity values to the specified channel of the thingspeak website.
The ESP8266 module is set to repeat the same operation once every 30 seconds period.
The ThingSpeak website collects the data received from the ESP8266 module and displays in chart format in the specified channel. These charts updates in real-time.
By using the specified channel number these charts can be accessed and seen from anywhere in the world. Also the data collected by ThingSpeak website can be exported to a CSV document.
Furthermore iCharts Android mobile app can be used to display these charts on the mobile devices.
Following image shows completed circuit that includes DHT11 sensor, ESP8266 module and other used components.