ESP8266 + ds18b20 + thingspeak+ nodemcu
New greatly updated tutorial in new post with NodeMCU dev board and ArduinoIDE. A lot simpler approach.
Update with deep sleep now in new post. Testing the battery operation time in progress.
Updated the connection drawing with updated Fritzing part of ds18b20 with correct pin order also in the breadboard view. In the schematics the part was wired properly all the time. Note: don’t trust computers.
Simple temperature logger for your wifi surroundings is actually quite simple.
- ESP8266, wifi-enabled microcontroller board with gpio
- DS18B20, maxim 1-wire temperature sensor
- 4k7 ohm resistor, some wire
- 3v power source, for short term testing 2*1,5V AA batteries
Nodemcu firmware for ESP8266 is quite easy to work with. There is a module to interact with 1-wire temperature sensor readily available.
To set things up you also need a TTL converter, for example USB To RS232 TTL PL2303HX Auto Converter Module.
What you first need to do is connect ESP8266 to the ttl converter, 3.3v to VCC, GND to GND, RX to TX, TX to RX. And to enable the esp8266 you also need to connect CH_PD to VCC. After this you should be in a state where you can communicate with esp8266 using a serial console program and AT commands. After successful start the first thing is to get NodeMCU running on the ESP8266.
After flashing rebooting the ESP8266 without GPIO0 connecter should bring up some version strings to the serial console stating NodeMCU. This is good news as then all needed to do is to wire up the ds18b20 and upload init.lua and dallas.lua scripts. You also need to upload lua 1-wire -module (ds18b20.lua) to ESP8266.
Good tool to deal with ESP8266 and lua-scripts is ESPlorer. It lets you run scripts, upload files, run snippets and do bunch of other useful things with your ESP8266.
Before uploading init.lua set up your wireless network credentials.
print(wifi.sta.getip()) wifi.setmode(wifi.STATION) wifi.sta.config("apname","password") print(wifi.sta.getip()) dofile('dallas.lua')
And before uploading dallas.lua set up your API-key for thingspeak.com.
require('ds18b20') port = 80 -- ESP-01 GPIO Mapping gpio0 = 3 ds18b20.setup(gpio0) function sendData() t1=ds18b20.read() t1=ds18b20.read() print("Temp:"..t1.." C\n") -- conection to thingspeak.com print("Sending data to thingspeak.com") conn=net.createConnection(net.TCP, 0) conn:on("receive", function(conn, payload) print(payload) end) -- api.thingspeak.com 184.108.40.206 conn:connect(80,'220.127.116.11') conn:send("GET /update?key=Q67WTIRSOWGXJEO&field1="..t1.." HTTP/1.1\r\n") conn:send("Host: api.thingspeak.com\r\n") conn:send("Accept: */*\r\n") conn:send("User-Agent: Mozilla/4.0 (compatible; esp8266 Lua; Windows NT 5.1)\r\n") conn:send("\r\n") conn:on("sent",function(conn) print("Closing connection") conn:close() end) conn:on("disconnection", function(conn) print("Got disconnection...") end) end -- send data every X ms to thing speak tmr.alarm(0, 60000, 1, function() sendData() end )
Run and enjoy.
The lua-scripts are in github.