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
Dimensions | 65mm (Length) x 56mm (Width) |
Opto-isolator | LTV-357T-B-IN |
Operating Voltage | 3.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:
4-CH Relay HAT | Pin function | BCM | wiringPi |
---|---|---|---|
5V | 5V | 5V | 5V |
3.3V | 3.3V | 3.3V | 3.3V |
GND | GND | GND | GND |
CH1 | Channel 1 | 26 | P25 |
CH2 | Channel 2 | 19 | P24 |
CH3 | Channel 3 | 13 | P23 |
CH4 | Channel 4 | 6 | P22 |
The pinout definition is shown in the figure below:
- ①、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
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:
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.
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
Data Sheet