ESP8266 + ds18b20 + thingspeak+ nodemcu

You may also like...

40 Responses

  1. Chris says:

    When I try this Lua reports:

    ds18b20-B.lua:1: module ‘ds18b20’ not found:
    no field package.preload[‘ds18b20’]
    no file ‘ds18b20.lua’
    no file ‘ds18b20.lc’

    I’d appreciate some guidance as to how to fix it.

  2. Sam says:

    Hi, I would like to first thank you about sharing this nice topic.
    Do you have any idea regarding hte battery life. ?

    Cheers

    • kengu says:

      The code as-is is not optimized in any way to preserve energy. Running it with a powerbank containing 2*2800mAh 3.7v lithium cells it did run for 5 days. With those AA-batteries it depends on the batteries but I would say something along the same lines. I never did prolonged testing with that code and AA-batteries.

  3. hanza says:

    code does notwork with negative temperatures below 0

    • kengu says:

      Might be true. Feel free to fix it and publish the outcome. The example code is used for indoor temperature logging so no testing with negative temperatures.

  4. Pee says:

    Pystyykö tuohon kytkemään useamman ds18b20 anturin?

  5. Luminaric says:

    Nice write-up. But I have a problem. When I run the above Lua program I am getting “attempt to index global ‘ds18b20’ (a nill value). Any idea why?

  6. Blaku says:

    If I’m not mistaken the DS18B20 is drawn as a mirror image of the actual package in both images. The pin names are correct though; the resistor is and should be a pullup. Note that it can also be run in parasitic mode by tying VDD to GND.

  7. Mikko says:

    Really nice article!

    I’m getting “Got disconnection…” every time it tries to connect to thingspeak.
    It is connected to my network and gets a ip but for some reason it does not upload any data.
    I have set up my api keys properly.

    Do you have any ideas what I could try?

    ———– serial log
    =wifi.sta.getip()
    10.101.29.125
    > Temp:26 C

    Sending data to thingspeak.com
    Closing connection
    Got disconnection…
    ———–

    • JR01 says:

      Hi, I have the same problem, it seams that the ds18b20 is read properly, if I hold the sensor, the temp reported goes up, but, as yours, it does not save to thingspeak. I tested with same API key in a browser from my computer, and that works. So I assume that the ESP-03 is not getting to send over internet to thingspeak.
      =====dallas.lua reports the following: ======
      Temp:33.5 C

      Sending data to thingspeak.com
      Got disconnection…
      =====whilst the wifi.sta.getip() reports, thus I assume all okay with wifi settings, and I can ping it=====
      > =wifi.sta.getip()
      192.168.2.61 255.255.255.0 192.168.2.1
      =========
      Does anybody have an idea on where I must look?
      I also tried another s1820.lua solution on git, and have the same issue, thus suspecting esp-03 not getting onto internet ???

    • kengu says:

      There is now updated tutorial on using ESP8266 and with ArduinoIDE. It might be easier to try that approach and get rid of the lua related problems. https://vaasa.hacklab.fi/2016/02/06/esp8266-on-nodemcu-board-ds18b20-arduinoide-thingspeak/

  8. Frank says:

    In your diagram the DS18B20 is drawn the wrong way round!! My DS18B20 got really hot when i connected it like in your diagram.

    Please correct the image!

    • kengu says:

      The schematics was correct all the time. The part was just errorneous in the parts library of Fritzing and thus produced a faulty image with pin orders. Now fixed. Never trust computers.

  9. Chris says:

    Hey thanks for creating this guide! I followed your instructions and it works great. Like some have already mentioned the picture shows the DS18B20 pins reversed but that was easy to correct. Now that I have the temperature posting to thingspeak I was wondering if you know how to modify the code to display F instead of C. Again thanks for sharing your work!

    • Jason says:

      Chris,
      I used this little function to do that in my dht11 module.

      local function toFahrenheit(c)
      return c * 9 / 5 + 32
      end

      just apply the math and bam!!! Fahrenheit 🙂

    • kengu says:

      Now fixed the image with a fixed part for Fritzing with right pin-order in the fancy looking breadboard picture also.

  10. George says:

    Just a question;
    You are doing this in your code:
    t1=ds18b20.read()
    t1=ds18b20.read()
    print(“Temp:”..t1..” C\n”)

    You read the temperature twice,
    is it because that you want to avoid the reset value that is 85°C?

    • kengu says:

      Now that you say that.. I have no idea why it is read twice. But maybe the reason is as you stated to skip the 85C. Or could it be just a typo on cleaning up the code and thus multiplication of a line there.

    • lee says:

      Nice write-up thanks. I got 85C result before it was called twice – then I got 20C correctly, so it appears it is needed.

  11. Pawel says:

    Why there is resistor between DQ and VDD ?

    • croscwa says:

      The resistor is a pull-up resistor for the data line. This insures that a reliable stream of 1’s and 0’s come out of the sensor.

      There are several examples on the Internet where there is no resistor. The data stream relies on a ‘parasitic’ voltage for the data stream, which usually works, but not always.

  12. Frank says:

    Can you explain the code:

    conn:on(“sent”,function(conn)
    print(“Closing connection”)
    conn:close()
    end)

    Is this checking to make sure the send has worked?

  13. Mike says:

    I suspect the 85C / 20C 2 reads is because of not enough delay after issuing a convert cmd to the ds18b20, if the DS18b20 is operating in parasite mode [ no +5Volts] then need to delay 750Ms+
    I’m not sure how much delay is needed if using non parasite- see data sheet

  14. Charles says:

    Have all 3 LUA files on the device…

    Am using the “fixed for negative values” of ds18b20.lua from here (https://github.com/sza2/nodemcu-firmware/commit/5a629e429752c5f99d1233cb133bdf614fb7d7c0) as Im wanting to use this as a freezer temp monitor.

    Running the files on the ESP8266 using ESplorer, I get the following:

    error loading module ‘ds18b20’ from file ‘ds18b20.lua’:
    ds18b20.lua:11: ‘=’ expected near ‘local’

    Line 11 is

    “local modname = …”

    direct from the original file.

    Is “…” correct, or am I supposed to change this to something?

    FWIW, this is running direct from the programmer usb doodah – I dont have the resister / temp chip on the board yet… just wanted to see if the script ran ok before I take it out of scripting mode for the final build.

    Thanks 🙂

  15. Alfredo says:

    Hi, thanks for your help in writing this code.
    I am trying to implement this example with en ESP8266 dev board, and I’m getting this message :

    Config done, IP is 192.168.0.25
    PANIC: unprotected error in call to Lua API (error loading module ‘ds18b20’ from file ‘ds18b20.lua’:
    ds18b20.lua:114: malformed number near ‘1.8’)

    Any idea on what’s going wrong ? Thanks in advance for your support !

  16. Alex says:

    Hi, I’m trying to use same code, but when execute ” t.setup(gpio0) ” i see:
    attempt to index global ‘t’ (a boolean value)
    I think my ” t = require(“ds18b20″) ” doesnt work, but ds18b20.lua and ds18b20.lc are exist…

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.