Digital Temperature Sensor DS18B20 With Arduino

by Utsource in Circuits > Arduino

1005 Views, 0 Favorites, 0 Comments

Digital Temperature Sensor DS18B20 With Arduino

20191121_182345.jpg
Hi guys in this instructables we will learn how to use DS18B20 temperature sensor with arduino.
So in this instructables we will do required setup & Libraries for this temperature sensor.

Things You Need

Km5Zu-2RIncAUweU7uG7IhyWPySZ0SqIgAI0-vk9w7767_IkthCPCcsirj2GGmXF4IdQDg8UVpHVLVM6CXnzFsG1hnAdSkK7BIhIOtEldXoZiDsvzsPo-6o0rD6Mda7UyOE=w456-h323-nc.png
images(112).jpg

For this instructables we will need following things :

Arduino uno

Jumper wires

Breadboard

DS18B20

Resistor 4.7k ohm

About DS18B20

images(112).jpg
The DS18B20 temperature sensor is a one-wire digital temperature sensor. This means that it just requires one data line (and GND) to communicate with the Arduino.

It can be powered by an external power supply or it can derive power from the data line (called “parasite mode”), which eliminates the need for an external power supply.
We will take a look into its working modes in further steps.

Connections

20191121_183612.jpg
20191121_183635.jpg
The sensor can operate in two modes:

Normal mode: 3-wire connection is needed. You provide power to the VDD pin. Here’s the schematic you need to follow:

Parasite mode: You only need data and GND. The sensor derives its power from the data line. In this case, here’s the schematic you need to follow:

You can read the temperature of more than one sensor at the same time using just one Arduino digital pin. For that, you just need to wire together all the sensors data pins to an Arduino digital pin.

Installing Libraries

20191121_184256.jpg
20191121_184244.jpg
1. Open your Arduino IDE and go to Sketch > Include Library > Manage Libraries. The Library Manager should open.

2. Type “OneWire” in the search box and install the OneWire library by Paul Stoffregen.


3. Then, search for “Dallas” and install the Dallas Temperature library by Miles Burton.

Code

images(110).jpg
Please copy the following code and upload it to the arduino Board :

#include "OneWire.h"
#include "DallasTemperature.h"

// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
}

void loop(void){
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();

Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(" - Fahrenheit temperature: ");
Serial.println(sensors.getTempFByIndex(0));
delay(1000);
}

Reading Temperature

20191121_184737.jpg
After uploading the code & connecting everything together plug the arduino cable to the PC and open the serial monitor in arduino ide and you'll able to read the temperature data in your serial monitor from this sensor.