2-CH Relay HAT Optocoupler Isolation Relay Expansion Board

2-CH Relay HAT

Overview

This product is a 2-channel relay expansion board, suitable for Raspberry Pi Zero/Zero W/Zero WH/2B/3B/3B+/4B, STM32, and Arduino. It comes with two relays on board, and can control shutdown independently.

Parameters

  • Supply voltage:5V
  • Relay allows access to the load:250V/5A
  • With relay working indicator, it is convenient to check the working status of the relay
  • Optocoupler isolation circuit, strong anti-interference ability, stable work
  • Open source demo codes available for Raspberry Pi
  • Size: 56mm(Length) x 34mm(width)
  • Weight: 25g

Usage

The example code is available in two versions: one for the WiringPi library and one for the Lgpio library. The Bullseye system uses the WiringPi library, while the Bookworm system uses the Lgpio library.

Hardware interface configuration description

The bookworm system in the Raspberry Pi sample program uses the BCM number pin definition, and the bullseye system uses the wiringPi number pin definition. The definitions for wiring with the Raspberry Pi motherboard are shown in the following table:

Table2-1 2-CH Relay HAT and Raspberry Pi pin
2-CH Relay HATPin functionBCMwiringPi
5V5V5V5V
GNDGNDGNDGND
CH1Channel 126P25
CH2Channel 219P24

The Resource Profile is shown in the figure below:

2-CH Relay HAT
Figure 2-1 2-CH Relay HAT Resource Profile on diagram

1. Relay control signal level and amplitude sliding switch, available 3.3V or 5V.

2. Relay working indicator: when the light is on, it means that the normally open end of the relay is closed, the normally closed end is disconnected, and when the light is off, it means that the normally open end of the relay is disconnected and the normally closed end is closed.

3. Relay

4. Relay output

5. Power indicator

6. PH2.0 4PIN Module wire

7. 2.54mm 4PIN connector

Relay wiring diagram is as follows:

Relay wiring instruction
Relay wiring instruction diagram

Demo Codes Usage

WiringPi Library Installation

sudo apt-get install wiringpi
wget https://project-downloads.drogon.net/wiringpi-latest.deb #

Raspberry Pi 4B Version Upgrade

sudo dpkg -i wiringpi-latest.deb
gpio -v #

If version 2.52 appears, it indicates that the installation was successful.

# For the Bullseye branch system, use the following commands:

git clone https://github.com/WiringPi/WiringPi
cd WiringPi
. /build
gpio -v #

# Running gpio -v should display version 2.70. If it does not, it indicates that the installation is incorrect.

If you encounter the error "ImportError: No module named 'wiringpi'" when running Python example programs, use the following command:

# For Python 2.x version

pip install wiringpi

# For Python 3.x version

pip3 install wiringpi

Note: If the installation fails, you can try the following compilation and installation steps:

git clone --recursive https://github.com/WiringPi/WiringPi-Python.git

Note: The --recursive option automatically pulls submodules; otherwise, you will need to download them manually.

Navigate to the downloaded WiringPi-Python folder and enter the following commands to compile and install:

# For Python 2.x version

sudo python setup.py install

# For Python 3.x version

sudo python3 setup.py install

If you encounter the following error:

2-CH Relay HAT

If you encounter the error, enter the command sudo apt install swig to install SWIG. After installation, run sudo python3 setup.py install to compile and install. If you see similar information, it indicates that the installation was successful.

2-CH Relay HAT

Lgpio Library Installation

For the Bookworm system, the example program uses the Lgpio library. The installation command for this library is as follows:

wget https://github.com/joan2937/lg/archive/master.zip
unzip master.zip
cd lg-master
make
sudo make install

Run Example Program

Python:

Enter the Python directory:

cd /home/pi/raspberry-pi/lgpio/python

or

cd /home/pi/raspberry-pi/wiringpi/python

Execute:

sudo python3 2-ch-relay.py

C:

Enter the C directory:

cd /home/pi/raspberry-pi/lgpio/c

or

cd /home/pi/raspberry-pi/wiringpi/c

Execute:

sudo make clean
sudo make
sudo ./main

Resources

Schematic

Demo Codes

Product

Data Sheet

HF3FF005-1ZS

LTV-357T-B-IN

Technical Support

Technical Support and Product Notes