Skip to content

Arduino Beer Thermostat


Sean shows us how to use an Arduino for kegerator temperature control. A Kegerator is a beer keg built inside a refrigerator. Anyone want a cold beer? He discusses the home brewing process and how a microcontroller can be applied to this and many other sensing and control task. Man I’m thirsty now…

This article was submitted by Sean Coates as part of the “Hobby parts for articles” program. Sean received a 120 LED Assortment from Alan’s Electronics Projects for this great article.

I belong to a diverse group of amateurs who have a fascination for brewing our own beer. In addition to the satisfaction of brewing the beer I drink, and the control I have over the process (and the ability to easily avoid crappy mega-swill beer from the big breweries), we homebrewers get to play with a bunch of cool gadgets. Even if you don’t have any interest in cooling beer, this information in this tutorial can be applied to other projects that involve analog sensors, and high-voltage/current devices.

Over the past few months, I’ve started kegging my own beer, at home. This is a pretty simple process, but one of the key ingredients to making consumable draught beer is temperature control. Obviously, beer doesn’t taste quite as good if it’s warm (or too cold, for that matter), but there’s more to it: carbon dioxide is much more soluble in water (or beer) at lower temperatures, so it’s essential that kegs be kept cold, when serving.

Most homebrewers take one of three approaches to cooling their beer: buying a pre-made kegerator, gutting a regular refrigerator to hold kegs with taps on the door, or altering a chest freezer to hold the kegs and mount taps. I chose to take the third approach (a friend was getting rid of a near-perfect sized chest freezer).

Generally, chest freezers have thermostats that work in the “freezer” range. That is, below 0ºC, or below water’s freezing point. Even at the “warmest” temperature, most freezers will still freeze beer. This is no good when it comes to kegerators. Many homebrewers solve this problem with a device referred to as a “Johnson,” “Love,” or “Ranco” controller (depending on the brand of controller). Basically, this device plugs between the AC mains and the chest freezer, and has a temperature probe that is placed in the freezer (the freezer’s internal thermostat is set at “maximum cold”). The temperature probe, depending on the model chosen, will either be a solid/liquid mechanical probe (usually found on the cheaper controllers–this is likely the same type as is found on the freezer’s internal controller), or a thermistor.

One day, a few weeks ago, I had the urge to finally get my chest kegerator cooling my beer. Living in Canada has its benefits, but one of the recurring problems we Canadians face is the difficulty (and delay) in having items shipped from the US (where most of these controllers are made/sold). I wanted to get it working now, not in a week, or more, when a controller would arrive. Additionally, these controllers can run for anywhere from $60-200. I didn’t feel like waiting, and I didn’t feel like paying. So, what’s a resourceful geek supposed to do? Build your own, of course.

The first thing I did was figure out what components I would need to build my own controller:

  • a microcontroller (I had an Arduino NG that I hadn’t embedded in anything, yet–perfect)
  • a thermistor (I happened to have some that I picked up from my local electronics shop for $1 each. They’re marked 1K, which usually indicates the resistance at room temperature, or somewhere around 20ºC)
  • some resistors to create a voltage divider to interface with the thermistor
  • a solid state relay (SSR) (again, I happened to have one on hand that I got from my local electronics shop for $5. Check eBay, there are plenty of good ones available for good prices). You need to make sure that the SSR can handle the current that your freezer will draw, both when the compressor fires up and draws extra current, and also when it runs at a lower current for longer periods of time.


I built my first prototype on a breadboard, shown above. The circuit for this is pretty simple: on the analog side is +5V, resistance, and analog line, a thermistor and ground. This is best explained by a schematic diagram, shown below.

Let’s go through the components listed above. First is the microcontroller. Hopefully everyone reading this site has heard of the Arduino, but in case you haven’t, it’s a simple microcontroller that has a number of analog inputs and digital input/output pins. For this project, we’ll be using one analog pin, one digital pin (in output mode), and the 5v/ground power bus, as well as some code that we’ll discuss a bit later.

Thermistors are variable resistors, like photo-resistors or potentiometers. Instead of detecting light or some sort of manual adjustment, however, the resistance in a thermistor changes depending on the component’s temperature. My particular thermistors have a range of approximately 0C-100ºC, where 0ºC gives a resistance of near 2K, and around 0 Ohm at 100ºC (as measured with an analog thermometer). Below 0ºC and above 100ºC, the thermistor reads closed (no conductivity, or infinite ohms). Yours might be different, so you’ll have to adjust your code and voltage divider if it is.

Basically, the voltage divider part of the circuit translates a resistance (the variable resistance of our thermistor, in this case) into a voltage that can be read on the analog pin of our microcontroller. This allows us to detect the thermistor’s temperature, and convert the analog signal to a digital value.

The solid state relay is an interesting device. It’s a bit like a conventional relay, where a secondary circuit (power to our freezer, in this case) can be completed by the primary circuit (our Arduino’s digital output), in a completely decoupled manner. This is usually done via a LED and a photo-diode plus a MOSFET. In practice, there are four poles: two for the high-voltage/high-current/AC circuit and 2 for the low voltage DC circuit. To trigger the SSR, you simply apply +5v (you need to get a relay that will trigger at 5v) and ground to the low voltage side (polarity matters, this is a LED, remember), and it will bridge the high voltage poles, to complete that circuit, and turn on the freezer.

As you saw in the schematic, this circuit is pretty simple. You can get a copy of the code here.

The code is a bit more complicated. I’m a programmer by trade. I don’t usually deal with C, but it’s similar to my development language of choice: PHP. I chose to implement my controller in such a way that would allow modularity. For example, I can plug in different thermistor/divider circuits, and all I need to do is add a new Therm structure. As you can see in the attached code, I also have a ”Fermenter” controller which, while a bit different, is essentially a copy of the circuit discussed here.

Stepping through the code, the first thing you’ll notice is a number of #define directives to set up some constants. I use these later, mostly to keep track of the state of my controller. You’ll see “struct’s” for both the Thermistor and the Controller objects.

Next is the Arduino’s setup()method. This is initialization code that is run once per execution of the sketch (program) to initialize different bits of data. Here is where we designate the digital pins as OUTPUT , initialize the Serial port (which we’ll use via USB to capture data), and set up the Thermistor and Freezer object parameters.

Without getting into too much detail on these values, the Thermistor base values are calculated, based on real-world data that I captured with a hotplate and a thermometer. I didn’t have the datasheet for my thermistors, so if you happen to be able to pull that data, you’re much better off and can skip the tedious manual testing. I determined the 0ºC value of my thermistor ThermB to be 22500, with per-degree steps of 10.2 (or 102 with the 10x factor I needed to get around Arduino’s poor floating-point performance). Note: most thermistors are not linear like this. Either I got lucky, or my measured range was so small that I didn’t have to resort to logarithmic calculations. This works out well for me, but you’ll need to measure and/or check your own datasheet.

Now that we’re set up properly, the Arduino runs the code within the loop()function, indefinitely. Here’s where we actually measure the current thermistor’s value (checkTemp()), optionally toggle() the freezer’s power to the compressor circuit, increment the Freezer’s state timer (mostly for debugging–turning a compressor on and off too quickly is a surefire way to reduce the life of your freezer), and output the data to our initialized Serial port. Then, the processor is instructed to delay() for 1000 ms (you could change this value if you like).

The other functions facilitate the above behavior by determining when to toggle the compressor’s power state, formatting output, and calculating the temperature.

That’s pretty much all there is to the firmware code. I managed to create a powerful, customizable temperature controller, all with parts I happened to have (mostly) laying around my workbench. The most expensive part is obviously the Arduino, but it’s still cheaper than a dedicated controller.


Here is a photo of my current controller in action. The circuit described here is on the right half of the board (I also have a fermentation controller, which you may have noticed in the code listing). Up-to-the-minute temperature logging of my controller can be found here.

I’m happy to answer any questions readers might have; feel free to send them my way… hopefully I’ll be able to help.

Author bio:
Sean Coates has been coding since he was very young, and has been doing so professionally for the past 9 years. He is the Editor-in-Chief of php|architect Magazine, and enjoys tinkering with microcontroller code and electronics in amateur capacity. He lives in Montreal with his wife and daughter, and you can contact him at sean[at]caedmon[.]net.

Posted in Arduino, Microcontroller, Projects.

18 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. kumar says

    pid tempurature control

  2. Rajnikumar says

    First intro of me my self Rajnikumar & i am a Electronic Engineer. I have need the PID Tempreture Controller Full Information. Please Give me a details of PID Tempreture Controller give me a full Circuit diagram with working details and Programming code if it is on ‘C’language Programming posible.Alos, i have to need the full Equatation of PID Tempreture Controller.

    Please Give me for Project help & I have to wait for positive Reply……

  3. Sean Coates says

    I’ve update the software/hardware significantly. Details here:


  4. T-Mac says

    Hi everybody…
    I read this contest what you done, and I want to ask you…
    Do you have C code for digital PID regulator. I must make digital PID regulator on PIC16f877A…
    If anybody have it, please send it to me…


  5. Sam says

    First of all — this is pretty cool Sean. I have been looking for a way to control the temp on my “new” but very used refrigerator. I was going to buy an in-line thermostat, but also wanted to monitor the accuracy of the control… So then I was looking at getting a thermostat AND a weather station that I could use to monitor the control… But at a total cost of well over $100 I don’t think my wife would let me. I am kind of new to electrical stuff but I think that I might be able to handle this with all of your advice (not to mention the code — I’m definately not a programmer)

    In response to Russ (response number 8) — I don’t see a need to use PID control to get more precise control of the fermentation temperature. Not that accurate control of the temperature is not important — I just think that the on/off control of the refrigeration is plenty good. Based on Sean’s control chart he has about +/- 1 degree C over a 1 hour period (or about +/- 2 degree F). (I am assuming that this is the air temp) The thermal mass of the fermenting beer (most likely 5 gallons) is enormous. I would bet that the temperature of the beer changes minimally. The extremely poor heat transfer coefficient between the beer and the air in the freezer will also contribute to a more constant temperature. Also, as far as thermistor accuracy goes — I don’t see why you would need more accuracy than +/- 0.2 degree C (which is the accuracy of a low quality thermistor). I am kind of new to home brewing — but I will give you props if you can tell the difference between a beer fermented at 53.0 degF rather than 52.8 degF.

  6. Sean Coates says

    Dale, thanks!

    1) I use a custom PHP script + RRDTool. If you want the source, I can share, but it’s some of my ugliest code ever (-:

    2) sure, you COULD set it up with a relay and only control the fridge side, but it’s _much_ easier to do it with a power toggle.


  7. Dale says

    Nice setups!

    1) How are you logging the historical data? From the Arduino sites I see that it interacts with a telnet type window. How are you saving it to a file?
    2) These setups seems to toggle the power to the cooling unit. Is there a way to set it up to complete the on-off circuit to emulate the thermostat? I’m looking at a side-by-side fridge and want to keep the freezer going as a real freezer.


  8. Sean Coates says

    @Rich: I’m considering something with the Quantum QT Prox sensor, but I’ve had no time )-:

    @Andrew: Thanks! I just found a cheap SSR at my local electronics shop. I’ve seen higher-rated ones that I intend to use for my boil kettle on eBay, though. It doesn’t get hot, and it handles 20A peak, but really only drives

  9. Andrew says

    Nice work! I’m curious as to what SSR you used? I have been looking for one that would work with the Arduino and handle > 3A @ 120V. All I have found so far is $40-50 range. Does it get hot and how many Amps is it handling? Thanks

  10. Rich says

    I have something similar at home I made years ago. I also wanted to measure the amount of liquid dispensed or the amount of liquid in the keg so I have some kind of idea when it needs to be refilled. Not sure how to go about this. Do you have any ideas?


  11. Russ says

    That’s some good work, mate. Although you didn’t mention keeping the temperature at the right level during the actual brewing people should know that is just as important in terms of repeatability. To brew my beer (I don’t have kegs to drink from, just bottles) I use a Eurotherm 3216 digital PID controller. Quite expensive, but can easily be shifted around to my other projects, making it highly worthwhile. This unit has two outputs (and self-tuning PID loops software), so you can control temp much more tightly. I use output 1 (with a SSR) to control a waterbed heater to warm the brew and am going to use output 2 to operate a solenoid for a cooling coil soon.
    You can also use RTDs with the Eurotherm, giving even more accuracy than K-type thermocouples or thermistors. Could you not implement a PID loop program for the Arduino?

  12. Sean Coates says

    Isn’t the Arduino using the same 5v for reference that it supplies on the +5v pin?
    If so, I don’t see how it would affect the digital reading.

    I could easily be wrong, though (-:


  13. dfowler says


    Bob brings up a good point. Changes in the 5V supply would directly effect the A/D readings. But I think you are fine if you use a regulator from the 12V supply. The variation on the regulated 5V should be small compaired to the swing for a degree keeping the error low.

  14. Sean Coates says

    Bob: thanks for the comment. I’m using an old PC power supply as my 12v in (to the Arduino). The Arduino is providing the 5v, and that should be properly regulated, no?

    If not, do I need another component on the 5v line?


  15. Bob says

    Just a thought. It looks like the the 5V should be well controlled or else variation in that supply would show up in the voltage divider signal going to the analog input. If the temperature coefficient of the thermistor is relatively large then it is probably ok – just a word of caution if there are differences from one set up to the next.

  16. Sean Coates says

    Jason: I’d planned to build a peltier-cooled fermentation chamber. My peltiers weren’t strong enough to handle it by convection. Then I was building a peltier-powered swamp bucket ( but I gave up on that one when a friend dropped off a spare refrigerator. So now my fermenter is controlled by the 2nd SSR you see in the photo, and it’s just a regular fridge.


  17. Jason says

    So what type of temperature control are you using for you fermenter?

  18. wytten says

    Years ago the “Hunter AirStat” was an off-the-shelf product that homebrewers preferred for this task, but I don’t know if it is still available.