Tutorial Video
Hardware
- PHPoC Blue or PHPoC Black
- Micro USB to USB Cable (to upload source code to PHPoC Device)
- Rotary Angle Sensor
- Jumper wires
About Rotaty Angle Sensor
Rotaty angle sensor (also called potentiometer) is used to linearly adjust/change something in value. The rotaty angle sensor used in this example includes three pins:
- VCC pin.
- GND pin.
- Signal pin ( produces analog output between 0 and VCC).
- The sensor outputs analog signal to signal pin. The signal value is in direct proportion to the rotated angle.
- By reading value of sensor's signal pin, we can infer the rotated angle or how many percent something should be addjusted/changed. To read value of sensor's signal pin, we just need to connect the sensor's signal pin to PHPoC device's ADC (Analog to Digital Converter) pin and use PHPoC code to read the value.
- Grove rotaty angle sensor (for more convenience, use it in combination with PHPoC Grove Expansion Board).
- Potentiometer.
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\02.adc_rotary_angle 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 "/lib/sd_340.php";
echo "PHPoC example : P4S-34X / ADC / Catalex Rotary Angle Sensor\r\n";
adc_setup(0, 0); // adc0, channel 0
$last_adc_in = 0;
while(1)
{
$adc_in = adc_in(0, 30);
if(abs($adc_in - $last_adc_in) > 5)
{
printf("Voltage : %.2fV\r\n", $adc_in / 4095.0 * 3.3);
$last_adc_in = $adc_in;
usleep(100000);
}
}
?>
[Explanation]
Source code of this file does:
- Setup ADC pin.
- Read value from rotaty angle sensor.
- Calculate Voltage based on the read value.
- Print Voltage to PHPoC Debugger's console.
See Also
- Rotary Angle Sensor - Monitoring Rotary Angle Sensor from Webpage using Hypertext.
- Rotary Angle Sensor - Monitoring Rotary Angle Sensor from Webpage with Image.
- Rotary Angle Sensor - Monitoring Rotary Angle Sensor via WebSocket.
- Rotary Angle Sensor - Monitoring Rotary Angle Sensor via WebSocket with Web-based Gauge.
Other Resources