This tutorial of Robo India explains, how to use DS18B20 Temperature Sensor with NodeMCU.
1. Introduction:
This module is used to measure temperature. DS18B20 are one wire bus protocol, which requires only one data line for communication with NodeMCU.
1.1 Features:
1. Measures temperature from -55 degree C to 125 Degree C.
2. 0.5°C Accuracy from -10°C to +85°C
3. Programmable Resolution from 9 Bits to 12 Bits
4. No external components required.
5. Unique one wire interface which requires only one port for communication.
2. Hardware required
S.No. | Item | Quantity |
1. | NodeMCU | 1 |
2. | Breadboard | 1 |
3. | DS18B20 Temperature Sensor | 1 |
4. | Resistor 4.7K | 1 |
5. | Male to male Jumper | 3 |
3. Circuit Diagram
Make the following connections with Arduino-
4. Library File
Following library will be required to run this sketch. Download the zip file extract the same and copy this to your Arduino library folder.
This library file should be placed at the install folder of Arduino. I have a 64 bit Win7 OS and my Arduino library folder address is located at
C:\Program Files (x86)\Arduino\libraries
You may download OneWire library file from here.
You may download DallasTemperature library file from here.
5. Programming
You may download this Arduino Sketch from here.
#include <DallasTemperature.h> #include <OneWire.h> #define ONE_WIRE_BUS 4 //D2 pin of nodemcu OneWire oneWire(ONE_WIRE_BUS); DallasTemperature sensors(&oneWire); // Pass the oneWire reference to Dallas Temperature. void setup(void) { Serial.begin(9600); sensors.begin(); } void loop(void) { sensors.requestTemperatures(); // Send the command to get temperatures Serial.println("Temperature is: "); Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire delay(500); }
6. Output
If you have any query please write us at support@roboindia.com
Thanks and Regards
Content Development Team
Robo India
https://roboindia.com
#define ONE_WIRE_BUS 4 //D1 pin of nodemcu
It is not D1 pin of nodemcu it is actually D2
so connect 18b20’s out to D2.