Arduino DS18B20 Temperature Monitor

Author : Dinesh Kumar Wickramasinghe

Introduction and Images

Hello Friends, How are you? Today we are going to build another temperature monitor. Hope you’ve done our first temperature monitor project using the LM35 Analogue temperature sensor. This time we are going to use the waterproof digital DS18B20 thermometer with arduino and create a temperature monitor project. Here are some images of the completed project.

DS18B20 Digital Thermometer

The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements. This sensor communicates over a 1-Wire bus.

Some features of DS18B20 thermometer are as follows

  • Unique 1-Wire® Interface Requires Only One Port Pin for Communication.
  • Measures Temperatures from -55°C to +125°C (-67°F to +257°F) (±0.5°C Accuracy from -10°C) to +85°C.
  • Programmable Resolution from 9 Bits to 12 Bits.
  • No External Components Required.
  • Parasitic Power Mode Requires Only 2 Pins for Operation (DQ and GND).
  • Simplifies Distributed Temperature-Sensing Applications with Multidrop Capability.
  • Each Device Has a Unique 64-Bit Serial Code Stored in On-Board ROM.
  • Available in 8-Pin SO (150 mils), 8-Pin µSOP, and3-Pin TO-92 Packages.

For more information, please refer the datasheet.

In this example, I will use the waterproof version of the DS18B20 as on below picture. This version can be used to measure the temperature of liquids as well. Yellow color wire is the data pin, Black one ground and Red one +5v or +3.3v

DS18B20 Waterproof

You can also use the below version as well. This version looks like a transistor and it is cheap. Both versions functions same.

DS18B20
Connection to the Arduino

You can refer the below schematic to connect your thermometer to Arduino. You have to connect a 4.7 K resistor between data pin and the +3.3V pin as a pull-up resistor.

Arduino DS18B20 Scematic

Please note that this thermometer works on both 5V and 3.3V power. Here I use 3.3V supply on Arduino since it is more safe.

Additional Libraries

You need to install two additional libraries to complete this tutorial.

  • One Wire
  • Dallas Temperature

Go to Arduino IDE Menu : Sketch > Include Library > Manage Libraries

On Library manager window, first search for "onewire" and install the onewire library as on below screenshot.

Install onewire Library Arduino IDE

Then search for "dallas" and install the dallasTemperature library as on below screenshot.

Install dallasTemperature Library Arduino IDE

Now you have done the required configurations on Arduino IDE and it's time to write your code and continue the experiment. (Please note that the above steps download the libraries from Internet and your PC should be connected to internet to download those driverse)

Arduino Code

Copy and paste the below sketch to your Arduino IDE and upload it. Once the code uploaded, open the Serial Monitor. You will see the temperature readings are coming every 2 seconds as on below screenshot.

#include <LiquidCrystal.h>
#include <OneWire.h> 
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);

void setup()
{
  sensors.begin();
  Serial.begin(9600);
}
void loop()
{
  sensors.requestTemperatures();
  float tempC = sensors.getTempCByIndex(0);
  float tempF = ((9.0*tempC) / 5.0) + 32.0;
  Serial.print(tempF);
  Serial.println(" F");
  Serial.print (tempC);
  Serial.print("C");
  Serial.println("---------------");
  delay(2000);
}
                    
Show Temperature on LCD

You can also connect a LCD screen to your project and monitor temperature. Here is the schematic and the source code for the temperature monitor with LCD.

Schematic

Arduino DS18B20 With LCD

Sketch (Source Code)

#include <LiquidCrystal.h>
#include <OneWire.h> 
#include <DallasTemperature.h>

#define ONE_WIRE_BUS 2
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
LiquidCrystal lcd (7, 8, 9, 10, 11, 12);

void setup()
{
  sensors.begin();
  lcd.begin(16, 2);
  lcd.setCursor(1,0);
  lcd.print("-TEMPERATURE-");
}
void loop()
{
  sensors.requestTemperatures();
  float tempC = sensors.getTempCByIndex(0);
  float tempF = ((9.0*tempC) / 5.0) + 32.0;

  lcd.setCursor(0, 1);
  lcd.print(tempF);
  lcd.print((char)223);
  lcd.print("F ");
  lcd.print (tempC);
  lcd.print((char)223);
  lcd.print("C");
  delay(2000);
}
                    

Here is my output on LCD

Arduino DS18B20 With LCD Output

Hope you enjoyed the tutorial, If you face any issues while following my steps, please mention them as a comment, Then I will respond. Have a good day!

Comments Area
Add your questions and comments here. Comments will be published after the admin approval
Published By : Verma
Added Date :5/2/2018 10:29:47 AM
This is nice, What is the difference between LM35 and DS18B20?

 

Similar Projects

Go Top