Tutorial Video
Hardware
- PHPoC Blue or PHPoC Black
- Micro USB to USB Cable (to upload source code to PHPoC Device)
- Piezo Buzzer
- Jumper wires
About Buzzer
Buzzer is used to make sound, tone and alerts. The buzzer used in this example includes three pins:
- VCC pin.
- GND pin.
- Signal pin (receives the control signal from controller).
- If generating a square wave of the specified frequency (and 50% duty cycle) on signal pin of buzzer, buzzer makes a specific tone corresponding to the frequency.
- If controlling the signal pin of buzzer to HIGH (3.3V to 5V), of buzzer makes constant sound.
- If controlling the signal pin of buzzer to LOW (0V), of buzzer keeps silent.
- This example shows how to simply control buzzer by controlling the signal pin of buzzer to HIGH or LOW to generate sound or mute, respectively. To do so, It just needs to connect an digital output pin of PHPoC devices to the signal pin of buzzer and control it. For advanced control, use can use hardware/software timer to generate a square wave of the desired frequency.
- Grove buzzer (for more convenience, use it in combination with PHPoC Grove Expansion Board).
- Piezo buzzer
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_buzzer 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("OUT_PIN", 0);
echo "PHPoC example : P4S-34X / UIO / Catalex Buzzer\r\n";
uio_setup(0, OUT_PIN, "out low");
while(1)
{
uio_out(0, OUT_PIN, HIGH);
usleep(100000);
uio_out(0, OUT_PIN, LOW);
usleep(900000);
}
?>
[Explanation]
Source code of this file does:
- Setup IO pin to output mode and initialize IO pin state to LOW (Buzzer is mute).
- Tongle output pin between LOW and HIGH to turn ON/OFF Buzzer.
See Also
- Buzzer - Controlling Buzzer from Webpage using Hypertext.
- Buzzer - Controlling Buzzer from Webpage with Image.
- Buzzer - Controlling Buzzer via WebSocket.
Other Resources