ESP8266 – DHT11 Driver for Open SDK

This long weekend is chilly, festive and also susceptible to boredom. To make it a little exciting and fun, I had a plan. I came across a taught that it would be fun to build an IoT based Weather Station for this Christmas 🙂 . I decided to use the esp8266 and the dht11 sensor for this purpose.

When working with the esp8266, I always prefer to use the open-SDK for developments rather than the Arduino environment. The open-SDK gives me a better feel for programming, unlike the Arduino environment which is an easy way out. Please check out this post before going further, as it will give you a better clarity of why and how I have fused the Arduino style GPIO usage with the open SDK.

The DHT11 is a low-cost Temperature and Relative Humidity sensor. It uses a one wire protocol to send data to MCU, in this case, it’s the esp8266. There already exists a few DHT11 Arduino libraries and open-SDK drivers which I could just port or use. However, I decided to write one from scratch to get a good understanding of how this sensor works and have some fun while solving logic and programming problems.

The structure of the packet received from the DHT11 is shown below.

Note that DHT11 has a resolution or step size of 1, unlike the DHT22 which has a resolution of 0.1. This driver only supports the dht11 sensor but you are free to extend its functionality to support the dht22 and I leave that to you as its pretty straight forward.

1. DHT11 Driver Software for ESP8266 – open SDK

Coming to the cream of this post i.e. the code. You can download the software from my Github repo or clone it using the below command.

2. Demo of the DHT11 Driver

The above video shows the dht11 sensor and the esp8266 in action (Sorry about my Laptops dirty screen, I haven’t cleaned it for a while 😛 ). The driver is simple to use and you can connect multiple dht11 sensors to read data simultaneously. After some testing, to be honest, I wasn’t all that impressed with the accuracy of the humidity data from the dht11. Therefore it cannot be used for any industrial or serious purpose but pretty cool for hobbyists and students.

Leave a Reply

Your email address will not be published. Required fields are marked *