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

Picture of Low Cost WIFI Temperature (DS18B20) Data Logger Based on ESP8266 With Connectivity to

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

Picture of 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

Picture of 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:

Download flashing tool for Windows:

or for Linux:

Run windows app for upload firmware or in Linux type:

./ -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:


You get you chip id back..

Done, you have working NodeMcu LUA firmware...

Step 3: Setting Up Account

Picture of Setting Up Account

Thingspeak is open data platform for the Internet of Things.

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

Set up one channel and get write API key.

Step 4: Uploading Software

Picture of 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

Or under Windows Lualoader:

You can get sotware from my github -

init.lua - this scrip is executed after start

Please modify your WIFI settings in this file here:


ds1820.lua - measure and post data to

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

Picture of Building Final Board

You can build final circuit to piece of veroboard.

Step 6: Final Testing

Picture of 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:


Elakit made it! (author)2015-09-17

Holy crap, I got it working! While there was a large amount of googling, and some trial and error, your instructable provided a solid outline for what to do. I created an account just to say thank you.

As for the photo, ignore the mess of wires this breadboard is set up to program two different ESP8266 chips and I already unplugged the FTDI chip. If anybody needs help on this still, I'll be glad to help.

FilipT16 (author)Elakit2017-02-01

Hi Elakit, I have same problem -1.0999 C all the time. I'm using ds18b20. Can you help me please?

DoodiD (author)Elakit2015-09-25

Hi Elakit, I am getting -1.0999 C all the time.

Can you help me please?

Elakit (author)DoodiD2015-09-25

I can definitely try! What is the model number of the temperature probe that you are using?

DoodiD (author)Elakit2015-09-26

Is it matter?
The value is stack no matter which voltage GPIO0 is getting.

Sandbird (author)2016-01-15

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


limbo (author)Sandbird2016-01-21

Go to

don't forget to add 1-wire. Use master branch!

Sandbird (author)limbo2016-01-21

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 :)

fespehana (author)Sandbird2016-03-25

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?

Sandbird (author)fespehana2016-03-25

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 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.!804&authkey=!AB8zzjtbgWJ-cJs&ithint=file%2czip

linkerhand (author)Sandbird2016-12-28

Great addition, this works for me!

Sandbird (author)linkerhand2016-12-28

I've changed the code a bit since i last posted this. The new one is located here:

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.

linkerhand (author)Sandbird2016-12-30

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 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.

Sandbird (author)linkerhand2016-12-30

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 case people want to be able to change that as well and store the value in the config file.

ColorBomb (author)Sandbird2016-06-01

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?

Sandbird (author)ColorBomb2016-06-02

There was a small problem with float numbers (depending on the firmware you have installed) 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


then after:


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.

ColorBomb (author)Sandbird2016-06-02

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


Sandbird (author)ColorBomb2016-06-02

ahahaha 'parakalo'

fespehana (author)Sandbird2016-03-29


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

sumitkakkar89 (author)2016-10-18


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

ColorBomb (author)2016-06-04

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

Sandbird (author)2016-06-04

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...



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 :)

Florian12343 (author)2016-03-01


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

I get this output:

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

Thanks Florian

USMCWarmachine made it! (author)2016-02-13

Had the whole thing up and running in a few hours, not bad for the first test project with an esp8266 and 1m ds18b20. Did run into an issue with the same temp reading error as others have, but solved it by making sure all the grounds were tied to the same common. No resistor required, and running the nodemcu_integer_0.9.6-dev_20150704 bin

From start to finish trend. You can see where the data was bad, when it was corrected, and three different locations tested (peak was from holding in hand for a few minutes).

Mr2clean (author)2016-01-24


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?

limbo made it! (author)2016-01-21

Project is (almost*) working under any nodemcu build.
I have a couple of modules running with custom build firmware from the master branch. Of course One wire library should be included to build as well uart and some other basic libraries.

* almost means that I had to change/correct few things on the code in order to make it run since some part lead me to "PANIC" messages.
Anyways I'm happy with the final solution.

sylayo (author)2015-11-22

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.


zagryl (author)sylayo2015-11-30

You could do it with an ESP8266, connected to your WIFI router. ESP has two usable GPIOs. Use one as OneWire interface for the DS1820 thermo probe, other pin on the ESP as an output to a relay that turns on your heater. Things you would need are:


Relay(two channel, one is enough)->

Power supply, 220/110 -> 3.3V(BE CAREFUL 220V) ->

Temperature probe(DS18B20) ->

FTDI module to program the ESP8266 ->

BE CAREFUL WITH FTDI MODULE DRIVER VERSION. Because if you install the latest driver, they will literally overwrite your USB device, making it useless, and you won't be able to use it without some serious hacks. Use driver named ->, and no newer versions.

You would have to play around with writing the LUA program for it (and getting the NodeMCU firmware in it first place with the FTDI). I will put my LUA program below, what I've done so far, but don't expect it to work as it's not nearly finished yet. It's similar to your needs.

Other things important to add are:

- in AP mode, ESP cannot have a fixed IP address. You should make your router assign always the same IP to the MAC address of your ESP8266. You get the MAC address by running wifi.sta.getmac() in the ESP8266 console..

- if you want to access your ESP8266 from the internet from your mobile you need to add port forward in your router NAT settings. So forward some external port, such as 8080, to the internal IP address of your ESP, and port 80.

Remember there is no safety here, so if someone scans your open ports and finds your interface at 8080, he'll be able to switch your heating on and off... :)

This code doesn't look at the temperature anywhere, just has a function to read it. Haven't tested it yet.. It has a web server, running on port 80, and options to switch outputs on and off.

---------start of code below, simplify it, change it, play with it and put it in a file named init.lua and get it in your ESP8266

--python --port COM6 --src init.lua --dest init.lua --verbose

print('init.lua ver 1.2')


print('set mode=STATION (mode='..wifi.getmode()..')')

print('MAC: ',wifi.sta.getmac())

print('chip: ',node.chipid())

print('heap: ',node.heap())

-- wifi config start


-- wifi config end





function toggle(pin)


status =

if (status == 1) then






function holdup(pin)








function holddown(pin)








function mysplit(inputstr, sep)

if sep == nil then

sep = "%s"


local t={} ; i=1

for str in string.gmatch(inputstr, "([^"..sep.."]+)") do

t[i] = str

i = i + 1


return t


-- A simple http server





if string.find(payload,"sethigh0") then



if string.find(payload,"setlow0") then



if string.find(payload,"sethigh2") then



if string.find(payload,"setlow2") then



if string.find(payload,"toggle0") then



if string.find(payload,"toggle2") then



if string.find(payload,"holdup0") then



if string.find(payload,"holdup2") then



if string.find(payload,"holddown0") then



if string.find(payload,"holddown2") then



if string.find(payload,"reset") then



start = string.find(payload,"atoggle:")

if (start) then

endd = string.find(payload,";", start + 9)

parametar = string.sub(payload,start+9,endd)




pin0 =

pin2 =

ret = wifi.sta.getip() .. "\r\n"

ret = ret .. "D0=" .. pin0 .. "\r\n"

ret = ret .. "D2=" .. pin2 .. "\r\n"



conn:on("sent",function(conn) conn:close() end)


function getTemp()

addr = ow.reset_search(pin)



if (addr ~= nil) then

crc = ow.crc8(string.sub(addr,1,7))

if (crc == addr:byte(8)) then

if ((addr:byte(1) == 0x10) or (addr:byte(1) == 0x28)) then

ow.reset(pin), addr)

ow.write(pin, 0x44, 1)


present = ow.reset(pin), addr)

ow.write(pin,0xBE, 1)

data = nil

data = string.char(

for i = 1, 8 do

data = data .. string.char(


crc = ow.crc8(string.sub(data,1,8))

if (crc == data:byte(9)) then

t = (data:byte(1) + data:byte(2) * 256)

if (t > 32768) then

t = (bxor(t, 0xffff)) + 1

t = (-1) * t


t = t * 625

lasttemp = t

print("Last temp: " .. lasttemp)






addr =

until(addr == nil)


function sendData()


t1 = lasttemp / 10000

t2 = (lasttemp >= 0 and lasttemp % 10000) or (10000 - lasttemp % 10000)

print("Temp:"..t1 .. "."..string.format("%04d", t2).." C\n")

-- conection to

print("Sending data to")

conn=net.createConnection(net.TCP, 0)

conn:on("receive", function(conn, payload) print(payload) end)



conn:send("GET /update?key=YOURKEY&field1="..t1.."."..string.format("%04d", t2).." HTTP/1.1\r\n")


conn:send("Accept: */*\r\n")

conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n")



print("Closing connection")



conn:on("disconnection", function(conn)

print("Got disconnection...")



--well.... good luck :)

godfish (author)2015-09-20

I through my hat in the ring and it came back and hit me in the face! I couldn't get this to work. and I'm not good enough to even try and see what's wrong. I really liked the ESPlorer, Everything work but all I got to Thinkspeak was --1.0999 C Ouch.. Oh well maybe someone can crack it, Not bad though I only wasted about 4 hours.

strontzak (author)godfish2015-10-20

i solved this problem by downgrading the firmware to




godfish (author)strontzak2015-10-20

Hmm, great.. Can you post the link to the firmware?

Elakit (author)godfish2015-09-25

Hi Godfish, what's the model number of the temperature probe are you using?

godfish (author)Elakit2015-09-26

DS18B20 nothing special.

tiking (author)2015-09-25

There is a documented bug for the one wire library in the latest version of NodeMCU 0.9.6. The bug affect particularly the,addr) function. It can temporarly be replaced by this snippet :

ow.write(pin,0x55, 1) -- 0x55==search aka select command

for i=1,8 do

ow.write(pin,addr:byte(i), 1)


That fixed the problem for me.

mnørgaard (author)tiking2015-10-07

You're awesome - that fixed my problem. Thanks!

xlaser (author)2015-07-13

Could not get this project working with the waterproof (1m of cable) version of the DS18B20. Works fine on the Arduino but not on the ESP8266. Scope shows the lines going high and low on pin GPIO0. I suspect the pulse timing is corrupted by the capacitance in the length of cable. Has anybody else tried this with the waterproof version?

Elakit (author)xlaser2015-09-17

I got it working using the DS18B20s.

xlaser (author)Elakit2015-09-18

Can you be more scientific! 15 years ago scientists announced they had achieved 'Cold Fusion'. Nobody managed to repeat the experiments that led to the claim. In this case we need to know exact details. What version of Lua firmware did you use, what version of the esp8266 did you use and publish your code and connection details? Only then can we repeat your experiment and substantiate you claim.

Elakit (author)xlaser2015-09-18

Hopefully this helps, if not, let me know what you're getting stuck on and I'll try and help.

Components Used:

Vktech DS18B20 - B00QGN0LKY - Output lead:red (VCC), yellow(DATA) , black(GND)

Addicore ESP8266 EXP-01 - B00PA3UQNI - Same as

FT232RL FTDI USB to TTL Serial Adapter - B00HSX3CXE

Cable made from a USB motherboard cable similar to B004RS5OYI

Velleman 1A 1.5V-40VDC Power Supply Kit - B0002Z82PS - Had it lying around. 15.67vdc in, 3.247vdc out.

Rough sequence:

Wiring Schematic (with the addition of my external power supply tapped onto the 3.3v and ground lines) - - Via

Breadboard Photo (lower button is reset, upper is programming mode, two sets of four 10k resistors in parallel as I didn't have any 2.5 resistors lying around) -

Communications port settings - COM3 at 9600bps 8 Data Bits, No Parity, 1 Stop Bit, and No Flow Control

Firmware - ESP8266_AT_V00180902_04 (0018000902-AI03) - From Addicore -

Flasher - ESP8266_flasher_V00170901_00 - - VIA

Terminal - Using PuTTY to confirm firmware update and nodemcu install works ('AT+GMR' and 'print(node.chipid())' commands respectively).

Notes: I didn't trust Addicore to have updated firmware on the ESP, so I attempted flashing new firmware. This was the biggest headache of the thing. Received a ton of errors when trying to flash the firmware, almost all of them were "invalid packet header". I just kept trying to reflash a dozen times or so, eventually it worked. After that, the nodemcu installed the first time.

NodeMCU - nodemcu_float_0.9.5_20150318.bin - Available from

LUA Files - ESPlorer ( to upload init.lua and ds1820.lua

Probe Hookup (minus the filter capacitor, TXD, and RXD leads) - - From ok1cdj

xlaser (author)Elakit2015-09-19

Thanks for the detailed description.

I see that you had the same issues that I did in flashing the 8266.

I attempted the nodemcu_int_0.9.5_20150318.bin and could not get the DS18B20 to work. The Wi-Fi worked OK.

Testing the 5.1.4 20141230 the DS18B20 worked but the Wi-Fi did not.

Tends to suggest that its either a firmware content issue or that the firmware is not correctly uploading into the 8266. Judging by the fact that several people claim success using the same firmware that fails for others, leads me to believe that the firmware loaders are not sophisticated enough to verify the firmware upload. The errors that I/we get when trying to run the main Lua application program suggests that the interpreter is not recognizing some commands.

This points to corrupted firmware.

Conclusion: the problem lies in the firmware uploaders reporting success based on data sent to the 8266 rather than verifying that the content is safely stored in 8266 flash memory.

Elakit (author)xlaser2015-09-18

Ah, you are still interested. I didn't want to go through all that work on a comment from two months ago unless the information was still needed. I'll write up the details and post it for you in a couple hours.

LeePatch (author)2015-07-25

Really struggling with this project in getting it to work, I have the same hardware as described here, I have a DS18B20 waterproof with a cable. xlaser suggested it may be due to capacitance on the cable, I have had difficulties with getting Dallas 1 wire to work before a while ago and remember it being the cause of much frustration and many late nights changing any thing I could think of to get these things to work. I can get mine to work flawlessly on my Arduino however not on the ESP8266 out of frustration I cut off the cable on my waterproof sensor to prove it was not a cabling issue and still cannot get it to work. would be grateful if anyone who has got this to work to reply with their setup; model of ESP8266 what they are programming their ESP8266 with exactly all files on ESP8266 when it works for them and also what version of LUA and what version firmware they are using on their ESP8266

Elakit (author)LeePatch2015-09-17

If you still need help on this, let me know. I just got it working myself.

CharlesM10 (author)2015-07-29

Hi, I understand the ESP8266 is simply used to program the device - and is removed once the "prototype" has been configured.

I already have an Arduino Nano - could this be used in place of the ESP8266?


Elakit (author)CharlesM102015-09-17

Hi, the USB to UART adapter is used to program the ESP8266. The USP to UART adapter is removed after programming, and the ESP8266 handles the temperature logging and wifi connection. Arduino Nanos don't have wifi built-in.

LeePatch (author)2015-07-26

OK so another 6 hours lost on this with no improvement but a slightly higher sense of frustration (I am very patient and persistant), i have got stable power supply, tried pull ups from 1k to 10k in 500R increments, and tried no pull up direct powered and parasitic powered and still got no further tried on 01 hardware as well as 12 version am i missing something, version of firmware, lua version, libraries, I get no errors just dont get any values just -1.0999 C in serial monitor and on thingspeak. Would love to know exactly what setup this has worked on for others so I can attempt to replicate it and hopefully locate where I have been going wrong and save others frustration.

Elakit (author)LeePatch2015-09-17

If you still need help on this, let me know. I just got it working myself.

xlaser (author)LeePatch2015-08-02

Update on my experiments with this project show that the most likely cause of these problems is the firmware and not cable capacitance as I suggested previously. I only got the DS18B20 to work on build 20141230, but then the Wi-Fi failed to work. Reasons are most likely related to one wire bus critical timing which have to be exactly right to work. The ESP is most likely an event driven device which means it is forced to do other (WI-FI) tasks while attempting to control the timing critical bus pulses. Hence it will explain why different versions of Lua firmware will behave differently. Physical (cable) capacitance in the circuit as suggested before potentially could affect the shape and timing of the one-wire pulses, but only experimentation will show to what extent and what the maximum cable length would be. My advise is not to use the ESP for processing. That was not what it was designed to do. Use a Arduino Uno for the temperature manipulation and send the data to the ESP for transmission only. Fewer hours of sleep will be lost!!!

jojaniittu (author)2015-08-09

How can you choose what firmware to flash? I dont get it..

I want to try older fw version because I also have -1,0999 temperature reading.

About This Instructable




More by ok1cdj:Low cost WIFI temperature (DS18B20) data logger based on ESP8266 with connectivity to 22 basic electronics circuits made with Electra I - modular electronics education KITPaperduino Tiny
Add instructable to: