If you've already familiarized yourself with the PHPoC environment, this article will continue with a relay expansion board, named PES-2401 R2.
Plug itThis board works only in conjunction with the PHPoC Blue or Black and is plugged. Since further boards can be plugged into each other, the slave ID must first be assigned via the DIP switch (named ID Switch): in our case, the first expansion board.
With the guided wizard within the board documentation, it's easy to click through dimensioning and differences in the Terminal Block (S and T-Type) to the sample sketch.
Code a 2 linerA string is used to address the respective relay: the Normal Open (NO) Relay is initiated with the set command and set to high or low accordingly. 4 LEDs of digital output lets the user visual monitor what happened.
// set Port 4 high {named internal Port 0-3}
spc_request_dev($sid, "set 3 output high");
// get status of output ports
echo "Port 3: ", spc_request_dev($sid, "get 3 output"), "\r\n";
sleep(3);
"set 3 output high" = when counting from 0-3, port 3 means the fourth relay, which is switched on.
Similar to the delay command, this is PHP "sleep(3)" - for 3 seconds instead of millis.
The status of this relay is retrieved with "get 3 output".
Upload itUsing the PHPoC debugger (for Win), you can put both the PHP script (attached) and the necessary SPC library (its a part of the PSP-Library with filename 'lib/sd_spc.php') for the extension boards on the PHPoC board.
Test it in your favorite browserThe PHPoC Blue / Black is connected via micro USB cable with 5V power.The separately controlled 12V circuit for the colorful LEDs is "switched" over the positive pole (red cables). The negative pole is directly connected to each other via the DC adapters (you can also invert this so that the minus pole is used).
As a result, the PHPoC code will now be executed via a website (192.168.178.55/relay.php) and the relay will be switched on as well as switched off again after 3 seconds.
Expand itButtons could be used to change the manually controlled circuit or automatically configure it even during times of the day.
You can find similar projects with Relay here:
https://www.hackster.io/ingo-lohs/mywater-fountain-controlled-by-particle-photon-and-blynk-bdd09d
https://www.hackster.io/ingo-lohs/mikroelektronika-relay-click-board-542fbe
https://www.hackster.io/ingo-lohs/mypir-sensor-activate-rgb-stripe-controlled-by-relay-f8010c
https://forum.phpoc.com/articles/tutorials/1262-arduino-relay-expansion-board
Bonus
Last month (09.11.2018) a new firmware v1.5.0 has been released for the Blue / Black board. You can update these via the PHPoC Debugger. More details can be found here.
Comments