ESP8266 & Temperature Sensor DS18B20 and Onewire library

There are a variety of sensors to measure temperature in devices such as Arduino and ESP8266, in this case we have chosen the Sensor DS18B20 this particular sensor is not connected through a GPIO Analogue, technically it is a digital sensor that uses the protocol Onewire or 1- Wire designed by dallas semiconductor, There are many tutorials on the net about this protocol.

Reference: Datasheet DS18B20 Maxim

In this case we have adapted our temperature sensor for fast connections, the sensor, the datasheet of DS18B20 Maxim recommends using a resistance of 4.7k, but we will use a resistance of 3.3k, but for ease we will use 3 resistors of 10k in parallel, This modification will allow your ESP8266 modules to work with this sensor without difficulty, with the help of heat shrinkable resistors and wiring.

Required Materials


We will use a module ESP8266 12E NodeMCU and the Onewire library, in this case, step by step the methods of sending and requesting sensor data.

Connections, GND, 5V, GPIO(2) PIN D4



Arduino IDE Code

In this case the code indicates step by step the process of requesting data to the probe, this example can easily be modified for other implementations with onewire, I decided to use this example to understand step by step how the Onewire protocol works.

  • Requires Libreria Onewire.h


Although it is considered that we simply test the sensor, this tutorial invites to adapt the Sensor and the resistance to facilitate connection in tests, this sensor will be used in a lot of future tests.

A great advantage of the use of these sensors, since being digital and using a protocol, allows to create a network of sensors to a single input (GPIO).






Leave a Reply