Introduction
To check the temperature at multiple points of any device, more than one DS18B20 sensor can be used. Consequently, many DS18B20 digital temperature sensors can easily be interfaced collectively with the microcontroller through one-wire communication. Therefore, In this tutorial, we will demonstrate how to interface ” DS18B20 Digital Temperature Sensors with Arduino UNO”. In short, this configuration can make outstanding benefits to temperature measurement devices. Certainly, this method helps to measure the temperature over large areas. But, before starting the interface, one must know the basics about the wiring of multiple DS18B29 sensors.
Wiring of Multiple DS18B20 Sensor
To interface the multiple sensors, connect the sensors in a way that they are wired parallel to each other. Now, Common all the Vdd pins of the sensors. Similarly, common all the ground pins of the sensors. After that, connect that Common Vdd to the 5V pin of an Arduino. In the same vein, connect the common ground wire to the ground pin of an Arduino. Moreover, connect the common signal pins and connect them with any digital pin of an Arduino.
Hardware Required
S.no | Components | Value | Qty |
---|---|---|---|
1 | Arduino UNO | 1 | |
2 | USB Cable Type A to B | 1 | |
3 | Jumper Wires | – | |
4 | Digital Temperature Sensors | DS18B20 | – |
Circuit Diagram
Connection Table
Arduino | DS18B20 Digital Temperature Sensors |
---|---|
GND | GND |
D2 | DQ |
5V | VDD |
Arduino Code
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into digital pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// Setup a oneWire instance to communicate with any OneWire device
OneWire oneWire(ONE_WIRE_BUS);
// Pass oneWire reference to DallasTemperature library
DallasTemperature sensors(&oneWire);
int deviceCount = 0;
float tempC;
void setup(void)
{
sensors.begin(); // Start up the library
Serial.begin(9600);
// locate devices on the bus
Serial.print("Locating devices...");
Serial.print("Found ");
deviceCount = sensors.getDeviceCount();
Serial.print(deviceCount, DEC);
Serial.println(" devices.");
Serial.println("");
}
void loop(void)
{
// Send command to all the sensors for temperature conversion
sensors.requestTemperatures();
// Display temperature from each sensor
for (int i = 0; i < deviceCount; i++)
{
Serial.print("Sensor ");
Serial.print(i+1);
Serial.print(" : ");
tempC = sensors.getTempCByIndex(i);
Serial.print(tempC);
Serial.print((char)176);//shows degrees character
Serial.print("C | ");
Serial.print(DallasTemperature::toFahrenheit(tempC));
Serial.print((char)176);//shows degrees character
Serial.println("F");
}
Serial.println("");
delay(1000);
}
Working Explanation
Connect the multiple DS18B20 digital temperature Sensors with Arduino according to the procedure described above. Further, copy the code from this article and paste it into your Arduino IDE. Now, upload the code. Open the serial monitor and observe the readings.
Code Explanation
- Firstly, download and install the Dallas temperature library, You can download the library from:
- Now, include the downloaded library. Also, include the wire library to allow one-wire communication. Define the Arduino pin that is connected to the sensor’s pin. Give the command oneWire( ) to communicate with the one-wire device, which is a sensor. Use the command sensors( ) to pass the one-wire reference to the temperature library. Define the float object tempC to store the Celsius values.
- After that, in the void setup, initialize the sensor and the serial monitor.
- Finally, in the void loop, send the requestTemperature( ) commands to get the readings from the sensor. Print the readings in Celsius. Formulate the programming to convert the readings into Fahrenheit. Give the commands to print those readings. Give some delay time to get the new readings.
Application and Uses
Most importantly, this configuration can be used to measure the temperature at multiple points. over a large area. Also, it helps to measure the temperature in a hard environment. In addition, it can also estimate the temperature of liquids.