ESP Thermometer

Battery operated inexpensive internet enabled thermometer built with ESP-01 WiFi module, DS18S20 digital thermometer, Arduino IDE and Ubidots

View the Project on GitHub gabormay/esp-thermometer

The objective of this project is to create a really inexpensive internet enabled thermometer to be able to monitor a room's temperature remotely.

Completed project photo 1 Completed project photo 2

Main components

Here's what you're going to need:

General notes and caveats

First steps - programming your ESP8266

Start with the installation steps from https://github.com/esp8266/Arduino#installing-with-boards-manager:

Wire up your ESP module on a breadboard as explained in https://github.com/esp8266/Arduino/blob/master/doc/boards.md#minimal-hardware-setup-for-bootloading-and-usage

Now load the Sketch from File/Examples/ESP8266/Blink

Now you're ready to flash you first program to the ESP8266! Make sure that you have the Board setting in Arduino IDE set correctly:

Board settings in Arduino IDE

Then put the ESP bootloader into programming mode:

In a short while the upload should finish without errors. If everything went fine the blue LED on the board will start blinking. You can now reset the board by connecting RST to GND momentarily. Make sure that GPIO0 is not connected to GND otherwise you will enter the programming mode again.

At this point I suggest you to play around with your ESP8266. Try changing the example or try other sketches. Look at the the list of functions in the included libraries and try to use them in your program.

You can use the Serial.print() family of functions to print diagnostic messages that you can then read in the Serial Monitor. Set the baud rate to 74880 to make it consistent with the bootloader via Serial.begin(74880).

Once you feel comfortable programming your ESP8266, come back here and read on.

Building the thermometer

The circuit

Schematic

Explanation:

Ubidots

The software

Prerequisites

Download and edit the source

Connect your circuit to the serial adapter. Make sure the serial interface is connected to the USB-to-serial adapter properly (see above) and the adapter is plugged in to a USB port on your computer

Connect the power rails to an external 3.3V power source (e.g. 2xAA battery or a stabilized wall adapter)

Once you have everything connected, you should download the program to the module

If everything went well you should see an output similar to this in the serial monitor:

 ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 1384, room 16 
tail 8
chksum 0x2d
csum 0x2d
v3ffe8654
~ld
à
ESP Thermometer starting...
Chip ID: [<your chip ID here>]

VCC = 2581 mV
Requesting temperatures...DONE
TEMP = 26.6 C
Connecting and sending...
.......WiFi connected
IP address: 
192.168.178.44
Posting your variables
HTTP/1.1 200 OK
Server: nginx
Date: Wed, 31 Aug 2016 20:18:29 GMT
Content-Type: application/json
Transfer-Encoding: chunked
Connection: close
Vary: Accept-Encoding
Vary: Accept
Allow: POST, OPTIONS

2c
[{"status_code": 201}, {"status_code": 201}]
0

Entering deep sleep [ 557s ] ...

 ets Jan  8 2013,rst cause:1, boot mode:(3,6)

[... and so on ...]

Running from a battery

I was able to run this project from 2 AA batteries for about 2-3 weeks - not great but not that bad either. Interestingly enough the thermometer chip proved to be more sensitive to loss of voltage. It stopped working and produced bogus measurements when the battery voltage fell below 2.4V or so. The ESP module worked fine until about 1.8V, which is pretty remarkable.

Anyway, let's dig a little bit into how this was made possible and what can you do to further improve battery life.

Deep sleep

Deep sleep is a power saving feature of the ESP8266 chip. When put to deep sleep, only an internal RTC circutry is powered, drawing very tiny current (~20uA). The rest of the chip is powered down and is completely inactive (no program runs for example). Once the specified delay is over, the RTC puts out a signal on GPIO16 which can be used to wake up the chip. Normally you would want to connect GPIO16 to RST to get the most features. On some ESP boards it is tied to CH_PD (chip enable) which works too but some of the features, i.e. keeping some state between sleep cycles is not supported. See the Application Note ESP Low Power Solutions from Expressif for more info.

Note that, in any case, upon wake-up, your program (sketch) will run from the very beginning (starting with setup()), so you don't really need to put anything in loop() at all. See the Application Note mentioned above for options to save some variables between these sleep cycles.

Modifications to the board

Scrapping the Power LED

The onboard power LED draws quite a bit of current (few milliamps at least) all the time the board is powered, even during deep sleep. That is almost 1000 times the current the chip needs in deep sleep, for just a plain power indicator, which is not a critical feature at all. On the ESP-01 board you don't have any control over this, so your only option to get rid of this 'powet hog' is to scrape the LED physically from the board. Be gentle, but firm. See Running ESP8266 from a battery for details.

Connecting GPIO 16

To be able to wake the chip up from deep sleep, GPIO need to be connected to CH_PD or RST. In case it is not connected on your board, you will have to do it yourself. See http://tim.jagenberg.info/2015/01/18/low-power-esp8266/

Doing even better

Here are a few things you can do to increase the battery life of your project even further.

What's next?

There are a lot of ways to further improve and extend this project. Here are a few ideas and pointers to get you started.

Closing words

Hope you've found this useful. If you run into problems and could not find anything on the internet and in the referenced documents, let me know - I will try to help as much as my time allows. In any case, please feel free to use the information presented in this article in any way you wish (no warranty, though, please refer to the LICENSE). Good luck!

References and further reading

Reference

Tutorials/guides

Deep sleep/battery operation

DS1820