thermostat3


Fridge thermostat - Building

Page 1 | 2 | 3 | 4

Hardware

Materials:

  • 7805 Linear voltage regulator ($0.25 Futurlec)
  • 8-pin IC socket ($0.04 Futurlec)
  • Atmel ATTiny25 microcontroller ($1.40 Futurlec)
  • 50k trimpot ($0.15 Futurlec)
  • 0.1uF ceramic capacitor ($0.10 Futurlec)
  • 47uF electrolytic capacitor ($0.07 Futurlec)
  • 10k NTC thermistor (alt. 50k NTC thermistor) ($0.35 Futurlec)
  • 10k Ohm resistor (alt. 50kOhm resistor) ($0.20 Futurlec)
  • 1k Ohm resistor ($0.20 Futurlec)
  • 1N4001 general purpose diode ($0.20 Futurlec)
  • MPS2222A general purpose NPN transistor ($0.50 Futurlec)
  • Solid state relay (Current rating depends on device being switched) ($4.95-$24.90 Futurlec)
  • 2 terminal 5mm spaced terminal block (optional) ($0.40 Futurlec)
  • 4xAA battery holder ($0.40 Futurlec)
  • 9V battery clip ($0.10 Futurlec)
  • Small stripboard ($0.95 Futurlec)

All up this comes to $5.31, plus the cost of your relay, plus a few extra dollars for postage, you should be looking at a total cost of $15-20. (All prices are USD)

Alternatively you could omit the stripboard and go about making or ordering a PCB, using the eagle BRD files that I've included on the final page. Keep in mind however that while I assume it will work, I haven't actually produced a PCB from the design, so anything could happen. 

Solder it all up together, and you should have something that looks along the lines of this:

Notice that the thermistor has been mounted high off the stripboard, this is just to minimise the effect of any ambient heat that is being generated by either the AVR or the transistor.

You might notice I've omitted the 0.1uF decoupling capacitor in this photo, which is a bit of a no-no especially in an environment where a load is being switched - but rest assured it's been placed in just next to the AVR now.

Software

So now that the hardware side of things is all worked out it's time to get started on programming the ATTiny. 

It will be serving a pretty basic purpose, compare the voltage at pin 7 (thermistor/resistor network) with the voltage at pin 2 (potentiometer output), then determine whether to switch the transistor on or not based on the values of the two ADC inputs. I won't go into too much detail about the code, as it's commented, but I'll mention a couple of points of interest.

Firstly, the use of interrupts. By using interrupts for the ADC reading, it allows the processor to go to sleep while waiting for the ADC to finish it's conversion reducing the amount of power consumed by the AVR in this period. I have also set the frequency of the ADC to the lowest possible setting, as it doesn't really need to be taking samples too often, which reduces the power used by the ADC, as well as increasing the time the processor spends asleep.

Secondly, you'll notice that I mention hysteresis in the code. Wikipedia has a good article on hysteresis, but in essence it is where a difference between the "switch-on" threshold and the "switch-off" threshold. The reason that I've put this in here is to avoid rapidly turning the relay on and off which would put the compressor of the fridge under a bit of stress.

Once the code is written and built, the firmware needs to be flashed to the device itself. For this I used avrdude, a great little program which can send the neccessary data to a AVR programmer. The AVR programmer I use is ladyada's fantastic USBtinyISP. It can be purchased in kit form from her website. You can use any other programmer, but remember to edit the Makefile in the source to reflect the changes.

Page 1 | 2 | 3 | 4