4-CH Relay Raspberry Pi Relay Expansion Board 4-CH Relay HAT

4-CH Relay HAT

Overview

This product is a 4-channel relay expansion board for Raspberry Pi, based on the Raspberry Pi 40-pin GPIO interface header. It is compatible with Raspberry Pi Zero/Zero W/Zero WH/2B/3B/3B+/4B. The board is equipped with four relays that can be controlled individually to turn on and off.

Product Features

  • Operating Voltage: 3.3V&5V
  • Maximum Load per Relay: 250V/5A
  • Each relay has a working indicator light for easy monitoring of relay status
  • Opto-isolated circuit for strong anti-interference capability and stable operation
  • Designed based on Raspberry Pi 40-pin GPIO interface header, suitable for Raspberry Pi series boards
  • Provides open-source example programs for Raspberry Pi development boards

Product Specifications

Dimensions65mm (Length) x 56mm (Width)
Opto-isolatorLTV-357T-B-IN
Operating Voltage3.3V&5V

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 4-CH Relay HAT and Raspberry Pi pin
4-CH Relay HATPin functionBCMwiringPi
5V5V5V5V
3.3V3.3V3.3V3.3V
GNDGNDGNDGND
CH1Channel 126P25
CH2Channel 219P24
CH3Channel 313P23
CH4Channel 46P22

The pinout definition is shown in the figure below:

4-CH Relay HAT
Figure 2-1 4-CH Relay HAT pinout definition diagram
  • ①、Relay output

    ②、Relay

    ③、The designated pin selects the pin header. The short circuit state indicates that the relay is connected to the designated control pin. On the contrary, it indicates that the user can connect to other pins through jumpers.

    ④、Raspberry Pi 40PIN header

    ⑤、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

    Relay wiring diagram is as follows:

Relay wiring diagram

4-CH Relay HAT
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:

4-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.

4-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/4-ch-relay/lgpio/python

or

cd /home/pi/4-ch-relay/wiringpi/python

Execute:

sudo python3 4-ch-relay.py

C:

Enter the C directory:

cd /home/pi/4-ch-relay/lgpio/c

or

cd /home/pi/4-ch-relay/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