Two Possibilities

January 26, 2011

Homebrew Temperature Controller

Filed under: Projects,Technology — Eric Friedrich @ 4:19 pm
LED Screen

Finished Product

Several months ago I heard some interviews with expert homebrewers advocating for better control of beer fermentation temperatures. The yeast used to ferment beer (producing alcohol and carbonation from sugars), is most effective in a relatively small temperature range. Above that range you may get off-flavors, while below it the beer may not fully ferment. The temperature in my apartments fluctuates quite widely, especially in the winter. We have a programmable thermostat in the apartment to keep it between 60 and 67 degrees, depending on time of day. Most yeasts prefer the 68-72 degree range, disliking temperatures down at 60 degrees. I needed some type of heater to warm my beer up and keep it at a constant temperature. As an added bonus, this project might be able to do double duty as a temperature controller for a sous vide water bath, but that’s another post. You can see the Temperature Controller in the photo to the right. A display shows current temperature of the sensor and what the set point is. The set point is adjusted with a potentiometer knob on the bottom of the box (not visible because of the lighting, but to the left of where the wires enter on the bottom). The “0″ on the bottom right of the display indicates that the relay is currently switched off. When the temperature drops enough, the relay switches on and the display shows a “1″ in that position. You can find links to the source code, schematic, board layout file, and parts list at the bottom of the post. Since there is no good licensing scheme for open sourcing hardware designs, if you use my board layout please at least give me credit.

Sensor

Temperature Probe

Temperature Probe

There are several options for the temperature sensor. The cheapest and easiest solution is using a thermistor, which is basically a resistor that varies its resistance with temperature. The temperature can be calculated by measuring the voltage drop across the resistor. This is how most cheap digital thermometers work. The second option is a thermocouple. Two pieces of different types of metal connected to each other create a voltage related to the temperature difference. These are more accurate, but also more complex to use correctly and require additional hardware. The type I ultimately ended up using is a digital temperature sensor. I already had several samples of the DS1820 Temperature Sensor laying around and had been looking for a reason to use one. It interfaces to the controller with a OneWire bus, only requiring a signal + ground connection. The DS1820 uses parasitic power, essentially powering itself off of the data connection. The Arduino platform already includes libraries for OneWire and DS1820 communications, making interfacing with the sensor a breeze. I wanted the temperature sensor to be waterproof, so I sealed all connections with a few layers of heatshrink and another layer of hot glue on top. High-temp silicone or epoxy may be a better choice as a sealant. Still, the heatshrink + hotglue combo is easier to repair and held up well after a few hours in 65 degree water. My first experiment with the DS1820 was simply measuring the air temperature of my room over the course of 24hrs. I did this quick proof of concept to gain experience working with the OneWire and DallasTemperature libraries and also to see if my room was a suitable temperature for growing a sourdough starter. Sampling the temperature once a second and graphing the results in gnuplot produced the following graph starting from 8AM on 12/16/2010. The temperature in my room varies between 17 and 23C. You can see it cool down during the day as the adjustable thermostat lowers the temperature while the apartment is empty.

Ambient Air Temp December 16, 2010

Controller

The brain of the temperature controller is a based on the Arduino family of microcontrollers. I like Arduino for their ease of use, support in the open source community, and wide range of available libraries. Getting the DS1820 OneWire interface working was a piece of cake, as was the Sparkfun SerLCD. One of the downsides of an Arduino is their price, a single board costs around 30 dollars. This is really meant as a prototyping tool; for a production item it is easy to move the micro-controller off the development board and onto a custom circuit board. This requires only 2 capacitors and a single crystal resonator, bringing the cost of components down from 30 dollars to about 6 dollars. I had never designed my own circuit board before and this project seemed like an ideal time to learn. I settled on Eagle and BatchPCB for board production, mainly on a basis of cost. There is a lead-time of several weeks, but the cost is low enough to justify the wait.

Printed Board

Printed Board

I started by prototyping parts of the circuit with an Arduino Duemilanove and breadboard. The theory behind the relay control portion of the circuit was borrowed from Sparkfun’s Controllable Power Outlet tutorial. I then copied the schematic from the breadboard into EagleCAD’s schematic editor. From there I laid out the components on the board and allowed the Eagle auto-router to do most of the work. I’m thankful for the ability of software to plan all the traces on the board, I do not envy that task. It was at this point in the board layout phase that I should have put some more thought into the final assembly of the system. I made several oversights in my choice of connectors and footprints on the board that detracted from the overall quality of the project. Specifically, I didn’t use the proper footprint for my potentiometer and didn’t adequately plan which connectors I would use to connect the power supply, display and temp sensor to the Arduino.

Populated Circuit Board

Populating the board took a few hours at the soldering iron and another order from Sparkfun for a surface mount switch I had forgotten to order with the rest of the components. Everything fit well except the potentiometer (used the wrong footprint for the part) and the serial/programming screw terminal connection on the bottom right (also used the wrong footprint). Testing the board went surprisingly well. For my first attempt at creating a circuit board, I expected smoke, burnt traces and general mayhem. I started my testing off using a hot-wired PC power supply. Both +12V and Ground were connected from the yellow and black pins of a Molex connector to my the screw terminals with a piece of hookup wire. The first time I powered the circuit up, I was not disappointed as smoke started billowing out of the Molex connector and the smell of molten plastic spread throughout my room. I was convinced my careless board design was at fault here, but further investigation turned up a wiring short inside the Molex connector. Once this was corrected, I was able to power up and continue testing the circuit. I suspect the short also damaged the NPN transistor on the board (seen just below the relay in the picture to the left) Unfortunately, in a rush at RadioShack I accidentally purchased PNP transistors. I was so glad RadioShack still carried transistors and that I didn’t have to pay shipping that I wasn’t very attentive to what I was actually buying. This required a small change in my code, instead of setting the output signal low to activate the relay, setting the signal high now activates the relay.

EagleCad Board Layout

The software for the microcontroller was very simple and compact. Most of the heavy lifting for the sensor and display are done by the OneWire and DallasTemperature libraries and the SoftSerial library respectively. I’ll gloss over most of the details of the driving the display, only saying that it should be updated with a high enough frequency to be responsive to a user turning the potentiometer. The control algorithm is a simple on/off control loop with hysteresis. The user sets the control point using the potentiometer on the circuit board. The potentiometer acts as a voltage divider, increasing or decreasing the voltage seen at the Arduino’s analog input. The Arduino’s Analog to Digital Converter (ADC) converts from a voltage into a 10-bit number. I then map this value into a range between 0 and 100 degrees Celsius.  Simultaneously, the Arduino polls the DS1820 for the current temperature (also in degrees C). If the sensor value is less than the set point minus a predefined tolerance, the relay activates and the heater turns on. Similarly, if the sensor value exceeds the set point by more than a predefined tolerance, the relay is turned off and the system is allowed to cool. This allows for a temperature range of twice the tolerance, centered around the set point. Setting the tolerance too low switches the relay too rapidly, shortening its lifetime. Setting the tolerance too high allows the temperature to vary more than desired. I originally chose 2 degrees C as my tolerance, but this provided a 4C temperature range, too wide for most applications. The tolerance value is now .5 degree C, allowing the temperature to vary only 1C. In a future revision, I would like the ability to control the tolerance without having to re-program the microcontroller. Commercial controllers can heat a water bath with .01C accuracy. This type of on/off control is less precise than a continuous control loop, however binary nature of the relay limits my control algorithm. Using a PID control loop and a triac to control the duty cycle of the A/C power is an alternative solution. This approach is overly complex for my needs, but is behind the control systems of most commercial temperature control products.

Heating Element

The main heating element for my beer fermentation setup is a flexible heat mat wrapped around a carboy. The exact part is a FlexWatt Heat Tape meant for warming reptile cages, but resembles the meant-for-beer FermWrap very closely. The reptile heater was about one third the price. It is not clear yet how warm this will be able to keep the beer, although I shouldn’t need more than few degrees warmth out of it. Assembling the heat tape with the separately provided power connectors took only 5 minutes and a pair of pliers.

Whole Shebang

For a sous vide setup, the heating element is an analog slow cooker set to high. Digital models don’t work because they cannot have their power removed without stopping the cooking cycle. The model I used was able to bring a gallon or two of water up to 65 degrees C within an hour or so. I’ve not yet tested how hot it can possibly get or how well it maintains temperature.

Results:

Board Design

Backside of Board

Backside of Board, note rework with black wire

The main problems with my board revolve around connecting the sensor and power supply to the rest of the circuit. I added screw terminals for the power supply, although I should have used a power jack. Similarly, I added screw terminal connections for the sensor, but only for the Data signal. I thought the ground connection could share with the power supply ground. While possible, its a tight fit in the screw terminal for multiple wires. Especially since my original board design did not take into account using the Serial LCD display. I did not provide a connection for 5V power and needed to do some rework on the board to use a spare screw terminal (seen in the black wire on the underside of the board). Similarly I also needed to connect the LCD with the ground screw terminal already occupied by the power supply and sensor ground connections. This is a very tight fit. Nor did I really provide a connection of any type for the Serial LCD data. I placed a 2-pin header connector on the board for Serial data and in-circuit programming, but used the wrong footprint. I was not able to fit a screw connector into this space. A single wire is soldered into the via on the circuit board and runs to the serial LCD providing it with data. I was not able to get in circuit programming working, but didn’t spend much time on this, opting to switch the Atmega IC back and forth between the Arduino board and my custom circuit board.

Fermentation Setup

Fermentation Setup

Note: You may need to remove the “.txt” extension from the above filenames, WordPress is picky about what filetypes you can upload to it.



7 Comments »

  1. Nice post. I’m glad to see the WIP board shots went to something worthwhile. I don’t have and pcb design exp, but as soon as I read beer heater I thought “lizard cage tape” hah! Next culinary test application: homemade yogurt?

    Comment by doppelson — January 27, 2011 @ 7:41 am

  2. [...] needed to keep the wort warm enough for yeast to ferment it into beer. To solve the problem he built his own fermentation temperature controler using a microprocessor to turn some heating tape on and off. You can see the heating element [...]

    Pingback by Fermentation temperature control - Hack a Day — February 1, 2011 @ 4:31 pm

  3. [...] http://www.twopossibilities.com/2011/01/26/homebrew-temperature-controller/ [...]

    Pingback by OPISO » DIY Temperature control — February 1, 2011 @ 8:19 pm

  4. Very neat, I like it.
    I also like how you describe the PID+triac controller as overly complicated, that’s exactly how i described my Fuzzy Logic + triac controller I made for a similar project. If you want to see my build check it out here

    Comment by HNTE — February 2, 2011 @ 6:42 am

  5. First, thanks for publishing all of this! I’m attempting to reproduce this, maybe even fixing a couple of the problems you outlined with the board design. I do have a couple of questions. Is there any particular reason you used an lm317 instead of an lm7805? Also, it seems like you should be able to draw power directly from the ac input before it goes to the relay. Right?

    Comment by phro — March 9, 2011 @ 5:05 pm

  6. No particular reason for the LM317, I just happened to have some lying around my parts bin. I considered drawing power from AC, but it was just cheaper (in terms of board/component cost) and easier for me to use an AC power brick I had laying around. It would be easy enough to add a transformer, some diodes and capacitors though. My biggest suggestion is to figure out which connectors you will use during board design. I kept putting it off and thats one of the areas of the project I am most unhappy with. Feel free to drop me a line with any other questions. Good luck and let me know how it goes

    Comment by Eric Friedrich — March 10, 2011 @ 10:54 am

  7. I did some reading of the sparkfun controllable power outlet tutorial, and there were comments stating that the traces on the PCB can only handle 5.5 Amps. I did some more research, and it looks to me as though they should be able to carry about 7.5A. Have you measured the draw on the flexwatt heat tape? It seems like it might be a good idea to throw a fuse into the design.

    I’m also wondering how you managed to drive the LCD with only one data line. I think I’m going to put a 16 pin female header on the board to connect the LCD. Also, you didn’t add a backlight control as far as I can tell. How did you manage to set the backlight to an appropriate level? I’m not nitpicking the design, I’m just trying to make sure I get things right. ;-)

    Comment by phro — March 15, 2011 @ 6:59 am

RSS feed for comments on this post. TrackBack URL

Leave a comment

You must be logged in to post a comment.

Powered by WordPress