Tutorial Video
Hardware
- PHPoC Blue or PHPoC Black
- Micro USB to USB Cable (to upload source code to PHPoC Device)
- Touch Sensor
- Jumper wires
About Touch Sensor
Touch sensor is used to detect the touch of finger. The touch sensor used in this example includes three pins:
- VCC pin.
- GND pin.
- Signal pin (outputs digital signal).
- If sensor is touched by finger, value of the sensor's signal pin is HIGH (VCC).
- Otherwise, value of sensor's signal pin is LOW (0 V).
- By reading value of sensor's signal pin, we can infer state of touch sensor. To read value of sensor's signal pin, we just need to connect the sensor's signal pin to PHPoC device's input pin and use PHPoC code to read the value.
- Grove touch sensor (for more convenience, use it in combination with PHPoC Grove Expansion Board).
Wiring Diagram

Quick Steps
Source code of this example is a part of PHPoC Support Packet (PSP). You need to:
- Download PHPoC Support Package.
- Upload example\p4s\01.php_task\01.uio_touch_sensor to PHPoC Blue/Black.
- Click "Run" button on PHPoC Debugger.
Source Code
Source files includes:
- init.php: this file is run when PHPoC system is powered or reset. It is used to specify which file is run is system loop.
- task0.php: this file is run in system loop of PHPoC devices.
init.php
This file is run when PHPoC system is powered or reset. It is used to specify that task0.php is run is system loop.
PHP Code:
<?php
system("php task0.php");
?>
task0.php
[Full Code]
PHP Code:
<?php
if(_SERVER("REQUEST_METHOD"))
exit; // avoid php execution via http request
include_once "/lib/sd_340.php";
define("IN_PIN", 0);
echo "PHPoC example : P4S-34X / UIO / Catalex Touch Sensor\r\n";
uio_setup(0, IN_PIN, "in");
$last_touch = 0;
while(1)
{
$touch = uio_in(0, IN_PIN);
if($touch != $last_touch)
{
if($touch)
echo "touch ON\r\n";
else
echo "touch OFF\r\n";
$last_touch = $touch;
}
}
?>
[Explanation]
Source code of this file does:
- Setup IO pin to input mode.
- Read value from IO pin to know state of touch sensor.
- Print touch state to PHPoC Debugger's console.
See Also
- Touch Sensor - Monitoring Touch Sensor from Webpage using Hypertext.
- Touch Sensor - Monitoring Touch Sensor from Webpage with Image.
- Touch Sensor - Monitoring Touch Sensor via WebSocket.
Other Resources