Low Cost WIFI Temperature (DS18B20) Data Logger Based on ESP8266 With Connectivity to Thingspeak.com

270,483

201

77

Published

Introduction: Low Cost WIFI Temperature (DS18B20) Data Logger Based on ESP8266 With Connectivity to Thingspeak.com

Temperature data logger based on ESP8266 and DS18B20 1-Wire temperature sensor.

Just only $5 ESP-01 board and DS18B20 sensor.

Software is written in LUA language and is running directly in ESP8266.

No other MCU needed!

Step 1: Part List

  1. ESP-01 board - eBay
  2. DS18B20
  3. Step down voltage converter min. 250 mA - AMS1117-3.3 LDO 800mA or LM2596
  4. > 220 uF / min 6.3 V Capacitor
  5. Vero board
  6. Some wires, PIN headers

USB to UART 3.3 V converter - only for programming


Be careful, the max. voltage for ESP8266 for all pins is 3.3V. If you are using adjustable voltage regulator, carefully set voltage to 3.3V.


The power consumption of ESP module is around 250mA when transmitting. You need proper power supply.


Step 2: Flashing LUA Firmware

Check that your ESP8266 has some firmware through any serial terminal program (coolterm, putty, serial monitor in arduino) at 115200 (most probable default speed) Type AT+GMR and you get version of actual firmware.

Congrats, you’ve got a working ESP8266 with a espressif firmware in it.

Now to burn LUA firmware:To Burn a firmware: CH_PD pin must be always connected to HIGH and GPIO0 pin to GROUND (LOW).

Download NodeMCU firmware from: https://github.com/nodemcu/nodemcu-firmware/tree/master/pre_build/0.9.2/512k-flash

Download flashing tool for Windows:https://github.com/nodemcu/nodemcu-flasher

or for Linux: https://github.com/themadinventor/esptool/blob/master/esptool.py

Run windows app for upload firmware or in Linux type:

./esptool.py -p /dev/
 write_flash 0x000000 nodemcu_512k.bin

After burning it, GPIO0 pin should be disconnected from ground in order to reboot in normal mode. Otherwise it will be reboot in UPLOAD mode. So power it OFF, disconnect GPIO0 pin from ground…

Now connect serial terminal with 9600 baud and check if Lua firmware working with:

print(node.chipid())

You get you chip id back..

Done, you have working NodeMcu LUA firmware...

Step 3: Setting Up Thinkspeak.com Account

Thingspeak is open data platform for the Internet of Things.

All data are stored in thingspeak.com. You need thingspeak account. Please register here:

thingspeak.com

Set up one channel and get write API key.

Step 4: Uploading Software

You need some upload tool, you can do it with basic terminal program, but with upload tool is uploading of files much easier.

You can use ESPlorer (need JAVA 8 for running), works on Linux and Windows

http://esp8266.ru/esplorer/#download

Or under Windows Lualoader:

http://benlo.com/esp8266/index.html#LuaLoader

You can get sotware from my github - https://github.com/ok1cdj/ESP8266-LUA/tree/master/Thermometer-DS18B20-Thingspeak

init.lua - this scrip is executed after start

Please modify your WIFI settings in this file here:

wifi.sta.config("SSID","PASSWORD")

ds1820.lua - measure and post data to thingspeak.com

Change you thingspeak API key here:

conn:send("GET /update?key=YOURKEY&field1="..t1.."."..t2.." HTTP/1.1\r\n")

You can change upload period here (default is 1 minute):

tmr.alarm(0, 60000, 1, function() sendData() end )

Upload both files to ESP...

Step 5: Building Final Board

You can build final circuit to piece of veroboard.

Step 6: Final Testing

With terminal app check output from ESP and you will see your IP address after reset and then value of temperature every upload period...

You can see your data in thingspeak like mine:

https://thingspeak.com/channels/21857

4 People Made This Project!

Recommendations

  • Clocks Contest

    Clocks Contest
  • Oil Contest

    Oil Contest
  • Water Contest

    Water Contest

77 Discussions

The firmware is not available anymore...can you please post a screenshot or something with the right modules need to create a firmware that works with the DS18B20 from http://nodemcu-build.com/

Thanks

13 replies

Thanks for that. I managed to make it work with the normal

nodemcu_integer_0.9.6-dev_20150704 bin

I realized that with the custom build for some reason the http server isnt working properly. It only outputs 1 line of code...weird...but the normal bin with an extra .lua file with the ds18b20 library works fine :)

hi. I also encountered the same thing. strange that with the custom build there is no option to add HTTP.

What do you mean by extra lua file with ds18b20 library? Can you share how to do this?

Sure, I've included all the files in the zip, (its for DHT22 and ds18b20).
You just need to edit: init.lua, and add your access point name and password.
Then in mainscript.lua i've enabled only the lua script for the ds. If you want to have the DHT just enable that --dofile("dht.lua") line and disable the ds instead.
And finally in the send.lua, put your thingspeak.com api key. I've include the schematic i used (without the DHT) and where i got my info from. This script will update your Thingspeak channel every 10 min.

https://onedrive.live.com/redir?resid=5A7336416C3E3C61!804&authkey=!AB8zzjtbgWJ-cJs&ithint=file%2czip

I've changed the code a bit since i last posted this. The new one is located here: https://github.com/Sandbird/ESP8266-with-LUA---Thi...

I added a setup page. No need to edit .lua files anymore to add the router/user/pass. You can do that from your mobile. Also i added a safeguard function. If the esp cant find the router anymore, it will enter setup mode again.

Thanks, this works even better! I get a list of AP’s and select one. Also nice how you made it possible to throw away the config file and reselect the Ap.

The only thing is that I have to use a different wiring, with CH_PD pulled up to Vcc with a resistor according to the basic wiring described in http://www.esp8266.com/wiki/doku.php?id=getting-started-with-the-esp8266. When I do not connect it to Vcc nothing happens. I also have to use a 470uF capacitator between Vcc and GND.

It also does not work with 2 AA batteries. My ESP draws more than 100mA. When I connect the batteries the Voltage drops to 2.4 V, which is too low.

To tell you the truth, i dont run it with batteries...this was a diagram i found on the net. I use a jumper to connect vcc with ch, (i soldered the male pins one on each pin and use the jumper on top). I dont use a capacitor....hmm maybe i should? Eventually i might do it with batteries, if i manage to make the 'deepsleep' soldering, and use a step up converter for 2 AA batteries.
I'll probably add the time interval for the loop as an input field in the page...in case people want to be able to change that as well and store the value in the config file.

Works like a dream, thank you for your effort.

I noticed in the ds18b20.lua file that you had a possible option for F readings. Is there a value that I would need to change to allow this?

There was a small problem with float numbers (depending on the firmware you have installed)..so i had to remove the F function in order for the program to compile. I just realized though that you could get away with it by using a small function that doesnt include floats. In the ds.lua you could make a function like this (put a tab in the beginning of the 2nd row):

local function toFahrenheit(c)

return c * 9 / 5 + 32

end

then after: temperature=t.read()

do:

temperature = toFahrenheit(temperature)

This way you'll have a F temp.
If you try to compile that and its not doing it cause of an error, then you have to search in the Nodemcu forum for a firmware that allows float numbers.

Thanks, I will give it a go this evening and update if it works out.

efcharistó

Hi,

Thank you very much for the advice and sharing of code. I will try and let you know.

hi

i want to connect ds18b20 to nodemcu(client) and send data to another nodemcu(server). how can i do that?

After more research I see that you did not mean to actually use "do" in the code.

Its my fault....i should have used pastebin
or something, since instructables doesnt have code friendly posting.
That 'do:' was a referring to you :P...Like 'do this'..its not an actual
command.hehe. I took a look at the code again, and i think there are 2
solutions to this problem. We could either remove the float value from
the Celsius and use the 1st digit only to calculate the Fahrenheit value
(example: 23.5C, use 23 and convert it to F....meaning an
approximation of the temperature), or try to 'hack' the ds.lua
file to show F instead of C. I'll make 2 pastebin versions...Give either
one a try...

1) http://pastebin.com/jb2KBkNK

2) http://pastebin.com/74AeJzXU

I
think you should start with the 2nd method first.. If it works it will
provide an accurate F value. If that doesnt work, then try the 1st
method and report back :)

Hi

I built it, but it doesn't post any data to thingspeak.com.

I get this output:

Sending data to thingspeak.com
Got disconnection...
Last temp: 222500
Temp:22.25.2500 C

Thanks Florian

Hi,

I have been scratching my head for over 2 weeks now.. Can someone tell me what ESP/Lua modules are used for this instructable (ow,wifi,node,net?).

My issue is that:

Case 1: Only Wifi client and web GET function works; posts data (-1.0999)

Case 2: Only Wifi client and Temperature works (Does not post any data).

Tried all kinds of firmware. Integer and Floating. Think that Dallas 18b20 worked last with Floating.

Can anyone upload the firmware and explain what modules I need?

0
user
sylayo

2 years ago

great instructable!

I just have a question (sorry if it look dummy, but I'm pretty new into that world...) would I be able to use this way of programming that board, I mean without using something like an arduino, to, let's say, turn a switch on/off?

I'd like to build an Wi-Fi thermostat for my garage so I can start the heater from my phone before I get there to work. My heater has a basic on/off switch. It would be easy to build it using an arduino but I'm looking for a simpler/cheaper solution.

Thanks