Altium
Arduino Projects

Interfacing Multiple DS18B20 Temperature Sensors to Arduino

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 degrees Celsius or Fahrenheit. Only one digital pin of Arduino is required to connect several temperature sensors. We can connect a maximum of 1024 sensors using the I2C Protocol. But here I have shown connecting 3 DS18B20 Temperature Sensors to Arduino. I have also a very detailed tutorial on how to connect multiple MAX6675 K-type thermocouples with the Arduino.

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.

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.

DS18B20
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:

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

Amazon Links:

12v Adaptor:

Arduino Uno

Arduino Nano

Mega 2560:

DS18B20 one-wire digital temperature sensor:

Potentiometer:

16X2 LCD

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Multiple DS18b20 sensors Interfacing with Arduino:

Interfacing Multiple DS18B20 Arduino, in this image you can see, multiple ds18b20 temperature sensors are interfaced with arduino, a 16x2 lcd is also connected with the arduino.

Multiple DS18b20 Arduino Source Code/Program:

//https://www.electroniclinic.com/
// Download Libraries
// https://www.electroniclinic.com/arduino-libraries-download-and-projects-they-are-used-in-project-codes/
#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++ ;
}

Related Project:

Nodemcu ESP8266 DS18b20 Waterproof Temperature Sensor Monitoring

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

Leave a Reply

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

Back to top button