ESP8266 NodeMCU Interface DSB1820

Real-World Use

Where this is useful?

  • Monitoring room or industrial temperature.
  • IoT projects (send temperature to cloud like MQTT, Blynk, or ThingSpeak).
  • Smart home automation (AC/fan control).
  • Data logging for greenhouse or aquarium.

Code of ESP8266 NodeMCU Interface DSB1820

local ow_pin = 1 -- gpio-02
ds18b20.setup(ow_pin)

ds18b20.read(
    function(ind,rom,res,temp,tdec,par)
        print(ind,
            string.format("%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X",
                string.match(rom,"(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+):(%d+)")
            ),
            res,temp,tdec,par
        )
        print("Temp : "..temp)
    end,{});

 

Explanation

  • ow_pin = 1: Here you assign NodeMCU pin D1 (which maps to GPIO2) as the One-Wire bus pin for DS18B20.
  • ds18b20.setup(ow_pin): Initializes the DS18B20 library to use that pin for communication.
  • ds18b20.read(callback, {}): Reads temperature data from all connected DS18B20 sensors.
  • The callback function is triggered for each sensor with these parameters:
  • ind → Index of the sensor (if multiple sensors are connected).
  • rom → Unique 64-bit ROM address of the DS18B20.
  • res → Resolution setting of the sensor (9 to 12 bits).
  • temp → Integer part of the measured temperature.
  • tdec → Decimal part of temperature (precision after decimal point).
  • par → Parasite power flag (1 if parasite powered, 0 otherwise).

Output of ESP8266 NodeMCU Interface DSB1820

1   28:FF:4C:60:91:16:05:3C   12   26   5   0
Temp : 26
Please turn AdBlock off, and continue learning

Notice for AdBlock users

Please turn AdBlock off
Index

Discover more from ArunEworld

Subscribe now to keep reading and get access to the full archive.

Continue reading