PHPackages                             piphp/gpio - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. piphp/gpio

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

piphp/gpio
==========

A library for accessing the GPIO pins on a Raspberry Pi

0.4.0(5y ago)4325.9k↓50%41[6 issues](https://github.com/PiPHP/GPIO/issues)[2 PRs](https://github.com/PiPHP/GPIO/pulls)2MITPHPPHP ^7.3||^8.0

Since Dec 13Pushed 5y ago20 watchersCompare

[ Source](https://github.com/PiPHP/GPIO)[ Packagist](https://packagist.org/packages/piphp/gpio)[ RSS](/packages/piphp-gpio/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (14)Used By (2)

PiPHP: GPIO
===========

[](#piphp-gpio)

[![License](https://camo.githubusercontent.com/67b66102f6d339528576b09143696ba895a7927b2f91f0430c00ef37e28487e3/68747470733a2f2f706f7365722e707567782e6f72672f70697068702f6770696f2f6c6963656e7365)](https://packagist.org/packages/piphp/gpio)[![Total Downloads](https://camo.githubusercontent.com/4ea6571bded57bec81cbba70b350f9ea8f9ccabde840770ba163c8c7b71d159f/68747470733a2f2f706f7365722e707567782e6f72672f70697068702f6770696f2f646f776e6c6f616473)](https://packagist.org/packages/piphp/gpio)

A library for low level access to the GPIO pins on a Raspberry Pi. These pins can be used to control outputs (LEDs, motors, valves, pumps) or read inputs (sensors).

By [AndrewCarterUK ![(Twitter)](https://camo.githubusercontent.com/6bdedfb2ec11bea20e0fb9720641fd26240465c2361f25955ca995df499d5d20/687474703a2f2f692e696d6775722e636f6d2f77577a583975422e706e67)](https://twitter.com/AndrewCarterUK)

Installing
----------

[](#installing)

Using [composer](https://getcomposer.org/):

`composer require piphp/gpio`

Or:

`php composer.phar require piphp/gpio`

Examples
--------

[](#examples)

### Setting Output Pins

[](#setting-output-pins)

```
use PiPHP\GPIO\GPIO;
use PiPHP\GPIO\Pin\PinInterface;

// Create a GPIO object
$gpio = new GPIO();

// Retrieve pin 18 and configure it as an output pin
$pin = $gpio->getOutputPin(18);

// Set the value of the pin high (turn it on)
$pin->setValue(PinInterface::VALUE_HIGH);
```

### Input Pin Interrupts

[](#input-pin-interrupts)

```
use PiPHP\GPIO\GPIO;
use PiPHP\GPIO\Pin\InputPinInterface;

// Create a GPIO object
$gpio = new GPIO();

// Retrieve pin 18 and configure it as an input pin
$pin = $gpio->getInputPin(18);

// Configure interrupts for both rising and falling edges
$pin->setEdge(InputPinInterface::EDGE_BOTH);

// Create an interrupt watcher
$interruptWatcher = $gpio->createWatcher();

// Register a callback to be triggered on pin interrupts
$interruptWatcher->register($pin, function (InputPinInterface $pin, $value) {
    echo 'Pin ' . $pin->getNumber() . ' changed to: ' . $value . PHP_EOL;

    // Returning false will make the watcher return false immediately
    return true;
});

// Watch for interrupts, timeout after 5000ms (5 seconds)
while ($interruptWatcher->watch(5000));
```

Further Reading
---------------

[](#further-reading)

SitePoint published a tutorial about [powering Raspberry Pi projects with PHP](https://www.sitepoint.com/powering-raspberry-pi-projects-with-php/) which used this library and shows a push button example with a wiring diagram.

More Resources
--------------

[](#more-resources)

PiPHP maintains a [resource directory](https://github.com/PiPHP/Resources) for PHP programming on the Raspberry Pi.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity44

Moderate usage in the ecosystem

Community26

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 69.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~171 days

Recently: every ~377 days

Total

11

Last Release

2093d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/6e7abce428a9dc9c76f4275ca8d8d11ad55138d72f3e3e2b01c6b2da5b479cc0?d=identicon)[AndrewCarterUK](/maintainers/AndrewCarterUK)

---

Top Contributors

[![AndrewCarterUK](https://avatars.githubusercontent.com/u/6486835?v=4)](https://github.com/AndrewCarterUK "AndrewCarterUK (69 commits)")[![svpernova09](https://avatars.githubusercontent.com/u/967362?v=4)](https://github.com/svpernova09 "svpernova09 (26 commits)")[![IonBazan](https://avatars.githubusercontent.com/u/1985514?v=4)](https://github.com/IonBazan "IonBazan (2 commits)")[![Sam-Burns](https://avatars.githubusercontent.com/u/6594039?v=4)](https://github.com/Sam-Burns "Sam-Burns (1 commits)")[![tomsseisums](https://avatars.githubusercontent.com/u/1030080?v=4)](https://github.com/tomsseisums "tomsseisums (1 commits)")

---

Tags

pinGPIOraspberrypinspi

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/piphp-gpio/health.svg)

```
[![Health](https://phpackages.com/badges/piphp-gpio/health.svg)](https://phpackages.com/packages/piphp-gpio)
```

###  Alternatives

[ronanguilloux/php-gpio

GPIO-related utils &amp; toolkit PHP library

2678.0k](/packages/ronanguilloux-php-gpio)[lkallas/estonianpin

A simple library for processing Estonian Personal Identification Code (isikukood).

1615.7k](/packages/lkallas-estonianpin)[welp/ical-bundle

Symfony Bundle to manage .ics iCal file (creating and eventually reading)

10114.3k](/packages/welp-ical-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
