Introduction
This Arduino tutorial will teach you how to use a “DS18B20 digital temperature sensor” to measure the temperature of the air, liquids like water, and the temperature of the ground. This is a useful tool for monitoring temperature trends, detecting changes in temperature, and more. So Let’s Get Started!
FS Tech is a leading Shenzhen PCB assembly manufacturer, having 18 years of one-stop PCBA manufacturing and overseas project management experience. FS Tech provides low-cost Turnkey PCB Assembly Services
Hardware Components
You will require the following hardware to interface DS18B20 Digital Temperature Sensor with Arduino UNO.
Components | Value | Qty |
---|---|---|
Arduino UNO | – | 1 |
Temperature Sensor | DS18B20 | 1 |
Resistor | 4.75k ohm | 1 |
Breadboard | Mini | 1 |
Jumper Wires | – | 1 |
DS18B20 Sensor
DS18B20 is a One-Wire digital temperature sensor from Maxim IC. It measures temperature from -55 to 125 (+/-0.5) in degrees Celsius with 9 -12-bit precision. Each sensor has a unique 64-Bit Serial number which allows for a huge number of sensors to be used on one data bus.
DS18B20 Features
- Unique 1-Wire® interface requires only one port pin for communication
- Each device has a unique 64-bit serial code stored in an onboard ROM
- Multidrop capability simplifies distributed temperature sensing applications
- Requires no external components
- Can be powered from a data line.
- The power supply range is 3.0V to 5.5V
- Measures temperatures from –55°C to +125°C (–67°F to +257°F)±0.5°C accuracy from –10°C to +85°C
- Thermometer resolution is user-selectable from 9 to 12 bits
- Converts temperature to 12-bit digital word in 750ms (max.)
- User-definable nonvolatile (NV) alarm settings
- The alarm search command identifies and addresses devices whose temperature is outside of programmed limits (temperature alarm condition)
- Applications include thermostatic controls, industrial systems, consumer products, thermometers, or any thermally sensitive system
DS18B20 Pinout
Pin Name | Description |
---|---|
Yellow | Data Pin |
Black | GND |
Red | VCC |
DS18B20 Temperature Sensor Interfacing with Arduino
Here in this tutorial, we interface the DS18B20 Temperature Sensor with Arduino UNO
Installing Arduino IDE
First, you need to install Arduino IDE Software from its official website Arduino. Here is a simple step-by-step guide on “How to install Arduino IDE“.
Installing Libraries
Before you start uploading a code, download and unzip the following libraries at /Progam Files(x86)/Arduino/Libraries (default), in order to use the sensor with the Arduino board. Here is a simple step-by-step guide on “How to Add Libraries in Arduino IDE“.
Schematic
To print the data from DS18B20 on the serial monitor of the IDE you have to build the circuit by following the schematic.
Wiring / Connections
Arduino | DS18B20 | Resistor |
---|---|---|
5V | VDD | One End |
GND | GND | – |
PIN 2 | Data | Other End |
Code
/********************************************************************/
// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
/********************************************************************/
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/********************************************************************/
void setup(void)
{
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
/********************************************************************/
Serial.print(" Requesting temperatures...");
sensors.requestTemperatures(); // Send the command to get temperature readings
Serial.println("DONE");
/********************************************************************/
Serial.print("Temperature is: ");
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
// You can have more than one DS18B20 on the same bus.
// 0 refers to the first IC on the wire
delay(1000);
}