Technical documentation Buy on-line

Relay interface

Two relays are available on the CM3-HOME-B and CM3-HOME-F board. This article explais how to use them.

  • Normally-Opened and Normally-Closed contacts available on screw terminals
  • Max rated: 24 VAC/DC @ 1A
  • Snubbers already on-board to increase reliability with inductive loads

GPIO used

  • RL1 (left relay) GPIO21
  • RL2 (right relay) GPIO22

Shell example

Configure

echo 21 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio21/direction                                   
echo 0 > /sys/class/gpio/gpio21/value

echo 22 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio22/direction                                   
echo 0 > /sys/class/gpio/gpio22/value

Turn on

echo 1 > /sys/class/gpio/gpio21/value
echo 1 > /sys/class/gpio/gpio22/value

Turn off

echo 0 > /sys/class/gpio/gpio22/value
echo 0 > /sys/class/gpio/gpio22/value

Python example

This example turns-on the relays alternately with a period of 1 second.

import RPi.GPIO as GPIO
import time

RELAY_LEFT=21
RELAY_RIGHT=22

GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
GPIO.setup(RELAY_LEFT,GPIO.OUT)
GPIO.setup(RELAY_RIGHT,GPIO.OUT)

for i in range(5):
        GPIO.output(RELAY_LEFT,GPIO.HIGH)
        GPIO.output(RELAY_RIGHT,GPIO.LOW)
        time.sleep(1)
        GPIO.output(RELAY_LEFT,GPIO.LOW)
        GPIO.output(RELAY_RIGHT,GPIO.HIGH)
        time.sleep(1)

GPIO.output(RELAY_LEFT,GPIO.LOW)
GPIO.output(RELAY_RIGHT,GPIO.LOW)

Technical documentation Buy on-line

Bruna Mandolino