Digital bar fridge thermostat
Sitting around one warm summer's night drinking some excellent homebrew beer with some mates, we had been playing around with the idea of building a kegerator-type thing to serve ice cold beer on demand.
We thought that an Esky, some copper piping and valve attachments along with some ice would probably be all it'd take, however after looking online at reasonably sized cooler boxes we noticed the cost was prohibitive (at least, when you're on a student's budget).
So the project took a back seat, until a few weeks later driving home from a party late one Saturday night we saw a bar fridge on the side of the road. I immediately thought that it'd be a perfect substitute for the cooler box in our project, and with a bit of shuffling, the solution to our problem was in the car!
However, it was the next morning that we discovered that unfortunately, the fridge actually worked... Unwilling to dismantle a perfectly working bar fridge, we re-targeted our project. Not too long ago we'd brewed a James Squire Golden Ale imitation, which had been exposed to some unsavoury weather conditions (read: Australian summer) and could have probably been better if it hadn't spent time at 45-50 degrees Celcius. A fridge would have been a good solution to this problem!
However, the built-in thermostat would only allow the fridge to go up to a maximum of 5 degrees... hardly an ideal beer brewing temperature. After looking online for replacement thermostats and finding them both hard to come by, and quite expensive, I decided to design my own.
I needed something that could switch the compressor of the fridge on and off depending on the temperature inside the fridge. Switching mains power on and off meant that I'd need a relay, and I remembered seeing a good tutorial over at Sparkfun explaining the ins and outs of what is needed. For more information I highly recommend reading the article.
I wanted the thermostat to conform to a couple design requirements:
- Have a simple, small design
- Be reasonably power efficient
- Have an adjustable temperature setting
Power
I needed to solve the problem of how to power the thermostat. I could have designed an AC-DC rectifier and piggy-backed the power from the fridge itself. This method would have also required a DC-DC step down converter, but it would have significantly increased the number of parts that I needed to build the overall project, increasing the complexity and physical size of the overall device.
One alternative was to use a battery pack and a 7805 linear voltage regulator to supply a nice 5V to the rest of the system. This certainly fulfilled the criterion of being small and simple, but it wasn't without its caveats. Firstly a 4xAA battery pack only delivers ~6V, and a 7805 LVR technically requires at least 7.2V to produce a 5V output according to the datasheet. The other issue is that the batteries will run out eventually and will have to be replaced. The first problem proved to be a non-issue as the 7805 still pumped out 4.88V from a 6V supply, probably enough for most ICs. I decided that this would be a fine solution, despite the flaws.
Temperature controlled switching
So that solved the problem of power, and the actual turning on and off of the fridge, but I still needed some kind of device which would be able to send a signal to the relay setup when the temperature exceeded a preset amount.
I opted to use a thermistor for temperature detection. These things are basically resistors which change resistance depending on the ambient temperature, in my design I chose to use a 10k NTC thermistor. This means that the resistance at 25 degrees Celcius would be 10 kOhms, and decrease in resistance as it got hotter. From the datasheet of the component I found that at 18 degrees the resistance would be approximately 13 kOhms. In retrospect, I feel that I should have purchased a 50kOhm thermistor, as this would have reduced the current flowing through it and lowered the overall power consumption.
I used the thermistor in conjunction with another resistor to create a simple voltage divider network, to give a varying voltage depending on the ambient temperature. That voltage could then be measured by some IC and compared to a reference voltage. My first thought was that a comparator would be an elegant solution, however after ordering a low-power comparator I found that it required a 2V difference between the two inputs for it to switch. This was completely impractical as a 2V difference translated to a 47 degree temperature change. So this ruled out the comparator, and instead I ordered a ATTiny25 Atmel microcontroller, which has a couple of ADC ports which can read the voltage on any of the ADC pins to an accuracy of 10 bits. This meant that I needed to write some firmware for the AVR to do the comparison but being reasonably familiar with the process this didn't really bother me.
So putting all this together got me a circuit that looked something like this:
Hardware
Materials:
- 7805 Linear voltage regulator ($0.25 Futurlec)
- ATTiny25 Atmel microcontroller ($1.40 Futurlec)
- 50k trimpot ($0.15 Futurlec)
- 10k NTC thermistor ($0.35 Futurlec)
- Solid state relay ($4.95-$24.90 Futurlec)
- 4xAA battery holder ($0.40 Futurlec)
All up this comes to around $15-20 USD including relay and postage.
Software
The firmware compares the voltage at the thermistor/resistor network with the potentiometer output, switching the relay accordingly. Key features: ADC interrupts to sleep the processor between samples (power saving), and hysteresis to avoid rapidly cycling the relay compressor.
The thermostat has been installed in the fridge and sits at a pretty constant 18 degrees. The current draw while the relay is active is 80uA, giving an estimated battery life of over two years from a set of AAs.
If anyone has any questions feel free to drop me a line at [email protected].