Digital Thermometer With Arduino & DS18B20





Introduction: Digital Thermometer With Arduino & DS18B20

Simply create a digital thermometer with can tell you the current room temperature on a LCD screen. This is a beginners project.

Apparatus that you need:
1. Arduino UNO R3
2. DS18B20 temperature sensor.
3. 16X2 LCD display.
4. Connecting wires.
5. Project board. 

Now lets make digital thermometer.....

This is a Atmega168 pinouts for arduino. Just skip this if you wat to make this thermometer with your arduino.

Step 1: Make Arduino on Breadboard.

Creating arduino on a breaboard is very easy. Now step by step wiring procedure is given below:
1. Pin 7  -> +5V
2. Pin8   -> GND
3. Pin9 -> Crystal -> 22pF capacitor -> GND
4. Pin10-> Crystal -> 22pF capacitor -> GND
5. pin 22 -> GND
6. Pin21 & Pin20 -> +5V
7. Pin1-> 10K registor to GND + Push button to +5V

Now you are ready.................

Step 2: Connecting LCD

Step 3: Connecting DS1307 Temperature Sensor

Step 4: Preparing the Circuit.

Connect the LCD with the atmega or arduino according to the default LCD example on the arduino IDE.

Now connect DS1307 DATA bus to the DIGITAL PIN 7 (Atmega pin 13)

Step 5: Arduino CODE

#include <OneWireTempSensor.h>

#include <OneWire.h>
#include <LiquidCrystal.h>
int DS18S20_Pin = 7; //DS18S20 Signal pin on digital 7 by rahulmitra
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
//Temperature chip i/o
OneWire ds(DS18S20_Pin); // on digital pin 7 by rahulmitra

void setup(void) {
  lcd.begin(16, 2);
  // Print a message to the LCD.
  lcd.print("Rahul Mitra");

void loop(void) {
float temperature = getTemp();
  lcd.setCursor(0, 1);
    lcd.print("Temp : ");
    lcd.print(" *C");
delay(100); //just here to slow down the output so it is easier to read


float getTemp(){
//returns the temperature from one DS18S20 in DEG Celsius

byte data[12];
byte addr[8];

if ( ! {
//no more sensors on chain, reset search
return -1000;

if ( OneWire::crc8( addr, 7) != addr[7]) {
Serial.println("CRC is not valid!");
return -1000;

if ( addr[0] != 0x10 && addr[0] != 0x28) {
Serial.print("Device is not recognized");
return -1000;

ds.write(0x44,1); // start conversion, with parasite power on at the end

byte present = ds.reset();;
ds.write(0xBE); // Read Scratchpad

for (int i = 0; i < 9; i++) { // we need 9 bytes
data[i] =;


byte MSB = data[1];
byte LSB = data[0];

float tempRead = ((MSB << 8) | LSB); //using two's compliment
float TemperatureSum = tempRead / 16;

return TemperatureSum;


Step 6: Finally You Have Done

Step 7: See LIVE



  • Epilog Challenge 9

    Epilog Challenge 9
  • Paper Contest 2018

    Paper Contest 2018
  • Pocket-Sized Contest

    Pocket-Sized Contest

We have a be nice policy.
Please be positive and constructive.




If you get an error trying to compile this code, remove the first line "#include <OneWireTempSensor.h>" because this isn't needed. #include <OneWire.h> does the very same thing.

hi.thanks very lot for this project.
I have a question:
how can i save the log for a month which data save per hour a day.
i mean save the log hour to hour for 1 month.and so i can draw the graph of these logs.
please help me.thanks a lot master.

There are two ways to do that...
1. web server
2. SD Card.

To do this with Web server, you need a web server and Ethernet shield for the arduino. Arduino will send the data only and a server side script will process the data and post the data in MySQL data base with current time stamp. And the benefit of this method is you can monitor real time data in web browser also real time graph.

And to do this with SD card you need and micro sd card and card shield and a clock module. then you can find example code in Arduino IDE. Than edit it and save the file name as "xxxx.csv". and write the data with (,) separated method. It will save an MS excel file in the sd card. And remove the card and connect it to pc with card reader. and open it in excel. and process it in excel.

*** Sorry for bad english.

i have problems:

Arduino: 1.6.5 (Windows 7), Board: "Arduino/Genuino Uno"

In file included from sketch_aug29c.ino:1:0:

C:\Users\Maretic\Documents\Arduino\libraries\OneWireTempSensor/OneWireTempSensor.h:26:22: fatal error: WProgram.h: No such file or directory

#include <WProgram.h>


compilation terminated.

Error compiling.

This report would have more information with

"Show verbose output during compilation"

enabled in File > Preferences.

Can you help me?

To patch the problem, just open displayshield4d.cpp and replace

#include "WProgram.h"

by this :

#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#include "WProgram.h"

hmm, how to open displayshield4d.cpp ?

im total noob :D

Hi, Do you have a *.ino version to send me? Thanks.

please tell the EXACT TEMPERATURE SENSOR name... And please upload the circuit DIAGRAM of this project...