Interfacing Multiple DS18B20 Temperature Sensors to Arduino

In this project, we will learn about connecting multiple DS18B20 temperature sensors to Arduino. Simply attach several DS18B20 temperature sensors to an Arduino board, and the Arduino will show the temperature readings in either degree Celsius or Fahrenheit. The Arduino only needs one digital pin to connect many temperature sensors. Using the I2C Protocol, a maximum of 1024 sensors can be connected. However, in this example, I’ve connected three DS18B20 temperature sensors to an Arduino.

A 1-wire digital temperature sensor, the DS18B20 measures temperature. With a straightforward 1-Wire interface, this enclosed package enables accurate temperature measurement in moist situations. It uses a shared bus to communicate. It implies that only one digital Arduino pin is required in order to connect many devices and read their values.

Components Required:

  • Arduino UNO Board
  • Multiple DS18B20 Waterproof Temperature Sensor
  • 16*2 LCD Display
  • 4.7K Resistor
  • Breadboard
  • Connecting Jumper Wires

DS18B20 Waterproof Digital Temperature Sensor:

The DS18B20 sensor is pre-wired and waterproof in this variant. Handy for measuring things from a distance or in damp situations. The Sensor is capable of measuring temperatures in the range of -55 to 125°C (-67 to +257°F). PVC is used to jacket the cable.

Due to its digital nature, there is no signal deterioration even at great distances. These 1-wire digital temperature sensors are fairly accurate, with an average range of 0.5°C. The built-in digital-to-analog converter can provide precision up to 12 bits. Any microcontroller with a single digital pin can use them with excellent success.

Interfacing Multiple DS18B20 Temperature Sensors to Arduino

The Dallas 1-Wire protocol they utilize, which is quite complicated and necessitates a lot of programming to parse out the message, is the sole drawback. When employing the sensor, a 4.7k resistor serves as a pullup from the DATA line to the VCC line.


  • Resolution: 9bits to 12bits (Selectable)
  • Supply Voltage (V): 3 to 5.5
  • Temperature Range(°C): -55 to +125
  • Measuring Accuracy(°C): ±0.5
  • Uses 1-Wire interface- requires only one digital pin for communication
  • Unique 64-bit ID burned into the chip
  • Multiple sensors can share one pin
  • Maximum conversion time and response: 750 ms
  • Multidrop capability simplifies distributed temperature sensing applications
  • Requires no external components
  • Digital signal output
  • 18B20 Temperature Sensor Chip
  • Send data via a pin
  • User-definable nonvolatile (NV) alarm settings
  • Dimension: 19*15*6cm
  • Weight: 9gm

Circuit Diagram & Connections:

Interfacing Multiple DS18B20 Temperature Sensors to Arduino
  • Connect LCD pins 4, 6, 11, 12, 13, and 14 to Arduino pins 11, 12, 5, 4, and 3.
  • Connect the DS18B20’s GND pin to the ground and the VDD pin to 5 volts. As illustrated in the diagram below, connect the data pin of each DS18B20 to Arduino’s digital pin 9 and a 4.7K resistor (connect the resistor’s other end to 5V).

Hardware & Design:

We created a straightforward digital thermometer for monitoring numerous temperatures by connecting all the sensors to one digital pin on the Arduino. Therefore, the image below shows how many DS18B20 temperature sensors were interfaced to an Arduino board and how the temperature was displayed.


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

#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)
Serial.begin(9600); //Start serial port
Serial.println(“Dallas Temperature IC Control Library”);
// Start up the library
// 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(” 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: “);
Serial.print(” “);
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.print(“Sensor Number “);
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);
sen_number++ ;

Working of Multiple DS18B20 Temperature Sensors with Arduino:

The DS18B20 offers 9 to 12-bit (customizable) temperature readings that show the device’s temperature. It communicates with a central microprocessor via a 1-Wire bus, which by definition only needs one data line (and ground). It can also draw power directly from the data line (known as “parasitic power”), doing away with the requirement for an additional power source.

The direct-to-digital temperature sensor is the DS18B20’s primary feature. The temperature sensor’s resolution can be set by the user to 9, 10, 11, or 12 bits, which, respectively, equating to increments of 0.5°C, 0.25°C, 0.125°C, and 0.0625°C. 12-bit resolution is the initial default setting.

Every single DS18B20 has a unique device address that is written in HEX format as follows: 0x28, 0x1D, 0x39, 0x31, 0x2, 0x0, 0x0, and 0xF0. As a result, the application is built around reading the temperature from a specific device address. The Arduino, therefore, counts the number of sensors first. Assume that these three sensors are interconnected. Therefore, it will only show the values of three separate readings. Multiple values will appear in the reading if other sensors are connected. After every two seconds, the temperature read by each sensor is displayed as Sensor Number 1 Temperature, Sensor Number 2 Temperature, and so on, up to the number of sensors that are connected.


Hope this blog helps you to understand the Interfacing Multiple DS18B20 Temperature Sensors with Arduino. We, MATHA ELECTRONICS  will come back with more informative blogs.

Leave a Reply

Your email address will not be published.