Homebrewing with the PiSoC

In this project I use the PiSoC to control the temperature of my fridge. This is needed for fermenting lager at 55 degrees Fahrenheit, which is well above the temperature a fridge would normally run at. This is accomplished by monitoring the temperature inside the fridge, and then using a relay to switch the fridge off when the temperature drops below our threshold. Because we are dealing with AC power this project gets a lot closer to home automation territory, and could certainly be modified for controlling other household appliances.

NOTE: This project will have you working with dangerous AC line voltages which can hurt or even kill you (or your fridge) if you don’t work with it safely. If you aren’t already comfortable working with line voltage do not attempt this project. I am not responsible for any damage caused by attempting this project.

fridge_small

Don’t leave anything that can spoil in a 55 degree fridge!

I cheat a little bit by putting the PiSoC itself into the fridge, and then measuring the PSoC’s die temperature. I could have used a thermocouple so I could put the display outside of the fridge, or even hooked it up to the internet. This is fast, simple, and cheap though, just what you need for making beer.

Setup

You’ll have to buy a few things for this project:

  • AC Relay board – I got one from Aliexpress but you can use something like this from Amazon. You’ll want to get one with an optocoupler so there’s no chance of baking your PiSoC. You can use this board to switch on and off any appliance that uses AC power.
  • Extension Cord – You’ll be modifying an off-the-shelf extension cord so you can plug your your fridge into the relay without messing with the fridge’s cord.
  • LCD Screen – I used this color lcd touch screen from adafruit. We ported the adafruit library so you can write text, draw shapes, and use the touch screen with virtual buttons. This project doesn’t really make much use of most of those features, so you could buy a simple 2-line lcd like this instead. PSoC Creator has a built-in component and example code for lcds that use that HD44780 chip.

PSoC Creator Code

The code for this project is pretty straight forward. We measure the PSoC’s core temperature once every few minutes, making the assumption that the core temp will be roughly the same as the fridge’s temperature.

We then use a very basic control loop called Bang-bang control. We simply check the temperature every few minutes and say if its 1 degree Celsius or higher than the desired temperature, turn the fridge (switch the relay) on. If the fridge is not at least 1 degree Celsius higher than desired, turn the fridge off. This is basically how thermostats work in a lot of homes, constantly hovering around the desired temperature.

In retrospect I probably should have made the temperature threshold a little higher, or checked the temperature less often, as the fridge switched on and off a little more than I liked. These are both easy variables to change in the PSoC Creator project, and I’ll show you how to do that below.

Here’s the code – Download it and program your PiSoC with it.

The relay needs to get hooked up to pin P4.0 on the PiSoC. The PiSoC needs usb power that can come from a phone charger or portable phone charger battery. No need to hook it up to the computer once programmed.

If you want to change anything the two main files you will want to look at are “TopDesign” and “Main.c”

TopDesign shows the overall schematic. Each piece in there is called a PSoC Component, and are basically libraries for using specific pieces of hardware. Double-click on the “Timer_1” component. This is where we set how often to check our PSoC temperature, and therefore how often the fridge could potentially switch on or off. You can see the period has been set to 15000 counts which correlates to a 300 second (5 minute) periodYou can change that to whatever you want. 10 or 15 minutes would probably be appropriate.

topdes

PSoC Creator Schematic

Main.c  contains all the code. Here we check if the temperature has gotten too high. If it has, we switch the fridge on. You can set your desired temperature in Celsius  on line 17 near the top. You can also set your temperature threshold on line 166. By default its set to turn the fridge on if current temperature is greater than desired temperature. This means if the temperature is even 1 degree higher than desired, the fridge switches on.

You could change line 166 to read “if(temperature > desired_temp + 1)”

This would set it so that the fridge only switches on when the current temperature is 2 degrees higher than desired. This should stop the fridge from cycling on and off too often.

Play with your values until you are happy with how the temperature control and fridge are performing. Good luck and happy brewing!

-Robert

Leave a Reply

Your email address will not be published.

Published on: 30 October 2015
Posted by: Robert Barron
Discussion: Leave a comment