English - nlpke/DS18B20-Arduino-Tutorial GitHub Wiki

DS18B20 Arduino Tutorial

The DS18B20 is a cheap temperatur sensor. As the DS18B20 uses an OneWire Protocol you'll have to install the following libraries (they can be found in the library manager):

  • OneWire Library
  • DallasTemperature

In this repository you'll find two sketches:

Every sketch returns the values via the serial monitor at a baud-rate of 9600.

  • Sketch A: This sketch returns the current temperature (in °C) and time (seconds since the beginning of the sketch) every two seconds. You may copy&paste these values into LibreOffice or Excel for visualization purposes.

  • Sketch B: This sketch returns the current temperature (in °C) every two seconds. Every sixty seconds, the sketch returns the average value of all measurements and the average of the measurements in the last sixy seconds.

Connecting the sensor to your Arduino

You'll need:

  • Arduino
  • DS18B20 (of course)
  • Breadboard
  • 4.5K Resistor
  • Computer

1. Upload one of the Sketches to your Arduino

Use the Arduino IDE to the sketch which suits your needs best. Don't forget to install the two libraries mentioned above.

2. Wiring the sensor up

DS18B20 Wiring

First, disconnect the Arduino from USB or any different energy source.

Your sensor should have three cables:

  • Red: Vin (Vmax = 5.5V - Be careful)
  • Yellow: OneWire Interface (this cable will transmit the data to your arduino)
  • Black: Ground

Now, wire the Vin to the 3.3V Pin of your Arduino and the ground wire to the ground Pin of your Arduino. You may connect the OneWire Cable to any port of the Arduino, the Sketches you find in the Repositroy use PIN9. Important: You need to add the 4.5K resistor between the OneWire cable and the V-in cable (it acts as a PullUp Resistor)

3. Use the sensor

After checking your wiring, you may connect the Arduino to USB. Via the serial monitor you can see the values of the sensor.