NetBSD Beer Fridge

"That's nerdy... really nerdy... but it's beer."


Current Status updated every two minutes.
Temperature Graph courtesy of Steve Middlekauf.
OS X Widget coming soon, I've heard.

My friends and I brew beer.  Our last two attempts have been less than perfect due to improper fermentation temperature.  The first was too cold, resulting in diacetyl (buttered popcorn) off-flavors.  The second was too warm, resulting in an overpowering excess of fusel alcohols.   Both suffered from a lack of web-presence during fermentation.

In an effort to remedy these flaws in our subsequent brews, I built and programmed Der BrewMeister 0xF-Thousand.  The system takes a detailed fermentation schedule and controls the temperature of the fermenting beer accordingly.  The beer status is updated on the web every two minutes, allowing us, or anyone else, to monitor the development of our creations.

Hardware

The system consists of a fridge, a light bulb, a computer, and a project box with hardware for sensing and controlling everything.  There are two Dallas DS18S20 temperature sensors mounted inside the fridge; one for the wort and one for the ambient air.  They are connected to the end of the blue ethernet cables via crimp-on butt connectors.  I got the fridge from craig's list.  It had a former life as a "kegerator" beer tap, where the previous owners drilled a hole in the back to accommodate a CO2 hose.  Coincidentally, the hole is a perfect entry point for the two cat-5 cables.  There was also a hole in the front, which I filled with styrofoam. When the light inside turns on, it looks like a glowing eyeball.



The contents of the project box can be seen below.  The larger board is a set of relays connected to the computer via the parallel port.  The smaller one reads the temperature data from the sensors and is connected through the serial port.  Both are available from qkits.com as item numbers QK74 and VK011, respectively.  There is a third sensor connected directly to the board inside the box.  I originally stuck it in there because I wanted to know if the box was heating up.  I left it in to measure the room temperature in my basement, for all the web to see.

Power to the fridge and light bulb are provided by an extension cord that has been dissected and rerouted through the relays.  It's an adaptation of the A/C wiring in Eric J. Wilhelm's Haunted House Controller in Make Magazine Vol. 3.



Software

The main software component is the BrewMeister daemon.  It follows a user provided schedule of fermentation stages and controls the temperature accordingly.  A user can send the daemon a few simple commands using the BAdmin utility, which communicates with it via a unix domain socket.  That is usually only necessary to query the status, or when a particular stage is configured to last until the user indicates that it's over, such as when the daemon is waiting for wort to be physically transferred between fermenters.  Otherwise, the schedule is all the information it needs.

The computer itself is hidden behind my firewall because I don't want anyone from the internet messing with something that is actually physically controlling things in my house.  The outside world's view of the current beer status is provided by a cron script that updates the static page every 2 minutes.

I'll probably put the code up here after I clean up some of the kludgiest parts.  But be forewarned, it handles things like IPC user credentials and parallel port output in ways that I think are very specific to NetBSD.  It might not even compile on anything else, but who knows?  I haven't tried it.

Control Algorithm

Based on a particular stage configuration, the daemon will either control the ambient air temperature, or the wort using the ambient.  Controlling the ambient alone seems simple enough - just turn on the heat/cold until the temperature is correct, right? Nope!

That generally works for heating because when the light turns off it stops producing heat.  Cooling, on the other hand, is complicated by the fact that when the fridge is turned off, the cooling coils are still cold, and are going to continue to absorb heat from the air.  In my first attempt to cool the air 5 degrees, I turned on the fridge until the temperature had dropped from 67 to 62, then turned the fridge off.  About 10 minutes later the temperature was down to 48!  Through some experimentation I determined that, for this fridge, the temperature would end up close to the target if it's turned on one minute for each degree the temperature needs to drop and then turned off for 5 minutes.  This has worked reasonably well so far.

If the wort was just water, controlling it would be as simple as keeping the ambient air at the wort's target temperature.  Eventually, everything in the fridge would be the same.  The big difference is that the wort has live metabolic activity going on, which is constantly pumping heat into the system.  BrewMeister deals with this by starting with the ambient temperature controlled at the wort target.  Once the ambient has been stable for 20 minutes, it finds the difference between the wort and its target.  The ambient target is then adjusted by that amount and the cycle begins again.

I know I should have dusted off my old Diff Eq book to find some elegant solution, but this algorithm actually works surprisingly well.  The wort is usually within half a degree of the target, and the heat or cold only turns on about once every 1.5 hours.  It can sometimes overshoot by a bit when cooling, but not when heating, so oscillating between the two has never been a problem.

I think that's all for now...

E-mail me: paul at monkey dot org