DS18B20: accurate temperature readings with Arduino

Published on: 01-03-2016 13:37 - Lees in het Nederlands

Please note: this article was semi-automatically translated from Dutch, translation errors may occur, links will lead to Dutch websites, you are welcome to comment in English.

A lot of my Arduino projects are using temperature sensors. Most of the time I'm using cheap and easy to use NTC's - temperature dependent resistors - but they aren't calibrated nor very accurate. Therefore I'm starting to use the DS18B20 one-wire temperature sensor.

Measuring temperature with Arduino

There are numerous ways to measure temperature with your Arduino. The easiest way is creating a voltage divider circuit with an NTC (Negative Temperature Coefficient) and a fixed resistor as I already described in the article about the Arduino weatherstation.

Downsides of using NTC's

The biggest downside of using an NTC is its unreliability. Not even a single NTC is exactly 5K, 10K or 20KOhm as specified and the same applies to the resistors. Therefore every version of the voltage divider circuit will differ from each other. Next to that it's very complex to derive a formula that describes the behavior of the NTC which makes most people chose the easy way by using a lookup-table. Now adding up all these uncertainties and your readings are way off.

A common deviation of an NTC-based temperature sensor is about 1,5 degrees Celsius. For a simple project this doesn't have to be a problem, most of the time you want something to happen at a certain threshold that doesn't have to be very specific. But since I'm adding these sensors to my home automation and weather station for climate purposes I want more accurate readings. I want to be able to compare reading from different rooms with each other and save them for drawing long-term graphs.

Other possibilities for measuring temperature

My weather/home automation system has a lot of sensors, and some of them have temperature sensors integrated, for instance because they need it to correct or temperature compensate their own readings. Humidity is for instance measured as relative humidity which is dependent of the temperature - hot air can store more moisture than cold air, hence condensation occurs when the temperature drops. These integrated sensors for relative humidity and air-pressure have simple temperature sensors inside which can be read using their corresponding libraries.

The DHT11 is one of the humidity sensors I'm using. This sensor is able to measure temperatures from 0 tot 50 degrees Celsius with an accuracy of 2 degrees Celsius. That's even worse than my own NTC solution, and since it can't measure below zero totally useless for outside.

For measuring air-pressure I'm using the BMP085. This sensor is able to measure below zero, from -40°C to 85°C, but also with an accuracy of only 2°C. The location of your temperature senosris also important, unfortunately I've soldered my BMP085 directly onto my home automation shield which get's quite hot due to the Arduino and Ethernetshield below it.

DS18B20 OneWire temperature sensor

Our saver is the DS18B20 one-wire temperature sensor. With a large reach of -50°C to 125°C and an accuracy of 0,5°C this sensor is exactly what I'm looking for!

The DS18B20 is digital, factory calibrated, temperature sensor, so our readings are always spot-on. Since it is a 1-wire sensor you can connect lot's of them together on a single data wire, and using parasite-mode you can even work with 2 wires in total, great if you need lot's of temperature sensors. Luckily someone already wrote an excellent DS18B20 library for communicating effortlessly with your Arduino.

Connecting the DS18B20 to Arduino

Connecting a DS18B20 oneWire temperature sensor to an Arduino using a pull-up resistor

The DS18B20 looks very similar to a transistor: it has a flat side and 3 legs. When holding the flat side towards you the pins, from left to right, are Ground, Data and VCC (+5 Volts). Connect the three pins to the corresponding pins of your Arduino: ground to gnd, VCC to +5V and data to one of your digital inputs. Don't forget to add a pull-up resistor of about 4,7 Kilo Ohms between 5 Volts and Data, as can be found in the datasheet.

Since I've replaced all of my (important) NTC's with DS18B20's I'm enjoying very accurate temperature readings in my Arduino home automation system. When you need a lot of DS18B20's or even waterproof ones you can buy them cheap on AliExpress!

7 comments on this article »

More articles like this one