Monday, October 31, 2011

Arduino Thermometer

For the last few months I've been considering getting an arduino board to play with, and last week I took the plunge and bought a SparkFun Inventor's Kit.

Over the weekend I had a bit of a play with some of the example circuits, making some small changes to them here and there when I saw further possibilities. But most of the examples are basically just that - examples of how the components work. Most of those that I built really amounted to no purpose.

So tonight I put together what I'd learned so far and built something with a purpose: a digital thermometer.

Ok, so it's not the easiest thermometer to read! Here's a close-up of the LEDs.

The top row of LEDs (which are actually yellow) show the 10's, so 2 out of 3 lit means the temperature is in the 20's. 

The bottom row is made up of 1 yellow (on the left, currently off) and 4 reds (3 on and 1 off). I'll explain the yellow in a second and skip to the reds, which show the degrees in increments of 2. That is, 2, 4, 6, and 8 respectively, from left to right. The photo shows up to the third is lit, so they represent 6 degrees. 

The yellow LED on the left is the last unrepresented digit: whether the temperature is odd or even. It's off in the photos, meaning the temperature is even.

So the temperature is 20+6+0, or 26C.

It all starts with a TMP36 temperature sensor, which is just visible on the very right of the breadboard in the first photo - it looks identical to a transistor. The voltage drop across this sensor changes with temperature, so I measure that with one of the analog pins on the arduino and do the appropriate conversion into a temperature.

Then I convert this temperature into the bits that represent the different sets of lights: the tens, the even degrees, and the odd bit. 

This is then passed to a 74HC595 shift register, which controls all 8 LEDs via only 3 digital out pins on the arduino. 

Given the shift register's outputs and the number of spare digital out pins on the arduino, I could have probably controlled 12 LEDs in total to make it much easier to read - that is, 3 LEDs for the 10's, then one each for the digits 1-9, in which case the temperature from the photos would have been 2x10 + 6. But that seemed like less of a challenge than having to work out how to convert the temperature to the final 8-LED solution. :)

Now back to the bigger challenge: what to build next? :)

On that note, the arduino is quite amazing. Given I have a limited number of components and a rather small breadboard to work with, I have to disassemble everything I build in order to build the next thing. But given most of the work is in planning the design and writing the code (called a sketch), it's fairly easy to rebuild a circuit a second time around. So even though I'll probable disassemble this tomorrow night, all it'd take is a few minutes rewiring, then upload the sketch and it'd be back in action. 

No comments: