Tags: Temperature Sensor DS18B20

Temperature Sensor DS18B20

  • 9.00 AED
    • Ex Tax:9.00 AED
    • Product Code:
    • Availability: In Stock
    The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communicat..

    The DS18B20 digital thermometer provides 9-bit to 12-bit Celsius temperature measurements and has an alarm function with nonvolatile user-programmable upper and lower trigger points. The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with a central microprocessor.

    In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply. Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems.

    Introduction 

    In this tutorial you will learn how to use DS18B20 temp sensor with Arduino. The temperature will be printed on the serial monitor of Codebender or Arduino IDE.

    Before we start let's see more information about this sensor.

    About DS18B20 sensor

    The DS18B20 communicates over a 1-Wire bus that by definition requires only one data line (and ground) for communication with Arduino. It has an operating temperature range of -55°C to +125°C and is accurate to ±0.5°C over the range of -10°C to +85°C. In addition, the DS18B20 can derive power directly from the data line (“parasite power”), eliminating the need for an external power supply.
    Each DS18B20 has a unique 64-bit serial code, which allows multiple DS18B20s to function on the same 1-Wire bus. Thus, it is simple to use one microprocessor to control many DS18B20s distributed over a large area. Applications that can benefit from this feature include HVAC environmental controls, temperature monitoring systems inside buildings, equipment, or machinery, and process monitoring and control systems.
    Picture
    Basic Features:
    • Unique 1-Wire Interface Requires Only One Port Pin for Communication
    • Each Device has a Unique 64-Bit Serial Code Stored in an On-Board ROM
    • Requires No External Components
    • Can Be Powered from Data Line; 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

    ​Find more info here: datasheet

    What you will need - Hardware

    The Circuit

    Picture
    The connections are pretty easy, see the image above with the breadboard circuit schematic.
    • Vcc & GND pins of sensor --> Arduino GND
    • Signal (middle pin) --> Arduino Pin 2
    • 4.7K Resistor between signal pin and 5V pin

    The code

    Here's the code, 
    • Serial.println(sensors.getTempCByIndex(0)); returns temperature in Celsius scale
    • Serial.println(sensors.getTempFByIndex(0)); returns temperature in Fahrenheit scale
    Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire! Try to add a second sensor and include the following command in your code: Serial.println(sensors.getTempFByIndex(1));

    /* Arduino DS18B20 temp sensor tutorial
       More info: http://www.ardumotive.com/how-to-use-the-ds18b20-temperature-sensor-en.html
       Date: 19/6/2015 // www.ardumotive.com */
    
    //Include 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)
    {
      Serial.begin(9600); //Begin serial communication
      Serial.println("Arduino Digital Temperature // Serial Monitor Version"); //Print a message
      sensors.begin();
    }
    
    void loop(void)
    { 
      // Send the command to get temperatures
      sensors.requestTemperatures();  
      Serial.print("Temperature is: ");
      Serial.println(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
      //Update value every 1 sec.
      delay(1000);
    }
    
    Download the code from here and open it with Arduino IDE. Inside you will also find additional libraries.
    ds18b20_tutorial.zip
    Download File


    Open the serial monitor from tools menu of Arduino IDE.

    You can keep playing with that start making your own modifications to the code.

    For example, try to change delay time and see how it changes the program. You can also try to connect more ds18b20 sensors!

    Well done!


    There are no reviews for this product.

    Write a review

    Please login or register to review