Interfacing Multiple DS18B20 Temperature Sensors to Microcontroller
Interfacing Multiple DS18B20 Temperature Sensors to Microcontroller ATmega328. Circuit diagram and PCB digarm is given below. Compile code and upload to MCU
- Suitable forB.Tech/Diploma Arduino students
- Build time1-2 weeks
- LevelBeginner
- Available atAjvika Labs, Kakinada
About this project
Interfacing Multiple DS18B20 Temperature Sensors to Microcontroller:
In this project we will learn about
Interfacing Multiple DS18B20 Temperature Sensors to Microcontroller ATmega328
. Simply we will
connect Multiple DS18B20 Temperature Sensors to Microcontroller pin
and display the temperature values of all the sensors in degree celsius or Fahrenheit. Only one digital pin of Microcontroller ATmega328 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 Microcontroller ATmega328.
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 Microcontroller.
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.
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:
ATmega328 Microcontroller
Multiple DS18B20 Waterproof Temperature Sensor
16*2 LCD Display
4.7K, 1M & 100 ohm Resistors
22pF, 10uF & 22pF Capacitors
16 MHz Crystal Oscillator
5 Volt Power Supply or Battery
Circuit Diagram & Connections:
Hardware & Design:
By connecting all the sensors to one digital pin of Microcontroller ATmega328 we have simply designed
Digital Thermometer for measuring multiple temperatures
. So the below picture tells how we have Interfaced
Multiple DS18B20 Temperature Sensors to Microcontroller ATmega328
and how the temperature is being displayed.
Source Code/Program:
We have used Arduino Language to write the code and upload it to the microcontroller. Take a fresh ATmega328 and insert it into Arduino UNO Board. First, upload the bootloader. Then simply compile the below code and upload it to the microcontroller. Now you can remove the microcontroller and insert it into PCB.
For interfacing Multiple DS18B20 Temperature Sensors to ATmega328 microcontroller you need two different library
Download 1 Wire Library
Download Dallas Temperature Library
#include <LiquidCrystal.h>
LiquidCrystal
lcd
(
)
;
#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
=
;
// 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
(
)
;
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
(
"Found: "
)
;
Serial
(
sensors
getDeviceCount
(
)
DEC
)
;
Serial
println
(
" Devices."
)
;
// report parasite power requirements
Serial
(
"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
)
)
Serial
println
(
"Not Found Sensor 1"
)
;
if
(
!
sensors
getAddress
(
T2
)
)
Serial
println
(
"Not Found Sensor 2"
)
;
if
(
!
sensors
getAddress
(
T3
)
)
Serial
println
(
"Not Found Sensor 3"
)
;
if
(
!
sensors
getAddress
(
T4
)
)
Serial
println
(
"Not Found Sensor 4"
)
;
if
(
!
sensors
getAddress
(
T5
)
)
Serial
println
(
"Not Found Sensor 5"
)
;
if
(
!
sensors
getAddress
(
T6
)
)
Serial
println
(
"Not Found Sensor 6"
)
;
if
(
!
sensors
getAddress
(
T7
)
)
Serial
println
(
"Not Found Sensor 7"
)
;
if
(
!
sensors
getAddress
(
T8
)
)
Serial
println
(
"Not Found Sensor 8"
)
;
// show the addresses we found on the bus
for
(
int
k
=
;
k
<
sensors
getDeviceCount
(
)
;
k
++
)
{
Serial
(
"Sensor "
)
;
Serial
(
k
+
)
;
Serial
(
" Address: "
)
;
if
(
k
==
)
{
printAddress
(
T1
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T2
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T3
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T4
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T5
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T6
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T7
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
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
=
;
k
<
sensors
getDeviceCount
(
)
;
k
++
)
{
Serial
(
"Sensor "
)
;
Serial
(
k
+
)
;
Serial
(
" Resolution: "
)
;
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T1
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T2
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T3
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T4
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T5
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T6
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T7
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T8
)
DEC
)
;
Serial
println
(
)
;
}
}
}
// function to print a device address
void
printAddress
(
DeviceAddress
deviceAddress
)
{
for
(
uint8
_
t
i
=
;
i
<
;
i
++
)
{
// zero pad the address if necessary
if
(
deviceAddress
[
i
]
<
)
Serial
(
"0"
)
;
Serial
(
deviceAddress
[
i
]
HEX
)
;
}
}
// function to print the temperature for a device
void
printTemperature
(
DeviceAddress
deviceAddress
)
{
float
tempC
=
sensors
getTempC
(
deviceAddress
)
;
Serial
(
"Temp : "
)
;
Serial
(
tempC
)
;
Serial
(
" Celcius degres "
)
;
// Serial.print(" Temp F: ");
//
In this project we will learn about
Interfacing Multiple DS18B20 Temperature Sensors to Microcontroller ATmega328
. Simply we will
connect Multiple DS18B20 Temperature Sensors to Microcontroller pin
and display the temperature values of all the sensors in degree celsius or Fahrenheit. Only one digital pin of Microcontroller ATmega328 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 Microcontroller ATmega328.
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 Microcontroller.
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.
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:
ATmega328 Microcontroller
Multiple DS18B20 Waterproof Temperature Sensor
16*2 LCD Display
4.7K, 1M & 100 ohm Resistors
22pF, 10uF & 22pF Capacitors
16 MHz Crystal Oscillator
5 Volt Power Supply or Battery
Circuit Diagram & Connections:
Hardware & Design:
By connecting all the sensors to one digital pin of Microcontroller ATmega328 we have simply designed
Digital Thermometer for measuring multiple temperatures
. So the below picture tells how we have Interfaced
Multiple DS18B20 Temperature Sensors to Microcontroller ATmega328
and how the temperature is being displayed.
Source Code/Program:
We have used Arduino Language to write the code and upload it to the microcontroller. Take a fresh ATmega328 and insert it into Arduino UNO Board. First, upload the bootloader. Then simply compile the below code and upload it to the microcontroller. Now you can remove the microcontroller and insert it into PCB.
For interfacing Multiple DS18B20 Temperature Sensors to ATmega328 microcontroller you need two different library
Download 1 Wire Library
Download Dallas Temperature Library
#include <LiquidCrystal.h>
LiquidCrystal
lcd
(
)
;
#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
=
;
// 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
(
)
;
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
(
"Found: "
)
;
Serial
(
sensors
getDeviceCount
(
)
DEC
)
;
Serial
println
(
" Devices."
)
;
// report parasite power requirements
Serial
(
"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
)
)
Serial
println
(
"Not Found Sensor 1"
)
;
if
(
!
sensors
getAddress
(
T2
)
)
Serial
println
(
"Not Found Sensor 2"
)
;
if
(
!
sensors
getAddress
(
T3
)
)
Serial
println
(
"Not Found Sensor 3"
)
;
if
(
!
sensors
getAddress
(
T4
)
)
Serial
println
(
"Not Found Sensor 4"
)
;
if
(
!
sensors
getAddress
(
T5
)
)
Serial
println
(
"Not Found Sensor 5"
)
;
if
(
!
sensors
getAddress
(
T6
)
)
Serial
println
(
"Not Found Sensor 6"
)
;
if
(
!
sensors
getAddress
(
T7
)
)
Serial
println
(
"Not Found Sensor 7"
)
;
if
(
!
sensors
getAddress
(
T8
)
)
Serial
println
(
"Not Found Sensor 8"
)
;
// show the addresses we found on the bus
for
(
int
k
=
;
k
<
sensors
getDeviceCount
(
)
;
k
++
)
{
Serial
(
"Sensor "
)
;
Serial
(
k
+
)
;
Serial
(
" Address: "
)
;
if
(
k
==
)
{
printAddress
(
T1
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T2
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T3
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T4
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T5
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T6
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
printAddress
(
T7
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
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
=
;
k
<
sensors
getDeviceCount
(
)
;
k
++
)
{
Serial
(
"Sensor "
)
;
Serial
(
k
+
)
;
Serial
(
" Resolution: "
)
;
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T1
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T2
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T3
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T4
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T5
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T6
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T7
)
DEC
)
;
Serial
println
(
)
;
}
else
if
(
k
==
)
{
Serial
(
sensors
getResolution
(
T8
)
DEC
)
;
Serial
println
(
)
;
}
}
}
// function to print a device address
void
printAddress
(
DeviceAddress
deviceAddress
)
{
for
(
uint8
_
t
i
=
;
i
<
;
i
++
)
{
// zero pad the address if necessary
if
(
deviceAddress
[
i
]
<
)
Serial
(
"0"
)
;
Serial
(
deviceAddress
[
i
]
HEX
)
;
}
}
// function to print the temperature for a device
void
printTemperature
(
DeviceAddress
deviceAddress
)
{
float
tempC
=
sensors
getTempC
(
deviceAddress
)
;
Serial
(
"Temp : "
)
;
Serial
(
tempC
)
;
Serial
(
" Celcius degres "
)
;
// Serial.print(" Temp F: ");
//
Technologies used
Hardware components
- Arduino
- DS18B20
Software & tools
- Arduino IDE
What you get
- Working project / hardware kit, tested before delivery
- Complete source code with explanation
- Project demo and guidance for your viva
- Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed.
Payment is in two parts:
• 50% advance to start the project
• Remaining 50% before delivery
Note:
• Documentation and PPT are not included by default
• If you need documentation/PPT, it can be arranged for extra time and cost
We'll confirm the exact timeline and cost with you after reviewing your requirements.