Library and example for the 4-port input expansion board are part of of PhpocExpansion library for Arduino. The library reference is available here.
This tutorial shows how to use 4-port input 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 Input Expansion Board - PES-2602
- Power supply for Arduino (USB or DC adapter)
- (optional) A DC electric device / sensor
Wiring
- Stack PHPoC Shield or PHPoC WiFi Shield on Arduino
- Stack input expansion board PES-2602 on PHPoC Shield or PHPoC WiFi Shield
- (optional) Connect the terminal block of input expansion board to a DC electric device.

Since input expansion board has four input port, it can monitor state of 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 "ExpansionPhotoInput" 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:
- If you connected a DC electric device to input expansion board, try to turn on/off device. And then see LED on input expansion board and log on Serial Monitor.
- If you does not connect a DC electric device to input expansion board, try to connect GND pin and 5v pin to GND pin and DI0 pin, respectively. And then see stgatus LED on input expansion board and log on Serial Monitor.
(on/off states depends on the input value)
Code Explanation
At the beginning
we need to create and four input object:
Code:
ExpansionPhotoInput in0(expansionId, 0); ExpansionPhotoInput in1(expansionId, 1); ExpansionPhotoInput in2(expansionId, 2); ExpansionPhotoInput in3(expansionId, 3);
You can change it and map it to the below to know the value.
Note that: 4-port input 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(in0.getName()) function is used optionally to get name of expansion board and print it to serial.
- There are some functions has been commented.
Code://in0.setDelay(900); //in1.setDelay(1000); //in2.setDelay(1100); //in3.setDelay(1200);
In loop() function
There are some functions are used.
- in0.isOn(): check whether the state of input port is on or not.
- in0.isOff(): check whether the state of input port 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