Tutorial Video
Hardware
- PHPoC Blue (+ USB WLAN) or PHPoC Black (+ Ethernet cable)
- 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\03.html_image\02.adc_rotary_angle to PHPoC Blue/Black.
- Configure network parameters (e.g. WiFi SSID, password, IP address ...).
- Access webpage on PHPoC using Web Browser on your PC or smart phone (See How To).
Source Code
Source files includes:
- index.php: this file contains source code of web page.It is only run in response to request from Web Browser.
- adc_rotary_angle.jpg: Wring diagram between PHPoC devices and rotaty angle sensor. It is displayed on webpage.
index.php
[Full Code]
PHP Code:
<html>
<head>
<title>PHPoC / <?echo system("uname -i")?></title>
<meta name="viewport" content="width=device-width, initial-scale=0.5">
<style> body { text-align: center; } </style>
</head>
<body>
<h2>
ADC / Catalex Rotary Angle Sensor<br>
<img src="adc_rotary_angle.jpg"><br>
<?php
include "/lib/sd_340.php";
adc_setup(0, 0); // adc0, channel 0
$adc_in = adc_in(0, 30);
printf("Voltage : %.2fV<br>\r\n", $adc_in / 4095.0 * 3.3);
?>
<br><a href="index.php">reload</a><br>
</h2>
</body>
</html>
[Explanation]
Source code of index.php file is composed of HTML, CSS and PHPoC code.
PHPoC code is interpreted on on PHPoC device.
-
PHP Code:
<?php
include "/lib/sd_340.php";
adc_setup(0, 0); // adc0, channel 0
$adc_in = adc_in(0, 30);
printf("Voltage : %.2fV<br>\r\n", $adc_in / 4095.0 * 3.3);
?>
- Setup ADC pin.
- Read value from rotaty angle sensor.
- Calculate Voltage based on the read value.
- Print the Voltage value to Webpage
PHPoC code may add/update the content of HTML, CSS or JavaScript code. Once PHPoC code is interpreted in PHPoC, the remaining code is client-side code and it is returned to Web Browser. Web Browser receives this code and interpret it to display the webpage.
- HTML: describes the structure of Web pages
- CSS: describes how HTML elements are to be displayed
See Also
- Rotary Angle Sensor - How to Use Rotary Angle Sensor.
- Rotary Angle Sensor - Monitoring Rotary Angle Sensor from Webpage using Hypertext.
- Rotary Angle Sensor - Monitoring Rotary Angle Sensor via WebSocket.
- Rotary Angle Sensor - Monitoring Rotary Angle Sensor via WebSocket with Web-based Gauge.
Other Resources