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 » Interfacing Multiple DS18B20 Temperature Sensors to Arduino
Arduino Projects

Interfacing Multiple DS18B20 Temperature Sensors to Arduino

Mamtaz AlamBy Mamtaz AlamUpdated:February 2, 202522 Comments4 Mins Read
Share Facebook Twitter LinkedIn Telegram Reddit WhatsApp
Interfacing Multiple DS18B20 Temperature Sensors to Arduino
Share
Facebook Twitter LinkedIn Pinterest Email Reddit Telegram WhatsApp

Interfacing Multiple DS18B20 Temperature Sensors to Arduino:

In this project we will learn about Interfacing Multiple DS18B20 Temperature Sensors to Arduino. Simply we will connect Multiple DS18B20 Temperature Sensors to Arduino and display the temperature values of all the sensors in degree celsius or Fahrenheit. Only one digital pin of Arduino is required to connect several temperature sensor. We can connect maximum of 1024 sensors using I2C Protocol. But here i have shown connecting 3 DS18B20 Temperature Sensors to Arduino.

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


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.

Interfacing Multiple DS18B20 Temperature Sensors to Arduino

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.



Components Required:

1. Arduino UNO Board
2. Multiple DS18B20 Waterproof Temperature Sensor
3. 16*2 LCD Display
4. 4.7K Resistor
5. Breadboard
6. Connecting Jumper Wires


Circuit Diagram & Connections:

Interfacing Multiple DS18B20 Temperature Sensors to Arduino

Connect pin 11,12,5,4,3,2 of Arduino to pin 4,6,11,12,13,14 of LCD.

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


Hardware & Design:

By connecting all the sensors to one digital pin of Arduino we have simply designed Digital Thermometer for measuring multiple temperature. So the below picture tells how we have Interfaced Multiple DS18B20 Temperature Sensors to Arduino and how the temperature is being displayed.

  • 1
  • 2
  • 3

  • 1
  • 2
  • 3




Source Code/Program:

For interfacing Multiple DS18B20 Temperature Sensors to Arduino you need two different library
1. Download 1 Wire Library
2. Download Dallas Temperature 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
139
140
141
142
143
144
145
146
147
148
#include <LiquidCrystal.h>
LiquidCrystal lcd(11, 12, 5, 4, 3, 2);
#include <OneWire.h>
#include <DallasTemperature.h>
 
#define ONE_WIRE_BUS 9 // Data wire is plugged into port 9 on the Arduino
#define precision 12 // OneWire precision Dallas Sensor
int sen_number = 0; // Counter of Dallas sensors
 
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature.
DeviceAddress T1, T2, T3, T4, T5, T6, T7, T8; // arrays to hold device addresses
void setup(void)
{
lcd.begin(16,2);
Serial.begin(9600); //Start serial port
Serial.println("Dallas Temperature IC Control Library");
// Start up the library
sensors.begin();
// locate devices on the bus
Serial.print("Found: ");
Serial.print(sensors.getDeviceCount(), DEC);
Serial.println(" Devices.");
// report parasite power requirements
Serial.print("Parasite power is: ");
if (sensors.isParasitePowerMode()) Serial.println("ON");
else Serial.println("OFF");
// Search for devices on the bus and assign based on an index.
 
if (!sensors.getAddress(T1, 0)) Serial.println("Not Found Sensor 1");
if (!sensors.getAddress(T2, 1)) Serial.println("Not Found Sensor 2");
if (!sensors.getAddress(T3, 2)) Serial.println("Not Found Sensor 3");
if (!sensors.getAddress(T4, 3)) Serial.println("Not Found Sensor 4");
if (!sensors.getAddress(T5, 4)) Serial.println("Not Found Sensor 5");
if (!sensors.getAddress(T6, 5)) Serial.println("Not Found Sensor 6");
if (!sensors.getAddress(T7, 6)) Serial.println("Not Found Sensor 7");
if (!sensors.getAddress(T8, 7)) Serial.println("Not Found Sensor 8");
 
// show the addresses we found on the bus
for (int k =0; k < sensors.getDeviceCount(); k++) {
Serial.print("Sensor "); Serial.print(k+1);
Serial.print(" Address: ");
if (k == 0) { printAddress(T1); Serial.println();
} else if (k == 1) { printAddress(T2); Serial.println();
} else if (k == 2) { printAddress(T3); Serial.println();
} else if (k == 3) { printAddress(T4); Serial.println();
} else if (k == 4) { printAddress(T5); Serial.println();
} else if (k == 5) { printAddress(T6); Serial.println();
} else if (k == 6) { printAddress(T7); Serial.println();
} else if (k == 7) { printAddress(T8); Serial.println();
}
}
// set the resolution to 12 bit per device
sensors.setResolution(T1, precision);
sensors.setResolution(T2, precision);
sensors.setResolution(T3, precision);
sensors.setResolution(T4, precision);
sensors.setResolution(T5, precision);
sensors.setResolution(T6, precision);
sensors.setResolution(T7, precision);
sensors.setResolution(T8, precision);
for (int k =0; k < sensors.getDeviceCount(); k++) {
Serial.print("Sensor "); Serial.print(k+1);
Serial.print(" Resolution: ");
if (k == 0) { Serial.print(sensors.getResolution(T1), DEC); Serial.println();
} else if (k == 1) { Serial.print(sensors.getResolution(T2), DEC); Serial.println();
} else if (k == 2) { Serial.print(sensors.getResolution(T3), DEC); Serial.println();
} else if (k == 3) { Serial.print(sensors.getResolution(T4), DEC); Serial.println();
} else if (k == 4) { Serial.print(sensors.getResolution(T5), DEC); Serial.println();
} else if (k == 5) { Serial.print(sensors.getResolution(T6), DEC); Serial.println();
} else if (k == 6) { Serial.print(sensors.getResolution(T7), DEC); Serial.println();
} else if (k == 7) { Serial.print(sensors.getResolution(T8), DEC); Serial.println();
}
}
}
// function to print a device address
void printAddress(DeviceAddress deviceAddress)
{
for (uint8_t i = 0; i < 8; i++)
{
// zero pad the address if necessary
if (deviceAddress[i] < 16) Serial.print("0");
Serial.print(deviceAddress[i], HEX);
}
}
// function to print the temperature for a device
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
Serial.print("Temp : ");
Serial.print(tempC);
Serial.print(" Celcius degres ");
// Serial.print(" Temp F: ");
// Serial.print(DallasTemperature::toFahrenheit(tempC));
}
// function to print a device's resolution
void printResolution(DeviceAddress deviceAddress)
{
}
 
void printData(DeviceAddress deviceAddress)
{
Serial.print("Device Address: ");
printAddress(deviceAddress);
Serial.print(" ");
printTemperature(deviceAddress);
Serial.println();
}
 
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature request to all devices on the bus
Serial.print("Reading DATA..."); sensors.requestTemperatures(); Serial.println("DONE");
// print the device information
for (int k =0; k < sensors.getDeviceCount(); k++) {
Serial.print("Sensor "); Serial.print(k+1); Serial.print(" ");
if (k == 0) { printData(T1);
} else if (k == 1) { printData(T2);
} else if (k == 2) { printData(T3);
} else if (k == 3) { printData(T4);
} else if (k == 4) { printData(T5);
} else if (k == 5) { printData(T6);
} else if (k == 6) { printData(T7);
} else if (k == 7) { printData(T8);
}
}
if (sen_number == sensors.getDeviceCount()) {
sen_number = 0; // reset counter
// lcd.clear(); // clear screen on LCD
}
lcd.setCursor(0,0);
lcd.print("Sensor Number ");
lcd.print(sen_number+1);
lcd.setCursor(0,1);
lcd.print(" Temp: ");
if (sen_number == 0) { lcd.print(sensors.getTempC(T1)); lcd.write((char)223); lcd.print("C ");
} else if (sen_number == 1) { lcd.print(sensors.getTempC(T2)); lcd.write((char)223); lcd.print("C ");
} else if (sen_number == 2) { lcd.print(sensors.getTempC(T3)); lcd.write((char)223); lcd.print("C ");
} else if (sen_number == 3) { lcd.print(sensors.getTempC(T4)); lcd.write((char)223); lcd.print("C ");
} else if (sen_number == 4) { lcd.print(sensors.getTempC(T5)); lcd.write((char)223); lcd.print("C ");
} else if (sen_number == 5) { lcd.print(sensors.getTempC(T6)); lcd.write((char)223); lcd.print("C ");
} else if (sen_number == 6) { lcd.print(sensors.getTempC(T7)); lcd.write((char)223); lcd.print("C ");
} else if (sen_number == 7) { lcd.print(sensors.getTempC(T8)); lcd.write((char)223); lcd.print("C ");
}
Serial.print("Sensor Number="); Serial.println(sen_number);
delay(2000);
sen_number++ ;
}




Working of Multiple DS18B20 Temperature Sensors with Arduino:

The DS18B20 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.

Each and every DS18B20 has particular device address in HEX format like { 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, 0xF0 }. So the program is designed on the basis of reading temperature from particular device address. So first the Arduino scans the number of sensors. Let us assume 3 sensors are connected here. So it will just displays values of 3 different reading. If more sensors are connected, the reading will switch to multiple values. The value of temperature read by each sensors is displayed after interval of 2 seconds as Sensor Number 1 Temperature, Sensor Number 2 Temperature and upto the value of number of sensor connected.

To learn more about the code you can go through the video below. Or simply read the code as I have commented each and every thing about each line in code.


Video Tutorial & Explanation:

Interfacing Multiple DS18B20 Temperature Sensor to Arduino/Microcontroller
Watch this video on YouTube.

Share. Facebook Twitter Pinterest LinkedIn Tumblr Email Reddit Telegram WhatsApp
Previous ArticleFingerprint Biometric Attendance System using Arduino
Next Article Interfacing Multiple DS18B20 Temperature Sensors to Microcontroller

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

22 Comments

  1. Paul kenneth on January 22, 2019 5:02 AM

    Wonderful project…. I have seen several months ago (don’t remember where..) a similar project but displaying the indoor and few seconds after the outdoor temperatures on a seven segment display since it is designated to be installed in a living room.
    Is it possible to modify the current project as described above ?

    Reply
    • Alex Newton on January 22, 2019 9:44 AM

      Check this https://www.how2electronics.com/ds18b20-based-thermometer-using-arduino/

      Reply
      • Paul kenneth on January 22, 2019 7:35 PM

        it uses one sensor not two (for indoor/outdoor temperature).

  2. ama on February 13, 2019 8:29 PM

    i have made it . it is excellent .

    Reply
  3. ama on February 13, 2019 8:34 PM

    i made it .it is practical and perfect .

    Reply
  4. Michael Lynch on April 20, 2019 7:33 PM

    I have built this circuit as a test. It works great. The one thing that I cannot figure out is how to make the LCD display Celcius and Fahrenheit at the same time. I was able to figure out the code to display both temps on the serial monitor and My serial monitor shows both temps. I am new to coding and cannot make the code work to show the same information on the LCD. Is there a “quick” explanation of the code to make the LCD Display both temps? Thank You in advance.

    Reply
    • Alex Newton on April 20, 2019 7:39 PM

      Use this formula to convert F to C
      C= (F-32)/1.8

      Use lcd.print command to display the required temperature. Learn about lcd arduino interfacing code more from google.

      If u want to display both temperature at the same time.
      I recomend u to use 20×4 LCD.

      Reply
      • Michael Lynch on April 21, 2019 2:00 AM

        I have the 20 x 4 display, that is not an issue. I know the math for the conversion. It is the code to make it happen on this particular sketch. This is different code than the other sketches I have done that display both C and F. I will do some more research. Thanks for the reply!

        MWL

  5. Mostafa on June 9, 2019 1:05 AM

    Hello,
    This code works well for 3 sensors when i try to use more than 3 sensors Zero devices is found

    Reply
    • Alex Newton on June 9, 2019 4:27 AM

      This code works for 8 sensors. I have already done the testing

      Reply
    • Serkan on November 17, 2019 2:26 AM

      Hi Mostafa. I have same problem. Did you solve this problem?

      Reply
  6. dmkmedia2 on July 12, 2019 2:20 PM

    it works on a arduino uno but for some reason arduino nano not receiving values

    Reply
  7. al on December 22, 2019 8:49 PM

    hi alex, i’m having a problem .. what if i use dht22 sensor?

    Reply
    • Alex on December 22, 2019 8:50 PM

      DHT22 can be used and interfacing DHT22 with Arduino is more easier.

      Reply
      • al on December 22, 2019 9:05 PM

        is it possible to use the program with multiple DHT22?

  8. Brad Hollan on November 27, 2020 1:56 AM

    Can I download the source code somewhere. I can’t seem to copy and paste. Thanks

    Reply
  9. Mauro on February 3, 2021 5:18 AM

    Hi, I have the display 20×4 but i don´t now how to modify the code to see the 2 sensors. Help me pleaseeeeeeee
    Thanks

    Reply
  10. Mauro on February 3, 2021 10:49 PM

    Hi, I have the display 20×4 but i don´t now how to modify the code to see the 2 sensors. Help me pleaseeeeeeee
    Thanks

    Reply
  11. Anuj Mittal on August 25, 2021 12:25 AM

    Hi I need this project with all hardware and with three sensor only difference is each sensor should have a specific name like Hot Water Temperature, Cold Water Temperature, Room Temperature.

    Power supply we have is of 12v where we want to place it .

    I dont have time to built this so any one who have made this project can contact me at [email protected]

    Reply
  12. carlitosreinoso on August 31, 2021 7:59 PM

    Dear all,
    How you fix the initial value in all sensors to measure variation of temperatures?, looks like every ds18b20 has different initial temperatures, are they calibrated wrong or in different regions.

    Reply
  13. Christophe on June 15, 2022 9:25 PM

    Bonjour, je suis débutant et j’aimerais attribuer un relais à chaque sonde pour déclencher un ventilateur , pouvez vous m’aider svp
    merci

    Reply
  14. Dino_T on November 9, 2022 3:45 PM

    Great!!
    Can we add RTD/PT100 instead of mentioned Sensor? if yes what all changes in codes to be done.
    Thanks.

    Reply

CommentsCancel reply

Latest Posts
ESP32 Fingerprint Attendance System with Live Web Dashboard

ESP32 Fingerprint Attendance System with Live Web Dashboard

June 16, 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
  • Buck Converter: Basics, Working, Design & Application
    Buck Converter: Basics, Working, Design & Application
  • IoT Based PM & Air Quality Monitoring System using ESP32
    IoT Based PM & Air Quality Monitoring System using ESP32
  • 12V DC to 220V AC Inverter Circuit & PCB
    12V DC to 220V AC Inverter Circuit & PCB
  • ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
    ESP32 CAN Bus Tutorial | Interfacing MCP2515 CAN Module with ESP32
  • Designing of MPPT Solar Charge Controller using Arduino
    Designing of MPPT Solar Charge Controller using Arduino
  • IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
    IoT AC Energy Meter with PZEM-004T & ESP32 WebServer
  • How to use Modbus RTU with ESP32 to read Sensor Data
    How to use Modbus RTU with ESP32 to read Sensor Data
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.