The Idea

To use a battery powered microcontroller to capture and log temperature and other measurements onto the Internet.

The data will be logged to ThinkSpeak and can be analysed with MatLab. Simple enough huh?

Update: The Ikea batteries lasted until the April 12th from February 20th. 40 Days!

Step 1 – Choosing a temperature module the ESP8266

The following article goes into depth on specifications and reliability of which temperature module you should use to hook up to an ESP8266 microcontroller – http://www.kandrsmith.org/RJS/Misc/Hygrometers/calib_many.html

I had decided on the BME280 module. Once I found a library and a demo sketch it was up and running within a few minutes after soldering. The module can use SPI or I2C: https://learn.sparkfun.com/tutorials/i2c#i2c-at-the-hardware-level

I chose ‘wisely’ the BME280 and the library: https://github.com/finitespace/BME280

Connecting up SCL and SDA to D1 and D2 respectively

Connecting up SCL and SDA to D1 and D2 respectively

After wiring D1 to SCL and D2 SDA to the ESP8266 kit board, I loaded the ‘Enviroment_Calculations’ demo code which was installed from the BME280 library.

The temperature is definitely working well from the serial monitor output.

Step 2 – Get Internet Connectivity

I added some code to switch on the Wifi module as follows:

#include <ESP8266WiFi.h>;
const char* ssid = "ssid";
const char* password = "yourpassword";

//////////////////////////////////////////////////////////////////
void setup()
{
Serial.begin(SERIAL_BAUD);

// We start by connecting to a WiFi network
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);

WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
...

Run and ensure an IP address is set.

Wifi connectivity enabled

So far so good. Wireless connectivity is working too…

Step 3 – Visualisation and Logging with ThinkSpeak

After setting up an account and creating a channel, I was able to get an API key for the sketch code.

Using the code and taking the bits from
https://github.com/squix78/esp8266-projects/tree/master/arduino-ide/thingspeak-data-logger
I was able to send data to ThinkSpeak –

Step 4 – Enabled Deep Sleep to Save Power

To get “Deep Sleep” mode working with D1 WeMOS ESP8266 device I had to connect D0 and RST together. This is required to wake up the controller from deep sleep. This setup really saves a lot of battery power. This difference makes the board run weeks instead of days.

// convert to microseconds
ESP.deepSleep(sleepSeconds * 1000000);

Step 5 – Voltage Monitoring

Additionally, I could also add some voltage monitor too.

Monitoring LiPo battery voltage with Wemos D1 minibattery shield and Thingspeak

However, on a battery circuit, this would reduce the running life, so more research is required for battery monitoring.

http://fettricks.blogspot.co.at/2014/01/reducing-voltage-divider-load-to-extend.html

https://jeelabs.org/2013/05/16/measuring-the-battery-without-draining-it/

https://jeelabs.org/2013/05/18/zero-power-measurement-part-2/indexf587.html

 

Sketch Code

The entire sketch for this post can be downloaded from: https://github.com/glyons/ESP8266-Temperature-Logger

February 21, 2018

Comments

Very interesting. I see you added a link to an article I wrote on logging the battery voltage. Indeed adding a voltage divider for that purpose is an extra drain on the battery. I think I did that article just to see how well the battery shield behaved and I used Thingspeak to log it.
Using Thingspeak in itself is also a bit of a drain on the battery ofcourse, even when using deepsleep, as the ESP8266 has to connect to the WiFi and then to Thingspeak.

For battery run ESP’s in fact I favour to use a bare ESP8266-12F and put that in deepsleep.The BME280 is already a huge advantage over say a combo of BMP280 and DHT11/22 as the latter draws I think some 15mA and needs a 2 sec warm up as well.
Currently testing an ESP8266-12F with BME280 and instead of a voltage divider I just read the Vcc. As I feed the ESP with 2 alkalines, the Vcc is equal to the Vbat.
If using a Lipo, ofcourse you need an LDO and the Vbat is no longer equal to the Vcc, but even then you could use monitoring the Vcc as an indicator for the Vbat. With a decent LDO the voltage drop may be 200mV. That means that when the LiPo drops to < 3.5Volt, there no longer will be 3.3 Volt on the Vcc. The ESP will still work and your LiPo is not critically low yet, but the moment you start measuring say 2.8 Volt, you know it is time to recharge the LiPo.
Admitted… it doesnt give you a nice curve of the True battery voltage but it saves current and you still can see when the LiPo gets critically low.
When I am done testing the battery fed bare ESP12/BME280 combo, I will post that. My current Wemos/BMP280/Wemosbatteryshield/voltagedivider combo (15 min deepsleep) is happily running into its 18th day on a 720mAh battery. Voltage dropped from 4.2 to 3.83 in that time so I guess it may have another week (so 25 days). I therefore guess that a bare ESP8266-12F/BME280 without battery shield or voltage divider will happily run a few months on 2xAA alkalines (but I could be overly optimistic)

Hi Ed,

There seems to be a lot of ways to do the battery monitoring. I need to order a MOSFET p-channel to try out my circuit design sketch. I’m aiming to go for something that’s simple and of course inexpensive.

Currently, my little setup is running nicely for over a week.

Gavin
btw I like your TRIAC dimmer circuit.

Leave a Reply