Measuring Temperature with an ESP8266
Let’s take the DHT11 temperature and humidity sensor that I have used in my post [“Measuring Temperature with an Arduino”]({% post_url 2016-01-12-meaasuring-temperature-with-arduino %}) and use it with the ESP8266 from my last post [“Hello ESP8266”]({% post_url 2016-04-18-hello-esp8266 %}).
One drawback of my Arduino Nano was that it had no possibility to wirelessly transmit the data to somewhere. My plan was to use the 433 MHz module from my post [“Hello World! - On 433 MHz”]({% post_url 2015-12-08-hello-world-on-433mhz %}).
Thanks to the WiFi capabilities of the ESP8266 this is now obsolete and we only need to attach the DHT11 to it and write some code for grabbing the data and pushing it to somewhere with a HTTP request or similar.
Let’s wire things up first. Thanks to this project for the Fritzing parts.
Am using a DHT11 with an on-board resistor, therefore I only need three wires for connecting it.
Next is the code for grabbing the temperature and humidity data only and then printing it out to the serial connection.
Basically, I put two code examples together. One is an example from the Adafruit DHT library. The other is the WiFiClient example from the ESP8266 Arduino library.
The final result looks like this:
{% gist 7cb867782dc4107ce687767d46128c84 esp-dht-http.ino %}
The URL am posting the data to is from a German computer news site. They are currently doing a survey on office temperatures. Instead of manually reading the temperature you can post your data to them automatically. A wonderful opportunity to test my setup.
Done for today!