Measuring temperature is incredibly useful. It is probably one of the most important environmental variables and there are a wide range of devices to do this task.

I have recently had a number of projects which require accurate temperature measurement and storage, including a data acquisition system to measure hot water usage and a monitoring system for my home fermentation equipment.

Here I give an overview of a few different sensors which can be used to monitor temperature and how to read that data with a microcontroller (the ubiquitous Arduino).

There are a number of ways to convert temperature into and electronic signal. The main ways are:

  • Thermo-couples
  • Thermistors
  • Analogue output devices
  • Digital output devices

Here is a brief introduction to these methods, along with pros and cons. One of the projects was already using digital out put devices (the Dallas Semiconductors DS18B20) and hence I will focus on that device.

Thermo-couples

A thermocouple consists of two different conductors which, when subjected to a temperature gradient, will produce a voltage proportional to the temperature difference.

The devices are ubiquitous in lots of products as they do not need a power supply and are cheap and come in a wide range of temperature ranges. They have very small thermal mass so they can respond quickly to changes in temperature. Disadvantages include the very small output voltage, the need for cold-junction calibration and the lack of accuracy (it is hard to get accuracy better than 1%).

Thermistors

A thermistor is a resistor whose resistance value varies with temperature. I also include the Resistance Thermometer (RTD) in this section, but the two devices are slightly different. These can be used to give a varying output voltage, by wiring them in a potential divider circuit.

Thermistors and RTDs can have high accuracy, but they are expensive (for accurate sensors) and suffer from non-linearlity, so some kind of look-up graph or relatively complex calculation is required to convert the resistance into a temperature.

Updated 22/11/12:

Sometimes reading thermistors can be a better solution for quickly reading temerature. I recently needed to read a temeratur which was going to vary quite quickly. Hence I needed to read temperature quickly and the sensor must respond to fast changes in temperature. The problems with digital output devices are that they take a while to respond to a temperature read request (in the case of the DS18B20 it can take up to 750mS) and also they typically have quite a large body and hence quite large thermal mass. This means they have a slight delay in warming up and cooling down.

For that particular operation I decided to use a very small body thermistor, which would have a very small thermal mass and hence can change temperature quite quickly.

I used a thermistor with a 10k ohm resistance as a potential divider with a resistor of the same value (10k). This gives me an output voltage which will vary in responce to the temperature, around the mid point.

Two different techniques can be used to convert the change in resistance/voltage into a temperature:

  • Use a look-up table
    • Can be very accurate.
    • Can be calibrated for each sensor
    • Takes up quite a lot of memory
  • Use the Steinhart-Hart equation (http://en.wikipedia.org/wiki/Thermistor)
    • Less memory used
    • Can be accurate

Chatting with a friend from Nottingham Hackspace, he had looked into this problem and had kept a record of his ideas here.

I am using an Arduino to read in the analouge voltage. I have been using the code presented here to convert the value. You need to change lots of the parameters depending upon the type of thermistor. The data sheet for the thermistor I am using is here. The B value is 4126 +/- 3%, with an output (T0) of 25C (298.1K) at (R0) 10k ohm resistance.

Some useful more detailed additional information regarding thermistors is available here: https://www.electrical4u.com/thermistor/ This site also has much more information on temperature monitoring.

Analogue output devices

There are a number of integrated components which contain circuitry which reads the temperature and outputs a linear voltage which is proportional to the temperature. I am used to using the LM35 from Texas Instruments, which outputs 10mV per degree centigrade. The output voltage is linearly proportional and accuracy is in the region of 0.5C.

These are useful devices and relatively cheap and accurate. Problems include the need for negative voltage supplies to be able to measure negative temperatures. The main problem is that you will need to use an analogue input for each temperature sensor you would like to measure (or use a multiplexer, on analogue input and a few digital outputs). You would also need to run separate wiring to each sensor.

There is a great instructable from adafruit on using temperature sensors, here.

Digital output devices

A digital output temperature sensor has an in-built analogue to digital converter. The temperature is measured and then converted into a digital signal. This digital signal can then be read by the micro-controller. Generally the output is in the form of a serial data stream. The more useful devices have unique IDs and hence can be called to give their data by the microcontroller. This means a number of sensors can be added to just one set of wires. The really great ones use a 1-wire data interface and can be run from ‘parasitic power’ (i.e. they do not need a direct power supply) and hence you can interface to a number of devices with just two wires. You only need 1 digital pin to measure numerous devices. Their main disadvantage is their higher cost.

The Dallas Semiconductor DS18B20 (datasheet is here) is a programmable resolution 1-wire digital thermometer. This is a clever little device with a load of features included. They are quite expensive (around £3.50 from RS) but you can also get bulk deals on these from China/eBay.

The DS18B20 includes a temperature sensor which has up to 12 bit accuracy and an operating range of -55 to +150°C. It is accurate to 0.5°C, which is good for temperature. It is a 1-wire device, which means we only need 1 data wire to talk to it (along with power and ground). Each IC has a unique 64-bit serial code. This means that if we have a number of them in the system then we can get data from each one individually. We can have a number of these sensors on a single data wire and still get back temperature readings from each one individually via a serial data stream. This means we only need one microcontroller pin to talk to loads of temperature devices. We send the device ID and that particular device will send back the temperature reading.

The pin out of the device is shown here.

Luckily someone has already worked on the code to talk to these devices with the Arduino. There are lots of tutorials like this one. Generally the sensors are used in parasitic power mode. This means they do not need local power and this saves one wire to the device. The tutorial just mentioned deals with the BS18S20, hence the parasitic power wiring is not correct for the DS18B20. For the DS18B20: Pins 1 and 3 should be grounded for the parasitic power mode to work. You will also need a 4k7ohm resistor to pull up the data line to Vcc (the supply voltage).

The Dallas Temperature Control Library is a library for the Arduino microcontroller. Go to this site and download the latest version on the library. Copy it into your Arduino sketchbook folder. Also download the latest copy of the OneWire Arduino library. Copy this to your sketchbook as well.

Start (or re-start) the Arduino IDE (I am using version 0.22). You should have two extra folders in your sketchbook list. I opened the DallasTemeprature folder and opened ‘tester’. Uploading the code to my Arduino-clone. I then opened the serial monitor and reset the Arduino. This is the data sent back. I had changed the program to give me 12bit resolution and put 2 devices on the 1 wire. Success!

Dallas Temperature IC Control Library Demo
Locating devices...Found 2 devices.
Parasite power is: ON
Found device 0 with address: 282680E403000072
Setting resolution to 12
Resolution actually set to: 12
Found device 1 with address: 289577E4030000DB
Setting resolution to 12
Resolution actually set to: 12
Requesting temperatures...DONE
Temperature for device: 0
Temp C: 23.25 Temp F: 73.85
Temperature for device: 1
Temp C: 23.19 Temp F: 73.74
Requesting temperatures...DONE

It the carries on reading temperature every 1/2 second or so. You can see that it has found two devices, each with a unique identifier. It has set the resolution to 12 bit and then started to read the temperature.

This is exactly what I need and I can easily expand the system to read more temperature sensors.

I found a source of DS18B20 sensors for around 80p each here and ordered a load for a number of projects. Now I can monitor the temperature of everything….

More information

Here are some useful links:

EDN collection of temerature sensing notes

 

Leave a Reply

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