Switching Mains Equipment with a Raspberry Pi - Part 1

With some simple hardware and software a Raspberry Pi connected to your home network can be used to switch mains powered equipment (I think this is called line power in the US).

A word of warning - if you are not familiar with the safety and construction practices required when working with mains power then please do not attempt this.  This stuff can bite, sometimes it bites hard enough to kill you (particularly in regions where mains is 220-240VAC) and I don't want to be killing off readers.

 

AC Switching

The design discussed here is not for switching high loads.  

In my case I am switching an electric fence controller and other low current items so used a solid state relay designed for 240VAC switching up to 3A.  If you are in New Zealand or Australia this is available from Jaycar Electronics as SY-4080.  A higher capacity unit is also available as SY-4084.  As the rated capacity goes up so does the price.  If you are interested there is a good article on Wikipedia that talks about the benefits of solid state switching relays over mechanical types for AC switching.  

There is another benefit... the relay can be switched on with any voltage above 3v.  This makes it easy to switch with a 5V logic level and possibly 3V3 as provided on the Pi GPIO header but if you are going to use a buffer on the GPIO pins (which you should) then using one that will give 5V logic levels provides a bit more margin.

 

Interfacing the Solid State Relay to a Raspberry Pi

The solid state relay connects is interfaced to the Pi's GPIO header via a buffer chip.  My design uses GPIO 7, 8, 9 and 10 as outputs to control the solid state relays.  I only have one relay installed at the moment but have designed for expansion.

For a description of the Pi's GPIO header and pin assignments please refer to http://www.raspberrypi-spy.co.uk/2012/06/simple-guide-to-the-rpi-gpio-header-and-pins/.  

5V power is provided to the Pi via the 5V (Pin 2) and VSS (Pin 6) GPIO Header pins.  The power is provided by a recycled external USB hard drive power supply which has 5V and 12V regulated outputs.  Only the 5V is used.

For the buffer I used a 74HCT244 buffer because it was in the junk box.  Alternative parts with small changes to the schematic would be the 74HCT573 or 74HCT245.

If using a 74HCT244

  • The GPIO 7,8,9 and 10 (Pins 26,24,21 and 19) are taken to the 1A0, 1A1, 1A2 and 1A3 inputs of the 74HCT244 buffer.  
  • All unused inputs 2A0, 2A1, 2A2 and 2A3 on the 74HCT244 are tried to ground to prevent oscillation.
  • The 74HCT244 is run at 5V.  The 74HCT is a CMOS device that uses TTL logic levels on it's inputs.  This means that >2V on one of the GPIO pins will be treated as 1 with an output of 5V from the 74HCT244 providing a nice margin above the relays minimum switching voltage. 
  • The /OE1 and /OE2 pins on the 74HCT244 are both tried to ground to enable the outputs.  

I am switching the electric fence with Pi GPIO 7 via 74HCT244 1A0 -> 2A0.  2A0 is connected to the + control input on the solid state relay.  The - control input is grounded.

 

The 74HCT244 buffer, relay(s) and header for the 240VAC mains is assembled on prototype board.  This connects to the Pi via a 20 pin IDC header.

 

The Pi and the recycled power supply are mounted on the inside of the case lid.  

For safety, plastic screws are used to mount the bottom of the original power supply box which then has the PCB held in place with cable ties.  For extra safety I should have left the top on the box but once opened it was impossible to reassemble .  The power supply gets 240VAC from the incoming switched line and can be disconnected and the Pi and interface board run from 5V via the Pi USB connector for "testing".

Coming in Part 2.... The Software

 

 

Powered by Easytagcloud v2.1

Contact Andrew Quinn

jaquinn@ihug.co.nz http://twitter.com/jaquinn