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



  • Creative Misuse Contest

    Creative Misuse Contest
  • Oil Contest

    Oil Contest
  • Water Contest

    Water Contest

30 Discussions

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.

1 reply

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?

3 replies
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"

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

Circuit was given there .... Just connect the digital data pin to the PIN 7 of the arduino uno.................

Is there a way to display Fahrenheit on the screen? I know that you can multiply the Celsius by 1.8 then add 32 to convert it. Can I apply this in the code?

2 replies

******This is not tested.. So please let me know whether it works or not.

>>>> change little bit in this portion----------


void loop(void) {

float temperature = getTemp();

float tempinf=(temperature*1.8+32);

lcd.setCursor(0, 1);
lcd.print("Temp : ");

lcd.print(" *F");


******This is not tested.. So please let me know whether it works or not.

Hmm you can.... Right now I can't test the code... I will try it then reply tomorrow. ..

Rahul, Very nice project. I would like to know something if you can.

I have TAIE digital temperature controller which I am using for temperature controlling in a specified range say 30 +/- 2 C. I want to connect it with arduino to give an alarm if it gets out of range and even send or call on a phone number. I know, for that I would required Arduino UNO, GSM module and a buzzer but don't know the arrangement. Pls. help if possible.

2 replies

it would be very easy if you tell me about TAIE. Its new to me.... Does it have any output pin that could be connected to arduino...????

Thanks for comment.... Please give me some time, i will reply you as soon as possible.
Thanks again...

can you please let me know how to convert to Fahrenheit ? and where should i include the code ?.

1 reply

I am sorry that i didnt noticed your comment... Have u solved your problem? If not then let me know.. I will help you.

Why it's show Temp : -1000. 00 on the screen? I'm using Arduino uno R3