NodeMCU Interfacing with SSD1306 and DS18B20 temperature sensor

This small post shows how to build a simple temperature measurement station using ESP8266 NodeMCU development board and DS18B20 digital temperature sensor where the measured temperature is displayed on SSD1306 OLED screen (128×64 Pixel) and sent serially to Arduino IDE serial monitor.

The DS18B20 sensor is a 3-pin electronic component (like a simple transistor) from Maxim (formerly Dallas) which uses 1-wire protocol to communicate with master device (microprocessor, microcontroller ….). Each DS18B20 device has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus and controlled with one master device.
The DS18B20 sensor provides 9-bit to 12-bit Celsius temperature measurement resolution (programmable resolution).
The DS18B20 sensor is available in 8-Pin SO (150 mils), 8-Pin μSOP, and 3-Pin TO-92 Packages. DS18B20 pin configurations is shown below:

ds18b20 pin configurations

The SSD1306 OLED used in this project is configured to work in I2C mode, some SSD1306 OLED boards may require a small hardware modifications (to select between SPI mode or I2C mode) such as soldering, placing jumpers ….

ESP-12E NodeMCU with SSD1306 OLED and DS18B20 sensor

Related Projects:
ESP8266 NodeMCU interfacing with SSD1306 OLED
ESP8266 NodeMCU interfacing with DHT11 sensor and SSD1306
Interfacing NodeMCU with DHT22 sensor and SSD1306 OLED

Hardware Required:

  • ESP8266 NodeMCU development board
  • SSD1306 OLED display with 128×64 Pixel resolution
  • DS18B20 temperature sensor — datasheet
  • 4.7k ohm resistor
  • micro USB cable (for programming and powering the circuit)
  • Breadboard
  • Jumper wires

NodeMCU Interfacing with SSD1306 and DS18B20 circuit:
The following image shows project circuit schematic diagram.

ESP8266 NodeMCU DS18B20 SSD1306 OLED circuit

and the following one shows fritzing circuit:

ESP8266 NodeMCU SSD1306 OLED DS18B20 fritzing circuit

The SDA and SCL lines of the I2C bus come from GPIO4 (D2) and GPIO0 (D3) of the NodeMCU board (respectively), they are connected to SDA and SCL (SCK) pins of the SSD1306 display module.
Reset pin (RES) of the display module is connected to GPIO5 (D1) of the NodeMCU development board.

The DS18B20 sensor has 3 pins: VCC (+5V), data and GND. The data pin is connected to pin D5 (GPIO14) of the NodeMCU module. A pull-up resistor of 4.7k ohm is required for the data pin.

The SSD1306 display module and the DHT22 (AM2302) sensor are supplied with 3.3V which comes from the NodeMCU board.

NodeMCU Interfacing with SSD1306 and DS18B20 code:
Example Arduino code is below, it doesn’t use any library for the DS18B20 sensor, but it requires Adafruit SSD1306 OLED display driver and graphics library.

Functions used in the code:
bool ds18b20_start(): used to know if the DS18B20 sensor is correctly connected to the circuit, returns 1 if OK and 0 if error.
ds18b20_write_bit(bool value): writes (sends) 1 bit to the DS18B20 sensor, the bit is ‘value’ which may be 1 or 0.
ds18b20_write_byte(byte value): writes 1 byte (8 bits) to the DS18B20 sensor, this function is based on the previous function. This function writes LSB first.
bool ds18b20_read_bit(void): reads 1 bit from the DS18B20 sensor, returns the read value (1 or 0).
byte ds18b20_read_byte(void): reads 1 byte from the DS18B20 sensor, this function is based on the previous function. This function reads LSB first.
bool ds18b20_read(int *raw_temp_value): reads the temperature raw data which is 16-bit long (two 8-bit registers), the data is stored in the variable raw_temp_value, returns 1 if OK and 0 if error.

The value of the temperature in degree Celsius is equal to the raw value divided by 16 (in case of 12-bit resolution). The default resolution of the DS18B20 is 12 bits.

Arduino IDE serial monitor output for temperature and relative humidity is shown below:

NodeMCU with DS18B20 temperature sensor output


Discover more from Simple Circuit

Subscribe to get the latest posts sent to your email.

Leave a Comment

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

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

Scroll to Top