Controlling GPIO with Raspberry Pi using php


Controlling GPIO/LED's with Raspberry Pi & PHP

I am using WiringPi with php. WiringPi - Wiring Pi pin number, for Gordon Henderson's Wiring Pi library

//install apache and php on pi
sudo apt-get install apache2 apache2-utils
sudo apt-get install libapache2-mod-php5 php5 php-pear php5-xcache php5-mysql php5-curl php5-gd

// Tooglle Yellow Light
if (isset($_POST["ledBtn_yellow_on"])) {
	LedToggle($_POST["ledBtn_yellow_on"], true);
if (isset($_POST["ledBtn_yellow_off"])) {
	LedToggle($_POST["ledBtn_yellow_off"], false);
// End toggle

function LedToggle($pin, $toggle)
	if ($toggle)
		system("gpio mode ". $pin ." out");
		system("gpio write ". $pin ." 1");
		system("gpio write ". $pin ." 0");
// View Source for HTML

//<button class="btn-block btn btn-success" value="4" name="ledBtn_yellow_on">Yellow Light On</button>


Below example shows how to use a RELAY with raspberry pi & php/python.

Home | Developed by Saqib Khan, Raspberry pi Demo.