Relay Shield is an overlay that uses four high quality relays and NO/NC interfaces to control high current loads. This means that the overlay can be a good solution to control devices that cannot be directly controlled by the IIC bus.The standardized shape of the cap allows easy connection to the Raspberry Pi. The cap also has four lights showing the on/off status of each relay.

Buy Now

Properties

  • Compatible with Raspberry Pi
  • Interfaces: IIC, 3 SW1 switches (1, 2, 3) - selection of fixed I2C bus address
  • Relay screw connections
  • Standardized shape and design of the cap
  • LEDs for each relay
  • Pins COM, NO (Normally Open) and NC (Normally Closed) for each relay
  • High quality relays
  • Operating status indicators for each relay

Specifications

FeatureMinTypicalMaxUnit
Supply voltage 4.75 5 5.5 VDC
Working intensity 10 / 360 mA
Switching voltage / / 30 / 250 VDC / VAC
Switching intensity / / 15 A
Frequency / 1 / Hz
Switching power / / 2770 VA / 240 W
Lifespan 100 000 / / series
Dimensions 91.20 x 56.15 x 32 mm

Equipment overview

Installation

To install the overlay and check its operation, the following steps must be taken:

  • Step 1: Install the overlay on your Raspberry Pi
  • Step 2 Enable Raspbian I2C software interface
  • Step 3. Check that Raspberry Pi recognizes the plate
  • Step 4. Run the code in Python to practice the board

Step 1: Mount the cap on your Raspberry Pi

Installation is very simple, the board has the appropriate female connectors needed to connect with male connectors on Raspberry Pi. Note: Raspberry Pi Zero does not have male connectors, you have to install them additionally to use relays.

We recommend placing an electrical tape on the Ethernet port on the Raspberry Pi before installing the board. If you mount the board without using spacers (as shown in the picture below), there is a chance that the board will contact the Ethernet port housing, which may cause a problem.

For design projects, we recommend that you use spacers that hold the two tiles firmly in place.

The overlay is configured for the older Raspberry Pi with a 26-pin connector, so when you connect it to the Raspberry Pi with a 40-pin connector, you will have to move the overlay to the side, as shown in the picture. If you don't align the pins properly, you may have problems later, because the overlay simply won't work.

Run I2C

The overlay communicates with Raspberry Pi via the I2C interface https://en.wikipedia.org/wiki/I%C2%B2C. This interface is disabled by default on the Raspbian operating system, so you need to enable it before using the overlay. Enable Raspberry Pi and let it run in the graphical interface. When you start, open the menu, select Preferences, and then Raspberry Pi Configuration, as shown below:

In the newly opened window, select the Interfaces tab, as shown in the picture below. Select Enable next to I2C, as shown in the picture, and click OK to continue. When you restart the computer, Raspberry Pi should recognize the Relay tab. In the next section, we will show you how to check if Raspberry Pi recognizes an overlay.

Check that Raspberry Pi recognizes the overlay

Since we already have the I2C interface enabled, it's time to make sure that Raspberry Pi recognizes our overlay. Open the terminal window on your Raspberry Pi and type the following command:

i2cdetect -y -r 1

The application will display a snapshot of recognized I2C devices, as shown in the picture below. In this example there is only one I2C board in the system, the overlay with relays is configured at address 20. Why this value is important, you will find out later in the article.

You should be able to use the switches on the overlay to set the I2C bus address. There are 4 DIP switches on the board, let's see what happens if you change them.

We have 4 switches, three of them are marked A0 to A2 and one as NC. NC means no signal. Each switch has a low state and a high state, and the following table shows how to set them to determine the I2C address on the board:

A0A1A2The address
High High High 20
Low High High 21
High Low High 22
High High Low 24
High Low Low 26
Low Low Low 27

Starting the test application

Use the test code from thegithub repository. Download the code and it will help you to easily do the following.

To start a test application: open the terminal window, go to the place where you pulled the sample application from and run it with the following command:

python ./seeed_relay_test.py

When the command prompt window appears, enter the following commands to turn the relays on and off:

  • Entering 1on, 2on, 3on, or 4on and confirming with an entere will turn on the indicated relay
  • Entering 1off, 2off, 3off, or 4off and confirming with an entero will disable the indicated relay
  • Entering allon or alloff will enable or disable all relays

Using the module in Python

To use a module in your own applications in Python, copy the module (relay_lib_seeed.py) to the project folder, then import the module in the application, adding the following line at the beginning:

from relay_lib_seeed import *

In this way, the application provides a number of functions:

  • relay_on(int_value) - Enable one snapshot. Enter an integer value from 1 to 4 (inclusive) to the function to specify the relay you want to enable. For example: relay_on(1) will enable the first relay (which is actually relay 0).
  • relay_off(int_value) - Turn on one snapshot. Enter an integer value from 1 to 4 (inclusive) to the function to specify the relay you want to turn on. For example: relay_on(4) will turn on the first relay (which is actually relay 3).
  • relay_all_on() - Turns on all relays simultaneously
  • relay_all_off() - Shuts down all relays simultaneously

The module will show the value of the configuration, which should be kept in mind when working with the board:

# 7 bit address (will be left shifted to add the read write bit)
DEVICE_ADDRESS = 0x20

20? Do you remember this value from the previous part of the manual? The tiletakes this address by default. If you change switches, you will have to update this variable accordingly.

To see the module in action, open a terminal window on Raspberry Pi, go to the folder where the files of this repository were extracted and type the following command:

python ./relay_lib_seeed_test.py

This application:

  • Will switch on all relays per second
  • It will switch off all relays
  • Goes through each of the relays (1 to 4), switching on each of them for a second

The module will save the indicators on the console by performing each step as shown in the figure below:

The LEDs on the board (one for each relay) will light up when the relays are activated. The lights may not light up in turn.

The code that executes these commands is as follows:

# turn all of the relays on
relay_all_on()
# wait a second
time.sleep(1)
# turn all of the relays off
relay_all_off()
# wait a second
time.sleep(1)
# now cycle each relay every second in an infinite loop
while True:
for and in range(1, 5):
   relay_on(i)
   time.sleep(1)
   relay_off(i)

That's all, now you can use all the possibilities of your tile.

Links

Botland.store - shop for makers!