Arduino Thermometer

A few weeks ago I was in Maplins and came across a bag of ‘lucky dip’ displays, there were various different 7-segment displays and some LCD displays. None of them came with pin outs, as expected, the 7-segment displays were quick enough to get working, however the LCD displays are a bit more of an issue, and so I’ll leave these for another time.

With a dual 7-segment display, a DS18B20 temperature sensor that I had and a couple of shift registers I figured that I could build a digital thermometer (exciting I know!).

Temperature Sensor

The sensor I’m using is the DS18B20, it’s a 3pin sensor that just requires a single input pin from the arduino. Multiple sensors can be hooked together, however I’m just using one for this project. As with a lot of different sensors there’s a handy library that makes it particularly easy to get the temperature in centigrade or fahrenheit, it’s the Dallas_Temperature library available here and a spec sheet for the sensor available from maxim.

To connect it to the arduino connect the ground pin on the sensor to a ground pin on the arduino, put a 4.7k resistor between pin 2 and pin 3 on the sensor, connect pin 3 to 3.3v from the arduino and then connect pin 2 to digital input on the arduino. Once this is done, we’re ready to read the temperature!

Code

The code below just sets up temperature sensor and then outputs it to serial

Controlling the Display

I chose to use a dual 7-segment display from the ‘lucky dip’ bag, it didn’t take long to figure out the pin outs, however an issue was the number of pins this would require from the arduino if I hooked it up directly, a massive 16. With two shift registers hooked up together this could reduce the number of pins required to only 3, as the two shift registers require only 3 pins and with being hooked together provide 16 parallel outputs. To work out how to connect the two shift registers I used this handy tutorial, and then connected the output pins to the pins on the 7-segment displays. (Note that at the moment I haven’t used resistors between the display and the shift registers mainly because I didn’t have room on the board, you should however just to be safe!)

Putting it Together

The code I’ve put together is at the end of this post. It basically sets up the temperature libraries, reads the temp, and then puts this into the shift registers. I’ve commented the code but if there are any issues then let me know!

Code:

Temperature_sketch_bb

Arduino_temp

David Roberts

Read more posts by this author.

Newcastle upon Tyne, UK https://davidatroberts.github.io/