Please read and remember the following warnings before using the RELAYplate:
- Every RELAYplate has a small shield on the bottom that protects the user from potentially high voltages. This shield is held on by five screws. DO NOT REMOVE THIS SHIELD. Doing so will expose you, and the rest of your circuitry to potentially lethal voltage levels. Tighten the screws if they appear to be loose.
- The RELAYplate has been designed to keep both the user and the user’s electronics safe from high voltages in the event of a single point failure. DO NOT ATTEMPT TO MODIFY ANY OF THE CIRCUITRY ON THE RELAYplate. Doing so will expose you, and the rest of your circuitry to potentially lethal voltage levels.
- Whenever attaching wires and loads to the RELAYplate, ENSURE THAT ALL POWER IS OFF. Do not attempt to attach live wires to the RELAYplate. Doing so will expose you, and the rest of your circuitry to potentially lethal voltage levels.
- When preparing a wire for use with a terminal block on the RELAYplate:
- Never use a wire gauge greater than 14 or less than 22. Exceeding these limits can expose you, and the rest of your circuitry to potentially lethal voltage levels.
- Strip off no more than 6 to 8mm (1/4″ to 1/3″) of insulation off the end of the wire that will attach to the RELAYplate.
- If the wire is stranded, “tin” it with solder after you have stripped it to ensure that no strands can become exposed after insertion
- Whenever pushing wires into the terminal blocks on the REALYplate, make sure that the insulation completely covers the wire and that no wire is exposed after insertion.
- If you are using stranded or a small gauge of wire it will be necessary to push the button on the terminal block as you slide the stripped end of the wire end. Once it is completely inserted, release the button to lock it in place. Then, do a pull test to ensure that the connection is secure.
- Whenever you are about to power your circuit, inspect your connections and ensure that no wire is exposed on the terminal blocks. Also make sure that the wires and terminals on your load are also protected.
- Do not exceed an AC voltage of 120VAC or a current greater than 1 amp.
- Do not exceed a DC voltage of 30VDC or a current greater than 1 amps.
- Be smart and keep children away from your work area while using or setting up your RELAYplate project
- Be even smarter and don’t let a child use or touch a RELAYplate once you have installed it in your project.
OK, if all those warnings didn’t scare you off then let’s learn about how to use your new RELAYplate.
What is a Relay?
Simply put, a relay is an electromechanical device that allows a high power load to be controlled with a low power circuit. The images below show a cross section of a relay very similar to what is on the RELAYplate. The first image shows the relay when the coil is deactivated. In this situation, the armature is pulled up by the spring placing the common terminal in contact with the normally closed terminal. Due to space constraints, the normally closed terminal is not used on the RELAYplate.
When a small voltage is applied to the coil, the current produces a magnetic field in the core which pulls down the armature. When this happens, the common terminal comes in contact with the normally open terminal.
Below is a photograph that shows these components in an actual relay.
Basic Features of the RELAYplate
Shown below are the major features of the RELAYplate. The two most obvious sets of features are the seven relays and the seven screwless terminal blocks. There are also seven LEDs labeled K1 through K7 which indicate to the user which relays are in the “on” state.
Unique to the relay plate is a combination of features that were added for safety. These include:
- The slots in the board. These provide an isolation barrier between the low voltage side of the board and the high energy side of the board.
- A small power supply that provides isolated power for the relay coils
- The small “shield” on the bottom of the RELAYplate that prevents the user from accidentally coming into contact with potentially hazardous voltages.
- A small area covered with yellow electrical tape. Under normal circumstances the traces under this tape are safe. However, in the event of a single point failure, these traces could become hazardous. So, DO NOT REMOVE THIS TAPE.
Relay coils require a substantial amount of power and if you only have a single RELAYplate connected to your Raspberry Pi then there should be enough power available to drive your board. However, your RPi power supply may not have enough power to drive more than a single RELAYplate. In the event that you need two or more RELAYplates on your stack of Pi-Plates, there are two different auxiliary power inputs available. Selecting and using these is discussed below.
Finally there are the features common to every Pi-Plate:
- The address header which allows you to stack up to eight RELAYplates on your stack
- A single programmable LED. A turn on this LED is turned on but its state can be controlled in software.
- An onboard microprocessor that controls each relay while interfacing to the Raspberry Pi.
Attaching a Load to the RELAYplate
Think of a relay as a programmable switch. As you know, a switch is a device that controls the power reaching a load. The load can be something like a heater, a light bulb, a motor, or an alarm. The power can be the AC coming from your wall socket or DC from a lead acid battery. By convention, the “hot” wire is the side of the power connection that is usually switched. For AC the hot wire is referred to as “line” while for DC this would be the positive terminal of a battery or power supply.Traditionally, relays have reference designators that start with the letter K. This can be seen in how we labelled the terminal blocks associated with K1 through K7 in the image below:
Below is a simple schematic of a lightbulb connected to an AC plug through relay K3 on the RELAYplate. Note that the line or “hot” wire is routed from the plug to one side of the terminal block for the K3 relay. Connecting loads this way reduces the exposure of potentially lethal voltages to the users.
Once you have made these connections and verified that the wires are securely and safely attached to the terminal blocks, plug the power connector into a wall socket and enter the following commands:
pi@Jessie2:~ $ python
Python 2.7.9 (default, Mar 8 2015, 00:52:26)
[GCC 4.9.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import piplates.RELAYplate as RELAY
- In the first line we are launching the Python command line environment. Note that with the Jessie Raspian distribution, it’s no longer necessary to precede the Python command with the “sudo” directive.
- After Python launches, we eventually get the familiar triple chevron. The next step is to load the RELAYplate module and assign it the alias of RELAY.
- Next we verify that there is a RELAYplate at address zero by requesting the ID string.
- Finally, we send the relayON command to K3.
Assuming everything is connected properly, the light bulb should turn on. To turn the light bulb off simply enter RELAY.relayOFF(0,3). To cycle the power off and on with a single command enter RELAY.relayTOGGLE(0,3).
These three commands will likely be the ones you use the most. However, see the instruction set below for additional commands to control your RELAYplate.
The RELAYplate Command Set
A summary of the Python RELAYplate commands are shown below. It addition, a printable, quick reference guide can be found here.
RELAY Control Functions
relayON(addr,relay) – turns on (closes) the specified relay
relayOFF(addr,relay) – turns off (opens) the specified relay
relayTOGGLE(addr,relay) – “toggles” state of specified relay. If relay is on, this command will turn it off. If relay is off, this command will turn it on. Use this command to blink a lamp off and on.
relayALL(addr,value) – used to control the state of all relays with a single command. “value” is a 7 bit number with each bit corresponding to a relay. Bit 0 is relay 1, bit 1 is relay 2, and so on. To turn all the relays on at once, use the number 127 for the value.
relaySTATE(addr) – Returns a 7-bit number with the current state of each relay. Bit 0 is relay 1, bit 1 is relay 2, and so on. A “1” in a bit position means that the relay is on and zero means that it’s off.
LED Control Functions
setLED(addr) – turn on the LED
clrLED(addr) – turn off the LED
toggleLED(addr) – if LED is on, turn off. If LED is off, turn on.
System Level Functions
getID(addr) – return Pi-Plate descriptor string
getFWrev(addr) – return FW revision in byte format
getHWrev(addr) – return HW revision in byte format
getPMrev() – returns revision of python module
getADDR(addr) – return address of pi-plate. Used for polling available boards at power up.
RESET(addr) – set RELAYplate to power-on state. Turns all relays off.
addr: Address – RELAYplates have jumpers on the board that allow their address to be set to a value between 0 and 7.
relay: Each RELAYplate has seven individually addressable relays numbered 1 through 7.
value: some commands require or return a seven bit value that can range from 0 to 127.
The coils in relays can be power hungry devices. For example, each of the relay coils on the RELAYplate pulls about 40mA. If we assume that the relay power supply is pretty efficient then, when all relays are in the ON state, about 300mA of current will be required for the coils. By default, the RELAYplate is set to receive power from the 5 volt supply of the Raspberry Pi. But, if you stack more than two RELAYplates and turn on all the relays, the RPi power supply will possibly be overloaded and it will start to “droop.” The best case result of this will be a colorful square appearing on your screen. The worst case will be that your RPi resets (that’s bad).
To get around this problem, the RELAYplate has two connectors dedicated to providing auxiliary power to the relay coils. These can be seen in the images below:
Relay Power Input 1 uses a standard USB micro-B connector and can be powered from the same type of power supplies used for a Raspberry Pi. The Relay Power Input 2 connector serves two functions: it can be used as a power input with a 5 volt power supply and/or it can be used to “daisy-chain” relay coil power between multiple RELAYplates.
The first step to take when using one of these two power inputs is to power down your Raspberry Pi and move the relay power select jumpers on each RELAYplate in the stack as shown below on the right:
Remember: move the jumper on all of the RELAYplates in the stack. Now plug a power supply with an output voltage of 4.5 to 5.5 volts into Relay Power Input 1 or connect the wires of 5VDC supply to Relay Power Input 2. A couple of warnings here:
- Always move the jumpers to short pins 3 and 4 BEFORE attaching a power supply to either of the Relay Power Inputs.
- Only use one of the Relay Power Inputs on one of the RELAYplates in your stack. Failure to do so could destroy your RELAYplate board.
Once your power supply is connected, use short lengths of 22 gauge wire to “daisy chain” the power between the RELAYplates using the terminal blocks for Relay Power Input 2. An example of this is shown below where a 5 volt DC power supply capable of providing 2.4 amps is powering a stack of eight RELAYplates.