loader
DS18B20 Temparature Sensor www.iotboys.com feature img e1503818841225

In this article we are showing how to use DS18B20 one wire water proof temperature sensor.
With the help of DS18B20 one wire temperature sensor we can measure the temperature from -55℃ To 125℃ with accuracy of ±5 .

Components Required :-

  1. 1 x Arduino uno board
  2. 1 x USB cable
  3. 1 x DS18B20 Temperature Sensor
  4. 3 x Jumper wire (Male to Male)

Additional Library :-

  1. One Wire Library
  2. Dallas Temperature Sensor library

Installation Instruction is available here

Connection :-

DS18B20 Temparature Sensor www.iotboys.com

Sketch/Source Code :-

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

#define ONE_WIRE_BUS 5

OneWire oneWire(ONE_WIRE_BUS);

DallasTemperature sensors(&oneWire);

 float Celcius=0;
 float Fahrenheit=0;
void setup(void)
{
  
  Serial.begin(9600);
  sensors.begin();
}

void loop(void)
{ 
  sensors.requestTemperatures(); 
  Celcius=sensors.getTempCByIndex(0);
  Fahrenheit=sensors.toFahrenheit(Celcius);
  Serial.print(" C  ");
  Serial.print(Celcius);
  Serial.print(" F  ");
  Serial.println(Fahrenheit);
  delay(1000);
}

31 Comments

  1. Tim Smith

    Hi. Great tutorial, thanks. Quick note, I used the waterproof DS18B20 from Sparkfun instead of the Elenker shown above. This required a pull-up resistor in order to complete the project. Again, thanks… Tim

    1. Linda Whitfield

      Tim, why did you use a pull-up resistor? I’m using the same sensor as well, and it’s just outputting the same values. Is that why it is doing that?

        1. bob

          “Its because of safety, else it will burn.”

          No, that’s not what pull-up resistors are for

        2. mithu

          hey ,i also didn’t use resistor but i am getting -127 celcius ,,,,
          where is my error please notice me

    1. IoT Boys

      No, DS18B20 Digital Thermometer provides 9 to 12-bit (configurable) temperature readings which indicate the temperature of the device. For soil temperature measurement you can use 109SS-L sensor.

  2. Elsa

    My serial monitor keeps giving C-127 while the water is boiling, is there something wrong in my code?

    1. IoT Boys

      Hi Elsa,
      Definitely there is something wrong, so what I suggest to do check proper wiring once otherwise most probably your sensor is not working fine so check with other sensor.

      Best Regards,
      IoTBoys

  3. Huntikhtk

    Hi, Im using this in an Arduino Mega 2560. I dont know if i have to put a pull-up resistor (and if i have to do, how and where i connect it), it uploads fine but the serial monitor always give -127 C. Can someone help me??

  4. Anuja

    Hello Sir,
    Can we use six sensors in Arduino for data logging ? Actually, I want to make a data logger with 6 channels.
    Please help.
    Thanking you in anticipation.

    Regards,

  5. Akshay Patil

    Hello. I wanted to measure whether human skin is in contact with something for my project. I was thinking about using this sensor fpr measurement of skin temp. Can I do it with this device

  6. Akeyan

    Sir im having the problem of sensor showing wrong value like 127 celicus i tried using different sensors but the problem still remained the same please help why is this error occuring.
    Thankyou

  7. FOYSOL MAHMUD

    I am using Arduino mega 2560 and the sensor is giving -127c and -127F. What is the problem

  8. pema Loday

    Hello Sir I get -127C and -192F would you like to help me to find the error i did same as you

  9. Cath

    Hi, I tried to follow the codes u provided above but it said “One_Wire_Bus” was not declared in this scope. what should I do?

Leave a Reply

Your email address will not be published. Required fields are marked *