Template: RPi Relay Board Manual
Interface description
- Correspondence between relay channel and RPi Pin
Channel No. | RPi Pin No. | wiringPi | BCM | Descriptions |
---|---|---|---|---|
CH1 | 37 | P25 | 26 | Channel 1 |
CH2 | 38 | P28 | 20 | Channel 2 |
CH3 | 40 | P29 | 21 | Channel 3 |
Notices: The labels on the PCB are corresponding to the wiringPi code.
If you use cable to wire the board instead of directly attaching the pin heard, you need to connect the 5V, 3.3V and GND for normally powering.
- Relay_JMP (6P jumper) usage:
Relay_JMP is the relay control pin selecting jumper. When this jumper is connected, the relay can be controlled by the Raspberry Pi.
- Relay screw terminal description:
This board integrates three screw terminals, and each has three pins for connecting external circuits.
All the terminals are low active. When the Raspberry Pi outputs a Low Level from its IO, the LED related to the corresponding channel lights up. At the same time, the relay NO (normally open contacts) closes, and the NC (normally closed contacts) opens, so as to change the ON/OFF status of the external circuit.
(PS: Remember to connect the jumper Relay_JMP!)
Before the relay action: | After the relay action: |
BCM2835
#Open the Raspberry Pi terminal and run the following commands wget http://www.airspayce.com/mikem/bcm2835/bcm2835-1.68.tar.gz tar zxvf bcm2835-1.68.tar.gz cd bcm2835-1.68/ sudo ./configure && sudo make && sudo make check && sudo make install # For more information, please refer to the official website: http://www.airspayce.com/mikem/bcm2835/
wiringPi
#Open the Raspberry Pi terminal and run the following commands sudo apt-get install wiringpi #For Raspberry Pi systems after May 2019 (If your system is earlier than this before, you may not need to execute), you may need to upgrade: wget https://project-downloads.drogon.net/wiringpi-latest.deb sudo dpkg -i wiringpi-latest.deb gpio -v # Run gpio -v and version 2.52 will appear. If it does not appear, the installation may be wrong #Bullseye branch system use the following command: git clone https://github.com/WiringPi/WiringPi cd WiringPi ./build gpio -v # Run gpio -v and version 2.60 will appear. If it does not appear, it means that there is an installation error
- Install Python function library
sudo apt-get update sudo apt-get install python-pip sudo apt-get install python-dev sudo pip install RPi.GPIO
Test demo
Execute the following commands in the terminal, download the demo and extract it to the specified directory.
wget https://www.waveshare.com/w/upload/0/0c/RPi_Relay_Board.zip unzip -o RPi_Relay_Board.zip -d ./RPi_Relay_Board sudo chmod 777 -R RPi_Relay_Board cd RPi_Relay_Board
Shell demo
Enter the Linux terminal and execute the following commands in the terminal:
cd shell sudo ./Relay.sh CH1 ON sudo ./Relay.sh CH2 ON sudo ./Relay.sh CH3 OFF
Expected Result: The LED for relay channel 1 is lighted up and the relay is audible. The last two parameters in the command can be changed. For example, run the above commands to turn on relay 2 and turn off relay 3.
Bcm2835 Program
Enter the Linux terminal and execute the following commands in the terminal:
cd bcm2835 make sudo ./Relay_Module
Expected result: You can see the 3 LEDs light up in sequence and the relay switches back and forth between NC and NO contacts in sequence. At the same time, the terminal will display which contact the relay is currently in.
wiringPi Program
Enter the Linux terminal and execute the following commands in the terminal:
cd wiringPi make sudo ./Relay_Module
Expected result: You can see the 3 LEDs light up in sequence and the relay switches back and forth between NC and NO contacts in sequence. At the same time, the terminal will display which contact the relay is currently in.
python program
Enter the Linux terminal and execute the following commands in the terminal:
cd python sudo python Relay_Module.py
Expected result: You can see the 3 LEDs light up in sequence and the relay switches back and forth between NC and NO contacts in sequence. At the same time, the terminal will display which contact the relay is currently in.
Web Control
The web page control of this demo is based on the python web framework to control the relay.
Enter the Linux terminal and execute the following commands in the terminal:
sudo apt-get install python-bottle cd python-bottle sudo python main.py
Enter the Raspberry Pi IP address in the address bar of Google Chrome (other browsers may be not compatible), port number 8080