DS18b20 is a temperature Sensor module which works on single wire protocol. The reason to choose DS18b20 as a temperature sensor is because, we can interface many DS18b20 sensors on single wire. So we do not need extra pins for interfacing as well as we also do not need analog pins. Because ESP8266 Nodemcu module has only single analog pin, so it is not wise to use it for such sensors which could easily be replaced with the digital output like DS18b20.
DS18b20 Main Features
According to the ds18b20 datasheet the main features of this sensor are as follows
- Power range is 3.0v to 5.5v
- It can measure temperature from -55°C to +125°C
- ±0.5°C accuracy from -10°C to +85°C
- Thermometer resolution is programmable from 9 to 12 bits
- ESP8266 NodeMCU module
- DS18b20 Temperature Sensor
- 4.7K Resistor
- Male to male jumpers or 0R resistors
- Serial Terminal Software for viewing the output
DS18b20 is a 3 pin sensor. Two pins are for power supply and middle pin for reading the output temperature via one wire protocol. Here is the wiring diagram for DS18b20 with ESP8266 Nodemcu board.
as you can see we had used only nodemcu and ds18b20 interfacing with esp8266 module. We do not need extra hardware for viewing the code.
Required Libraries and Code
There are two main libraries which we use for reading the DS18b20 with esp8266. Same libraries and code is also valid for other Arduino variants. The libraries you need for this code are <DallasTemperature.h> and <OneWire.h>.
The complete code is as follows