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 » DS18B20 Thermometer using Arduino & 4 Digits 7 Segment Display
Arduino Projects

DS18B20 Thermometer using Arduino & 4 Digits 7 Segment Display

Mamtaz AlamBy Mamtaz AlamUpdated:February 2, 20257 Comments4 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
DS18B20 Based Thermometer using Arduino & 4 Digits 7 Segment Display
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

DS18B20 Based Thermometer using Arduino & 4 Digits 7 Segment Display:

In this project, we will learn how to design a DS18B20 Based Thermometer using Arduino & 4 Digits 7 Segment Display. Simply we will interface Arduino with DS18B20 Digital Waterproof Temperature Sensor and display the temperature values in degree celsius on Common Cathode Display.

The DS18B20 temperature sensor is a 1-wire digital temperature sensor. This comes with a sealed package 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.

Check some of the posts related to DS18B20 here:
1. Temperature Meter using DS18B20 OLED Display & Arduino
2. Digital Thermometer Using Arduino & DS18B20 Temperature Sensor


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 any 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.

Digital Thermometer Using Arduino & 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.


LM35 vs DS18B20:

A DS18B20 is factory calibrated to output the right temperature. An LM35 is factory calibrated for voltage (not temperature), and the Arduino has to convert this to temperature.

LM35 is an analog temperature sensor, so any distortion in input can rapidly affect the reading. But DS18B20 is a digital temperature sensor, so input doesn’t affect the output reading.

If the long wire is used for measuring the temperature at a certain distance, wire length can deviate the value in analog LM35 Sensor. But DS18B20 is a digital sensor, there is no effect in any output value.


LM35 can measure the temperature between −55°C to 150°C but DS18B20 can measure between −50°C to 125°C.

1 digital output pin of Arduino can be used to connect multiple DS18B20 but it doesn’t happen with LM35.


Components Required for Digital Thermometer:

  1. Arduino UNO Board
  2. DS18B20 Waterproof Temperature Sensor
  3. Common Anode 7 Segment Display – 4
  4. 7HC595 IC (8 bit Shift Resistor)
  5. 4.7K Resistor
  6. 330 ohm Resistor – 8
  7. Breadboard
  8. Connecting Jumper Wires

Circuit Diagram & Connections:

Connect the VDD pin of DS18B20 to 5V and GND Pin to Ground. Connect its data pin to digital pin 2 of Arduino and also to 4.7K Resistor (Connect another end of 4.7K Resistor to 5V) as shown in the figure below.


Working of the Project:

The DS18B20 Digital Thermometer provides 9 to 12-bit (configurable) temperature readings which indicate the temperature of the device. It communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor. In addition, it can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.

The core functionality of the DS18B20 is its direct-to-digital temperature sensor. The resolution of the temperature sensor is user-configurable to 9, 10, 11, or 12 bits, corresponding to increments of 0.5°C, 0.25°C, 0.125°C, and 0.0625°C, respectively. The default resolution at power-up is 12-bit. We have also used 74HC595 IC here. To learn more about 74HC595 IC, go through 74HC595 Arduino tutorial.




Source Code/Program for Displaying Temperature in °Celsius:

DS18B20 Based Thermometer using Arduino & 4 Digits 7 Segment Display

To design DS18B20 Based Thermometer using Arduino & 4 Digits 7 Segment Display& to display temperature in degree Celsius you need two different library
1. Download 1 Wire Library
2. Download Dallas Temperature Library

Add these to the library file to Arduino IDE and then simply compile and upload the code.

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
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;
const int ledPin = 13;// LED connected to digital pin 13
const int latchPin = 8;// Pin connected to ST_CP of 74HC595
const int clockPin = 9;// Pin connected to SH_CP of 74HC595
const int dataPin = 10;// Pin connected to DS of 74HC595
const int digitPins[4] = {3,4,5,6}; //pins to control the 4 common anode pins of display
const byte digit[12] = //seven segment digit bits + blank + minus
{
B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111, //9
B00000000, //Blank
B01000000 //-
};
int digitBuffer[4] = {
1};
int digitScan = 0;
int soft_scaler = 0;
float tempC, tempF;
int tmp;
boolean sign = false;
void setup() {
TCCR2A = 0;
TCCR2B = (1<<CS21);
TIMSK2 = (1<<TOIE2);
TCNT2 = 0;
pinMode(ledPin, OUTPUT);
for(int i=0;i<4;i++)
{
pinMode(digitPins[i],OUTPUT);
}
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
sensors.begin();
sensors.getAddress(insideThermometer, 0);
}
ISR(TIMER2_OVF_vect) {
soft_scaler++;
if(soft_scaler==15)
{
refreshDisplay();
soft_scaler = 0;
}
};
void refreshDisplay()
{
for(byte k=0;k<4;k++)
{
digitalWrite(digitPins[k], LOW);
}
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, B11111111);
digitalWrite(latchPin, HIGH);
delayMicroseconds(50);
digitalWrite(digitPins[digitScan], HIGH);
digitalWrite(latchPin, LOW);
if(digitScan==1)
{
shiftOut(dataPin, clockPin, MSBFIRST, ~(digit[digitBuffer[digitScan]] | B10000000));
}
else
{
shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);
}
digitalWrite(latchPin, HIGH);
digitScan++;
if(digitScan>3) digitScan=0;
}
void loop()
{
digitalWrite(ledPin, HIGH);
sensors.requestTemperatures();
tempC = sensors.getTempC(insideThermometer);
tmp = int(tempC*10);
if (tempC < 0){
sign = true;
tmp = abs(tmp);
}
else{
sign = false;
}
if (int(tmp)/1000 == 0){
digitBuffer[3] = 10;
if (sign){
digitBuffer[3] = 11;
}
}
else{
digitBuffer[3] = int(tmp)/1000;
}
if (int(tmp)/1000 == 0 && (int(tmp)%1000)/100 == 0) {
digitBuffer[2] = 10;
if (sign){
digitBuffer[2] = 11;
digitBuffer[3] = 10;
}
}
else{
digitBuffer[2] = (int(tmp)%1000)/100;
}
digitBuffer[1] = (int(tmp)%100)/10;
digitBuffer[0] = (int(tmp)%100)%10;
digitalWrite(ledPin, LOW);
delay(500);
}


Source Code/Program for Displaying Temperature in °Fahrenheit:

DS18B20 Based Thermometer using Arduino & 4 Digits 7 Segment Display

To design DS18B20 Based Thermometer using Arduino & 4 Digits 7 Segment Display& to display temperature in degree Fahrenheit you need two different library
1. Download 1 Wire Library
2. Download Dallas Temperature Library

Add these to the library file to Arduino IDE and then simply compile and upload the code.

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
#include <OneWire.h>
#include <DallasTemperature.h>
 
#define ONE_WIRE_BUS 2
 
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
DeviceAddress insideThermometer;
 
const int ledPin = 13;// LED connected to digital pin 13
const int latchPin = 8;//Pin connected to ST_CP of 74HC595
const int clockPin = 9;//Pin connected to SH_CP of 74HC595
const int dataPin = 10;//Pin connected to DS of 74HC595
 
const int digitPins[4] = {
3,4,5,6}; //pins to control the 4 common anode pins of the display
 
const byte digit[10] = //seven segment digit bits
{
B00111111, //0
B00000110, //1
B01011011, //2
B01001111, //3
B01100110, //4
B01101101, //5
B01111101, //6
B00000111, //7
B01111111, //8
B01101111 //9
};
 
int digitBuffer[4] = {
0};
int digitScan = 0;
int soft_scaler = 0;
float tempC, tempF;
int tmp;
 
void setup() {
TCCR2A = 0;
TCCR2B = (1<<CS21);
TIMSK2 = (1<<TOIE2);
TCNT2 = 0;
 
pinMode(ledPin, OUTPUT);
for(int i=0;i<4;i++)
{
pinMode(digitPins[i],OUTPUT);
}
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
 
sensors.begin();
sensors.getAddress(insideThermometer, 0);
}
 
ISR(TIMER2_OVF_vect) {
soft_scaler++;
if(soft_scaler==15)
{
refreshDisplay();
soft_scaler = 0;
}
};
 
void refreshDisplay()
{
for(byte k=0;k<4;k++)
{
digitalWrite(digitPins[k], LOW);
}
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, B11111111);
digitalWrite(latchPin, HIGH);
delayMicroseconds(400);
digitalWrite(digitPins[digitScan], HIGH);
 
digitalWrite(latchPin, LOW);
if(digitScan==2)
{
shiftOut(dataPin, clockPin, MSBFIRST, ~(digit[digitBuffer[digitScan]] | B10000000));
}
else
{
shiftOut(dataPin, clockPin, MSBFIRST, ~digit[digitBuffer[digitScan]]);
}
digitalWrite(latchPin, HIGH);
digitScan++;
if(digitScan>3) digitScan=0;
}
 
void loop()
{
digitalWrite(ledPin, HIGH);
sensors.requestTemperatures();
tempC = sensors.getTempC(insideThermometer);
tempF = DallasTemperature::toFahrenheit(tempC);
tmp = int(tempF*100);
digitBuffer[3] = tmp/1000;
digitBuffer[2] = (tmp%1000)/100;
digitBuffer[1] = (tmp%100)/10;
digitBuffer[0] = (tmp%100)%10;
 
digitalWrite(ledPin, LOW);
delay(50);
}

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleSmart & Manual Home Automation with Alexa & ESP8266
Next Article Digital Tachometer using IR Sensor with Arduino for measuring RPM

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 7 Comments

7 Comments

  1. Eddy Ari on January 19, 2019 5:29 AM

    Thanks for the detailed explanation of the project.
    Could you please help me on how to modify the sketch in order to use 2 sensors (DS18b20) at the same time (mounted in parallel).

    Thanks.

    Reply
    • Alex Newton on January 19, 2019 11:36 AM

      I have already explained this here. You can check https://www.how2electronics.com/interfacing-multiple-ds18b20-temperature-sensors/

      Reply
      • Eddy Ari on January 19, 2019 1:58 PM

        Thanks for answering. Have already checked . But my wish is to combine the 2 projects , ie : interfacing multiple ds18b20 sensors and using Seven Segment display like in this project.
        Thanks again.

  2. Santiago Pascual on November 27, 2020 6:59 PM

    Hola Alex quiero montar tu circuito termómetro pero sustituir los 4 displays por 4 displays de tira de led , por internet encontré un circuito que utiliza el 74HC595 y el ULN2003 para cada segmentos A-B-C-D-E-F-G de la tira de led , como puedo adaptar el ULN2003 a tu circuito Arduino necesitaría 3 ULN2003 ahí que modificar el programa que tu as montando , me puedes ayudar .

    Reply
  3. Santiago Pascual on November 29, 2020 12:56 PM

    Hola monte tu circuito pero no me funciona bien me marcan los display 8 fijo , el código del programa esta bien ,como lo puedo solucionar revise el circuito y esta todo bien montado , pienso que es algo del programa me puedes ayudar te dejo mi correo [email protected]

    Reply
  4. tesladroid2 on January 27, 2021 12:54 AM

    did you achieve? I’m also working on it, I want to know if it can be adapted

    Reply
  5. mahesh on February 2, 2021 4:31 PM

    Hello Mr. Alex , My self Mahesh from Bangalore im looking for Ds18b20 Indicator Can you please help me in this.

    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.