ESP8266

Cloud Temperature Logger with the ESP8266

The ESP8266 is an amazingly cheap & small WiFi chip that can be used for several home automation applications. In this project, we are going to use it to automatically log temperature (and humidity) measurements in the cloud, and display these measurements inside an online dashboard.

By following this tutorial, you will be able to build a small & cheap measurement platform that logs data in the cloud. Of course, this can be applied to several type of sensors, like motion detectors. Let's dive in!

What You'll Need

ComponentQty
ESP8266 Olimex module1
Breadboard 3.3V power supply1
3.3V FTDI USB module1
DHT11 sensor1
Breadboard1
Jumper wiresMultiple

Step by Step

1

Hardware & Software Requirements

<p style="text-align: justify">For this project, you will of course need an ESP8266 chip. You can for example use an Olimex ESP8266 module.</p><p style="text-align: justify">You will also need a temperature sensor. I used a DHT11 sensor, which is very easy to use &amp; that will allow us to measure the ambient temperature &amp; humidity.</p><p style="text-align: justify">You will also need a 3.3V FTDI USB module to program the ESP8266 chip. Finally, you will also need some jumper wires &amp; a breadboard.</p><p style="text-align: justify">On the software side, I will let you see my guide on how to set up the ESP8266 for a first use: <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.openhomeautomation.net/getting-started-esp8266/">https://www.openhomeautomation.net/getting-started-esp8266/</a></p><p style="text-align: justify">At the end, you will need to have an ESP8266 chip ready to be used with the ESP8266 Arduino IDE.</p>

2

Hardware Configuration

<p style="text-align: justify">Again, for most of the hardware configuration I will redirect you to the article I wrote on setting up your ESP8266 chip: <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.openhomeautomation.net/getting-started-esp8266/">https://www.openhomeautomation.net/getting-started-esp8266/</a></p><p style="text-align: justify">Once this is done, simply put the DHT11 sensor on the breadboard. Then, connect the left pin to VCC (red power rail), the right pin to GND (blue power rail), and the pin next to VCC to the GPIO5 pin on your ESP8266 chip. This is the final result, not showing the USB-to-Serial FTDI cables:</p>

3

Testing the Sensor

<p style="text-align: justify">We are now going to test the sensor. Again, remember that we are using the modified version of the Arduino IDE, so we can code just like we would do using an Arduino board. Here, we will simply print the value of the temperature inside the Serial monitor of the Arduino IDE.</p><p style="text-align: justify">Let's see the details of the code. You can see that all the measurement part is contained inside the loop() function, which makes the code inside it repeat every 2 seconds.</p><p style="text-align: justify">Then, we read data from the DHT11 sensor, print the value of the temperature &amp; humidity on the Serial port.</p><p style="text-align: justify">You can now paste this code in the Arduino IDE, and upload it to your board. Then, open the Serial monitor. You should immediately see that the temperature &amp; humidity readings inside the Serial monitor. My sensor was reading around 24 degrees celsius when I tested it, which is a realistic value.</p>

4

Logging Data to Dweet.io

<p style="text-align: justify">We are now going to see how to log these measurements in the cloud. This will be really easy to do as our chip is already connected to the web. We will once more use the Dweet.io cloud service that I used in several articles of this website: <a target="_blank" rel="noopener noreferrer nofollow" href="http://dweet.io/">http://dweet.io/</a></p><p style="text-align: justify">As the code for this part is very long, we will only see the important parts here. You can of course get all the code from the GitHub repository for this project. Again all the measurements are done inside the loop() function of the sketch, which makes the code repeat every 10 seconds, using a delay() function.</p><p style="text-align: justify">Inside this loop, we connect to the Dweet.io server, then we read the data from the sensor, and after that, we send data to the Dweet.io server.</p><p style="text-align: justify">You might want to replace the 'myesp8266' here, which is your device name on Dweet.io. Use a complicated name (just like a password) to make sure you are creating an unique device on Dweet.io.</p><p style="text-align: justify">We also print any received data on the serial port.</p><p style="text-align: justify">Note that the complete code can also be found inside the GitHub repository of the project: <a target="_blank" rel="noopener noreferrer nofollow" href="https://github.com/openhomeautomation/esp8266-cloud">https://github.com/openhomeautomation.net/esp8266-cloud</a></p><p style="text-align: justify">Note that you also need to modify the code to insert your own WiFi network name &amp; password. You can now upload the code to the ESP8266 board, and open the Serial monitor. You should see that every 10 seconds, the request is sent to the Dweet.io server, and you get the answer back with a 'succeeded' message.</p>

5

Display Data Using Freeboard.io

<p style="text-align: justify">Now, we would like to actually display the recorded data inside a dashboard that can be accessed from anywhere in the world. For that, we are going to use a service that I love to use along with Dweet.io: Freeboard. You can create an account there by going to: <a target="_blank" rel="noopener noreferrer nofollow" href="https://www.freeboard.io/">https://www.freeboard.io/</a></p><p style="text-align: justify">Then, also create a new dashboard, and inside this dashboard, create a new datasource. Link this datasource to your Dweet.io 'thing' that you defined in the ESP8266 code.</p><p style="text-align: justify">Then, create a new 'Gauge' widget, that we will use to display the temperature. Give it a name, and link it to the temperature field of our datasource.</p><p style="text-align: justify">You should see that the temperature data coming from the ESP8266 is logged every 10 seconds and is immediately displayed inside the Freeboard.io panel. Congratulations, you should built a very small &amp; cheap temperature sensor that logs data in the cloud! You can then do the same with the humidity measurements &amp; also display them on this dashboard.</p>

Wrapping Up

Let's summarise what we did in this project. We built a simple & cheap WiFi temperature sensor based on the ESP8266 chip. We configured it to automatically log data on the Dweet.io service, and we displayed these measurements inside a dashboard.

There are many ways to improve this project. You can simply add more sensors to the project, and display these measurements as well inside the Freeboard.io dashboard. You can also for example completely change the project, by connecting a motion sensor to the ESP8266 board. You can then configure this sensor to automatically send you an alert when motion is detected, for example via email or using Twitter. The possibilities are endless!