Close Menu
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
Facebook X (Twitter) Instagram
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us
Facebook X (Twitter) Instagram Pinterest YouTube LinkedIn
How To Electronics
  • Articles
    • Learn Electronics
    • Product Review
    • Tech Articles
  • Electronics Circuits
    • 555 Timer Projects
    • Op-Amp Circuits
    • Power Electronics
  • Microcontrollers
    • Arduino Projects
    • STM32 Projects
    • AMB82-Mini IoT AI Camera
    • BLE Projects
  • IoT Projects
    • ESP8266 Projects
    • ESP32 Projects
    • ESP32 MicroPython
    • ESP32-CAM Projects
    • LoRa/LoRaWAN Projects
  • Raspberry Pi
    • Raspberry Pi Projects
    • Raspberry Pi Pico Projects
    • Raspberry Pi Pico W Projects
  • Electronics Calculator
How To Electronics
Home » Temperature Meter using DS18B20 OLED Display & Arduino
Arduino Projects

Temperature Meter using DS18B20 OLED Display & Arduino

Mamtaz AlamBy Mamtaz AlamUpdated:August 22, 20222 Comments3 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
DS18B20 OLED Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Temperature Meter using DS18B20 OLED Display & Arduino

In this post, we will learn how to interface DS18B20 Temperature Sensor with OLED Display & Arduino. Simply we will interface DS18B20 Dallas Temperature sensor with Arduino & display the temperature value in 128×64 OLED Display.

The DS18B20 temperature sensor is a 1-wire digital temperature sensor. This comes with a sealed package that lets precisely measure temperatures in wet environments with a simple 1-wire interface. It communicates on a common bus. It means it can connect several devices and read their values using just one digital pin of the Arduino.


Bill of Materials

The components required for making Digital Temperature Meter are as follows. All these components can be purchased easily from Amazon.

S.N.Components NameQuantityPurchase Links
1Arduino Nano Board1Amazon | AliExpress
2DS18B20 Temperature Sensor1Amazon | AliExpress
40.96" I2C OLED Display1Amazon | AliExpress
5Resistor 4.7K1Amazon | AliExpress
6Connecting Wires10Amazon | AliExpress
7Breadboard1Amazon | AliExpress




DS18B20 Waterproof Digital Temperature Sensor:

This is a pre-wired and waterproofed version of the DS18B20 sensor. Handy for when you need to measure something far away, or in wet conditions. The Sensor can measure the temperature between -55 to 125°C (-67°F to +257°F). The cable is jacketed in PVC.

Because it is digital, there is no signal degradation even over long distances. These 1-wire digital temperature sensors are fairly precise, i.e ±0.5°C over much of the range. It can give up to 12 bits of precision from the onboard digital-to-analog converter. They work great with any microcontroller using a single digital pin.

DS18B20 Temperature Sensor

The only downside is they use the Dallas 1-Wire protocol, which is somewhat complex and requires a bunch of code to parse out the communication. We toss in a 4.7k resistor, which is required as a pullup from the DATA to the VCC line when using the sensor.

To learn more about this sensor you can check this post: Digital Thermometer Using Arduino & DS18B20 Temperature Sensor


Circuit Diagram & Connections

Connect VDD pin of DS18B20 to 5V and GND Pin to Ground. Connect its data pin to Analog pin A0 of Arduino. Between data pin & VDD connect 4.7K resistor.

Circuit of Arduino OLED Display & DS18B20

Connect SSD1306 0.96″ OLED Display to I2C Pins of Arduino as shown in the figure above.


Source Code/Program

The source code for interfacing OLED Display & DS18B20 Sensor with Arduino is given below. We need to add the following 2 libraries:

  1. SSD1306 OLED driver
  2. OLED GFX Library


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include <Wire.h> // include Arduino wire library for I2C devices
#include <Adafruit_GFX.h> // include Adafruit graphics library
#include <Adafruit_SSD1306.h> // include Adafruit SSD1306 OLED display driver
 
#define OLED_RESET 4 // define display reset pin
Adafruit_SSD1306 display(OLED_RESET);
 
#define DS18B20_PIN A0 // define DS18B20 data pin connection
 
void setup(void)
{
delay(1000); // wait a second
 
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize the SSD1306 OLED display with I2C address 0x3C
display.clearDisplay(); // clear the display buffer.
 
display.setTextSize(2);
display.setTextColor(WHITE, BLACK);
display.setCursor(34, 5);
display.print("HOW2ELECTRONICS");
 
display.setTextSize(1);
display.setTextColor(WHITE, BLACK);
display.setCursor(29, 33);
display.print("Temperature:");
display.display();
display.setTextSize(2);
}
 
unsigned int ds18b20_temp;
char _buffer[11];
 
void loop()
{
display.setCursor(1, 50);
 
if(ds18b20_read(&ds18b20_temp))
{
if (ds18b20_temp & 0x8000) // if temperature < 0
{
ds18b20_temp = ~ds18b20_temp + 1; // change temperature value to positive form
sprintf(_buffer, "-%02u.%04u C", (ds18b20_temp/16) % 100, (ds18b20_temp & 0x0F) * 625);
}
 
else
{ // otherwise (temperature >= 0)
if (ds18b20_temp/16 > 100) // if temperature >= 100 °C
sprintf(_buffer, "%03u.%04u C", ds18b20_temp/16, (ds18b20_temp & 0x0F) * 625);
else // otherwise ( 0 <= temperature < 100)
sprintf(_buffer, " %02u.%04u C", ds18b20_temp/16, (ds18b20_temp & 0x0F) * 625);
}
 
display.print(_buffer);
display.drawCircle(103, 52, 2, WHITE); // put degree symbol ( ° )
 
}
 
else
display.print(" ERROR ");
 
display.display();
 
delay(1000); // wait a second
 
}
 
bool ds18b20_start()
{
bool ret = 0;
digitalWrite(DS18B20_PIN, LOW); // send reset pulse to the DS18B20 sensor
pinMode(DS18B20_PIN, OUTPUT);
delayMicroseconds(500); // wait 500 us
pinMode(DS18B20_PIN, INPUT);
delayMicroseconds(100); // wait to read the DS18B20 sensor response
if (!digitalRead(DS18B20_PIN))
{
ret = 1; // DS18B20 sensor is present
delayMicroseconds(400); // wait 400 us
}
return(ret);
}
 
void ds18b20_write_bit(bool value)
{
digitalWrite(DS18B20_PIN, LOW);
pinMode(DS18B20_PIN, OUTPUT);
delayMicroseconds(2);
digitalWrite(DS18B20_PIN, value);
delayMicroseconds(80);
pinMode(DS18B20_PIN, INPUT);
delayMicroseconds(2);
}
 
void ds18b20_write_byte(byte value)
{
byte i;
for(i = 0; i < 8; i++)
ds18b20_write_bit(bitRead(value, i));
}
 
bool ds18b20_read_bit(void)
{
bool value;
digitalWrite(DS18B20_PIN, LOW);
pinMode(DS18B20_PIN, OUTPUT);
delayMicroseconds(2);
pinMode(DS18B20_PIN, INPUT);
delayMicroseconds(5);
value = digitalRead(DS18B20_PIN);
delayMicroseconds(100);
return value;
}
 
byte ds18b20_read_byte(void)
{
byte i, value;
for(i = 0; i < 8; i++)
bitWrite(value, i, ds18b20_read_bit());
return value;
}
 
bool ds18b20_read(int *raw_temp_value)
{
if (!ds18b20_start()) // send start pulse
return(0);
ds18b20_write_byte(0xCC); // send skip ROM command
ds18b20_write_byte(0x44); // send start conversion command
while(ds18b20_read_byte() == 0); // wait for conversion complete
if (!ds18b20_start()) // send start pulse
return(0); // return 0 if error
ds18b20_write_byte(0xCC); // send skip ROM command
ds18b20_write_byte(0xBE); // send read command
 
*raw_temp_value = ds18b20_read_byte(); // read temperature LSB byte and store it on raw_temp_value LSB byte
*raw_temp_value |= (unsigned int)(ds18b20_read_byte() << 8); // read temperature MSB byte and store it on raw_temp_value MSB byte
 
return(1);
}




Working of the Project

DS18B20 Temperature Meter

The Arduino code below doesn’t use any library for the DS18B20 sensor. Rather Analog pin is used for measuring temperature.

  1. bool ds18b20_start(): checks whether DS18B20 sensor is correctly connected to the circuit or not & returns 1 if OK and 0 if error.
  2. ds18b20_write_bit(bool value): write a single bit to the DS18B20 sensor, which maybe 1 or 0.
  3. ds18b20_write_byte(byte value): write 1 byte (8 bits) to the DS18B20 sensor
  4. bool ds18b20_read_bit(void): reads 1 bit from the DS18B20 sensor, returns the read value (1 or 0).
  5. byte ds18b20_read_byte(void): reads 1 byte from the DS18B20 sensor, based on the previous value.
  6. 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.
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleLithium-Ion Battery Charger Circuit using MCP73831
Next Article Voice Based Home Automation with NodeMCU & Alexa using fauxmoESP

Related Posts

DC Energy Meter using Arduino

Build a DC Energy Meter using Arduino – 32V/5A

Updated:August 26, 20252K
Interfacing ADXL375 Accelerometer with Arduino

Interfacing ADXL375 Accelerometer with Arduino (±200g)

Updated:June 28, 2025
PZEM-004T Arduino Energy Meter

DIY AC Energy Meter using PZEM-004T & Arduino

Updated:March 6, 20258K
Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Interfacing BMI160 Accelerometer & Gyroscope with Arduino

Updated:February 2, 20259K
Password Based Door Lock Security System Using Arduino & Keypad

Password Based Door Lock Security System Using Arduino & Keypad

Updated:February 2, 20252436K
Earthquake Detector Alarm with with Accelerometer & Arduino

Earthquake Detector Alarm with Accelerometer & Arduino

Updated:February 2, 2025661K
View 2 Comments

2 Comments

  1. Harry on April 22, 2021 10:12 AM

    C:\Users\termy\AppData\Local\Temp\arduino_modified_sketch_471779\sketch_apr21d.ino: In function ‘void loop()’:
    C:\Users\termy\AppData\Local\Temp\arduino_modified_sketch_471779\sketch_apr21d.ino:37:17: warning: invalid conversion from ‘unsigned int‘ to ‘int‘ [-fpermissive]
    if(ds18b20_read(&ds18b20_temp))
    ^~~~~~~~~~~~~
    C:\Users\termy\AppData\Local\Temp\arduino_modified_sketch_471779\sketch_apr21d.ino:122:6: note: initializing argument 1 of ‘bool ds18b20_read(int*)’
    bool ds18b20_read(int *raw_temp_value)
    ^~~~~~~~~~~~
    this is what i get. It just hangs at how2electronics on the led

    Reply
  2. Jonas on May 27, 2023 7:54 AM

    if for someone it is not working, adjust “display.setCursor(1, 10);” lines

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 21, 2026
IoT Based PM & Air Quality Monitoring System using ESP32

IoT Based PM & Air Quality Monitoring System using ESP32

June 14, 2026
DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

DIY ESP32 MLX90640 IR Thermal Camera with Live Web Display

May 10, 2026
IoT Activity Tracker with ESP32 & Accelerometer Gyroscope

IoT Activity Tracker with ESP32 & Accelerometer/Gyroscope

May 2, 2026
A Guide to Sourcing Obsolete ICs for Vintage Projects

Beyond AliExpress: A Guide to Sourcing Obsolete ICs for Vintage Projects

April 21, 2026

ESP32 IoT Vehicle Motion Analyzer with MPU6050 & LIS3MDL

April 27, 2026
Building a Smart Sensor Node with a BLE Microcontroller

Building a Smart Sensor Node with a BLE Microcontroller

February 26, 2026
High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

High-Accuracy Pitch, Roll, Yaw with ESP32 & BNO08x IMU

April 27, 2026
Top Posts & Pages
  • ESP32 Fingerprint Attendance System with Live Web Dashboard
    ESP32 Fingerprint Attendance System with Live Web Dashboard
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • MAX30102 & Arduino: Heart Rate + Blood Oxygen Monitoring
    MAX30102 & Arduino: Heart Rate + Blood Oxygen Monitoring
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
  • IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
    IoT Based ECG Monitoring with AD8232 ECG Sensor & ESP32
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
Categories
  • Arduino Projects (197)
  • Articles (60)
    • Learn Electronics (19)
    • Product Review (15)
    • Tech Articles (28)
  • Electronics Circuits (46)
    • 555 Timer Projects (21)
    • Op-Amp Circuits (7)
    • Power Electronics (13)
  • IoT Projects (205)
    • ESP32 MicroPython (7)
    • ESP32 Projects (82)
    • ESP32-CAM Projects (15)
    • ESP8266 Projects (76)
    • LoRa/LoRaWAN Projects (22)
  • Microcontrollers (38)
    • AMB82-Mini IoT AI Camera (4)
    • BLE Projects (18)
    • STM32 Projects (19)
  • Raspberry Pi (93)
    • Raspberry Pi Pico Projects (57)
    • Raspberry Pi Pico W Projects (12)
    • Raspberry Pi Projects (24)
Follow Us
  • Facebook
  • Twitter
  • Pinterest
  • Instagram
  • YouTube
About Us

“‘How to Electronics’ is a vibrant community for electronics enthusiasts and professionals. We deliver latest insights in areas such as Embedded Systems, Power Electronics, AI, IoT, and Robotics. Our goal is to stimulate innovation and provide practical solutions for students, organizations, and industries. Join us to transform learning into a joyful journey of discovery and innovation.

Copyright © How To Electronics. All rights reserved.
  • About Us
  • Disclaimer
  • Privacy Policy
  • Contact Us
  • Advertise With Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!
Ad Blocker Enabled!
Looks like you're using an ad blocker. Please allow ads on our site. We rely on advertising to help fund our site.