ESP8266 - Building a cheap wireless thermometer

So my ESP8266 modules finally arrived just in time for a quick project.

The problem, my parents that live up north are heading out of town for a while and to calm my fathers nerves he would like to know if the house gets below freezing. I thought I would whip up a quick wireless thermometer for him as my first ESP8266 project.

First I couldn’t be bothered to build my own firmware for this so instead I used this lua firmware. My project is simple enough so I felt this would do the trick.

To program this firmware I used esptool.py to upload the custom firmware on to the device using a 3.3v usb to serial adapter. Note GPIO 0 needs to be set to low to enable firmware update mode.

./esptool.py -p /dev/<path-to-serial> write_flash 0x000000 nodemcu_512k.bin

Firmware now updated I can connect via serial to see if wifi is working:

> wifi.setmode(wifi.STATION);
> wifi.sta.config("<ssid>","<password>");
> print(wifi.sta.getip());
192.168.0.120

Success! I’m connected.

Using a MCP9808 I connected this i2c temperature sensor to GPIO pins 0 and 2 on the wifi module, to read the values I used this:

id=0
sda=9 --GPIO2
scl=8 --GPIO0
i2c.setup(id, sda, scl, i2c.SLOW)

function read_reg(dev_addr, reg_addr)
  i2c.start(id)
  i2c.address(id, dev_addr ,i2c.TRANSMITTER)
  i2c.write(id,reg_addr)
  i2c.stop(id)
  i2c.start(id)
  i2c.address(id, dev_addr,i2c.RECEIVER)
  c=i2c.read(id,2)
  i2c.stop(id)
  return c
end

tempval = read_reg(0x18, 0x05)

This gives me a 2 byte value of the current temperature and since I have no idea how to bit shift in lua I thought I would just send both byte values to one of my servers running node.js to process.

conn=net.createConnection(net.TCP, 0)
conn:connect(300 0,"<hostname>")
payload = "{\"current\":[" .. string.byte(tempval,1) .. "," .. string.byte(tempval,2) .. "]}";
conn:send("PUT /<uri> HTTP/1.1\r\n"
.."Host: <hostname>\r\n"
.."Content-Type: application/json\r\n"
.."Content-Length: " .. payload:len() .. "\r\n"
.."Connection: close\r\n"
.."\r\n"..payload.."\r\n") 

Data is sent. Since everything is looking good I wrapped the read_reg and upload in a function then ran this on a timer to execute every 20 seconds. Now when my parents want to see the temperature they can view the webpage and see the current temp and historic chart.

All that is left for this is to add a voltage regulator and some sort of power source and it’s ready to go.

3 Likes

This looks great… At one time I had a bunch of 18B20 1 wire sensors strung around the house and graphed the temperature of pretty much everything…

On a related topic you may want to get your parents to check with their insurance company to see what coverage they have if the house is unoccupied. Most home insurance riders will not cover you for specific things (like frozen pipes and related flooding) if you don’t have someone checking the home every few days… I had friends go through this…

But with your system at least they can get someone to visit the house if they see the temperature dropping…

Is the source for that firmware available? I can’t find it.

What I’d like to do with one of these things is get lower level access to the wifi module and see if I can put it into monitor mode.

They haven’t released the source for the lua firmware but you can build your own custom one:

http://bbs.espressif.com/viewtopic.php?f=5&t=2&sid=f682e316fc48a3b73805773b6b12b892

It’s pretty ghetto right now, they provide a virtual box instance pre-configured with the tool chain needed to build your own firmware.

See this as well: Toolchain · esp8266/esp8266-wiki Wiki · GitHub

This is awesome. I might have to grab a few of these. What are you going to use to power it? A few AA batteries look like they’d last about 10 days by really rough estimation.

I haven’t really decided yet, it would be pretty neat to power it with a 3.7v lipo with an integrated charging circuit.

Once I figure out how to get this thing in/out of deep sleep I’m sure this will use hardly any power between readings.

Do you want 802.11 or BLE, ANTIf you want BLE, ANT, the nordic nrf51422 is the way to go. It includes an ADC.

I can provide you with support for the firmware, which includes deep sleep. For the absolute minimum power consumption, I recommend a low power mcusuch as STM32L151.

The problem with the nrf51422 is user programs do not have access to the DMA andit is not easy out of the box to run programs from memory. The most efficient way totake measurements is to run the small measurement program from memory.

Well this is just for messing around, 802.11 is what i’m looking for and something really cheap. For $2 these little boards are pretty handy.

So I got deep sleep working on this ESP-01 boards. I basically attached XPD_DCDC from the chip directly to the reset pin so now it sleeps. According to my power supply it’s using 1mA while asleep, could be less, i’m thinking now if you don’t need to upload a lot of samples you could get a decent amount of battery life with this guy.

Which brings me to my next question, what’s the best/easiest way to measure the total amount of power that was used in a small circuit over a given period of time? I would like to measure how much power was used during each sample upload so I can get an idea for battery requirements.

For BLE

1mA sleep at 3.3V is way too high. 2mA average 3.3V is the operational current.

10uA to 20uA sleep is about right

With these specs you can get nearly a year out of a coin battery

With regards to measuring current, a resister and digital storage scope 1M of storage is preferred anything less and you can hardly see what is happening. I am currently using a scope with only 4K of storage. It only gives you a rough idea.

This will can give you pretty good idea of your current consumption.

Longer term, plugging a battery in and measuring how long it takes to drain is a remarkably good and simple approach.

On this note, I would like to get together with members and purchase a digital storage scope with lots of memory, for this very purpose.

1 Like

To start a good voltmeter will give you a just as good estimated average current. Surprising just as good, perhaps better then a scope with only 4K of storage.

It will not now show the current during transmission pulses. But it will give you very accurate sleep current.

Thanks @tdwebste, that makes sense. I think the lowest my power supply will display is 0.001 amp so it very well could be using 10uA, the spec sheet claims 12uA.

I think I need a better voltmeter, mine at home didn’t register anything on the mA side when it was sleeping. I was hoping there was something cheap that I could just plug in to the circuit that would tell me. I currently use this for my quadcopters, a low current version would be handy.

Dave Jones’s uCurrent is specifically for low-current measurement. I donated one to the space a while ago… it’s somewhere… on a crate… :stuck_out_tongue: I have another I can lend you in the meantime @garthomite.

His article on its design goes into great detail of why a multimeter alone is useless for the purpose: http://alternatezone.com/electronics/ucurrent/uCurrentArticle.pdf

The uCurrent that the space has is designed for this kind of thing! It’s in the bottom third of pallet second from the bay doors.

Awesome thanks guys!

I can wait until it’s happily unpacked in its new home. In the time being my next project with these is to take the SMD form factor like this guy and learn how to make a PCB for them. I want to make a simple prototyping board that is powered by USB, has an optional USB-serial IC, on board voltage regulator and most importantly not go up in blue smoke.

For free Schematic Capture packages, Eagle used to be the best, but I think it’s rapidly getting left behind in the dust by KiCad. CERN throwing their weight behind KiCad helps

I have used the dave jones uCurrect,

Warning it will clip if you try to use it both in an out of sleep.I found a simple 10 ohm resistor with a scope was actually better, because I had more dynamic range.

Great circuit be needs a design up upgrade to increase its dynamic range.

IIRC there’s nothing in the design that limits the dynamic range - only the multimeter that’s plugged into it will be the limitation. I could be wrong, but pretty sure at least that this is the case…

richard, can you please post the schematics.

In my experience using it the dynamic range is limited.

The article I linked to goes over its design in detail along with some schematics (it’s closed source, but a quite simple circuit - the devil’s in the details). Reading it again, it does look like you’re correct; on the uA range you’d be limited to ~1.3mA due to the battery voltage. I suppose the easiest work-around would be to have 2 uCurrents, one on the uA range and one on the mA range, each connected to a channel of a scope.