Library and example for the 4-port Relay Expansion Board are part of of PhpocExpansion library for Arduino. The library reference is available here.
This tutorial shows how to use 4-port Relay Expansion Board with an example of PhpocExpansion library for Arduino.
Hardware Required
- Arduino Uno or Mega
- USB Cable for Arduino
- PHPoC Shield R2 or PHPoC WiFi Shield R2
- 4-port Relay Expansion Board - PES-2601
- Power supply for Arduino (USB or DC adapter)
- (optional) A DC electric device (e.g. DC light bulb, EM lock, electric horns) + DC power adapter for the device
Wiring
- Stack PHPoC Shield or PHPoC WiFi Shield on Arduino
- Stack Relay Expansion Board PES-2601 on PHPoC Shield or PHPoC WiFi Shield
- (optional) Connect the terminal block of Relay Expansion Board to a DC electric device.
Note that relay just like a switch, you can connect positive line or negative line to relay.

Since Relay Expansion Board has four relays, it can control four devices simultaneously. The above images show only one device for illustration.
Install Arduino IDE
If you have not install Arduino IDE yet, please download and install Arduino IDE .
Install Library
- Run Arduino IDE.
- Navigate to Sketch > Include Library > Manage Libraries
- Search "Phpoc Expansion" on search bar of the Library Manager.
- Select the PhpocExpansion library and press the [Install] button.
- Restart Arduino IDE for the next step.
Source Code
- Connect Arduino to PC via usb cable
- Open Arduino IDE
- Open "ExpansionRelayOutput" example
- Compile the example code and uploads to Arduino by clicking "Upload" button on Arduino IDE
- Open "Serial Monitor" tool on Arduino IDE to see the output log
- Watch four LED's state on Relay Expansion Board. We can see these LED blink one time per second.
- If you connected a DC electric device to Relay Expansion Board, you can see the device switch between on/off every second.
Code Explanation
At the beginning
we need to create and four relay object:
Code:
ExpansionRelayOutput relay0(expansionId, 0); ExpansionRelayOutput relay1(expansionId, 1); ExpansionRelayOutput relay2(expansionId, 2); ExpansionRelayOutput relay3(expansionId, 3);
You can change it and map it to the below to know the value.
Note that: 4-port Relay Expansion Board is one of the expansion boards. List of expansion for arduino is available here
In setup() function
- Phpoc.begin() and Expansion.begin() functions must be used to initial PHPoC [WiFi] Shield and expansion board, repectively.
- Serial.println(relay0.getName()) function is used optionally to get name of expansion board and print it to serial.
- There are some functions has been commented.
Code://relay0.setDelay(900); //relay1.setDelay(1000); //relay2.setDelay(1100); //relay3.setDelay(1200);
In loop() function
There are some functions are used.
- relay0.on(): control relay on.
- relay0.off(): control relay off.
- relay0.isOn(): check whether relay is on or not.
- relay0.isOff(): check whether relay is off or not.
See Also
- Arduino - Relay Expansion Board - PES-2601
- Arduino - Digital Input Expansion Board - PES-2602
- Arduino - DC Motor Controller - PES-2604
- Arduino - Stepper Motor Controller - PES-2605
- Arduino - RS-232 Expansion Board - PES-2606
- Arduino - RS-422 Expansion Board - PES-2607
- Arduino - RS-485 Expansion Board - PES-2607
References