Skip to content
Switch branches/tags


Failed to load latest commit information.
Latest commit message
Commit time

I am not responsible for any damage you might cause to your power supply, Raspberry Pi, LEDs or to yourself. 
If you plug a wrong wire into wrong pin, you might fry your RPi.   



What you will need


This class was written for one reason: easy usage of RGB LEDs with Raspberry Pi. Should be easy to use, and each function has a simple help section to it.

This class was written to be used in conjuction with PiBlaster ( PiBlaster creates a special file in /dev/pi-blaster, and any application can write to it, meaning you don't have to be root to control the LEDs.

Using this class is completely free, but you can buy me a cup of coffee if you want. But that is completely optional. I did this for fun and education.

Click here to lend your support to: LED-controller PHP class for Raspberry Pi and make a donation at !

This project is licensed under MIT License, which pretty much allows you to do what you want with the code, but requires you to include a license and copyright notice.

Simplest usage would be:

require "class.rgbcontrol.php";
$led = new LedControl(18,23,24); # GPIO Pins on RPi
$led->setHex("#FFF000"); # Will provide yellowish color.

However, I've included a all-in-one package which requires nothing else but you setting up the RPi and connecting the LEDs correctly. It's even paired with a "remote" that you can access directly from your browser.

What you will need:

  • Raspberry Pi, preferably model B(+), as it has more RAM.
  • 3 TIP120 transistors, which can be found on ebay for about 1€ for five (including shipping)
  • RGB LED (strip)
  • Hookup wire (can be bought from ebay for about 1€)
  • Jumper wire (can be bought from ebay for about 1€)
  • DC power supply (anything with high enough amp rating. 5M of 12V 5050 RGB LEDs draw about 6A of power).


Setup a LAMP server if you haven't already, Digital Ocean has a good tutorial about that. Having PHPMyAdmin installed can also help later on.

Assuming you're running Raspbian:

sudo apt-get update
sudo apt-get install autoconf
sudo apt-get install unzip
cd pi-blaster-master
sudo make install

Then you need to wire it up, like this (photo credit to

Raspberry Pi Wiring

After you've done that, you might as well try it out! Try running echo "18=1" > /dev/pi-blaster into shell and see if anything lights up!

If it does, here's the rest if you couldn't figure it out yourself.

Assuming your www directory is /var/www/:

cd /var/www/
mv rpi-php* led-controller
php /var/www/led-controller/sample.php

Then navigate to your RPis IP address, for example,, and see if a manly color lights up!


A PHP class to be used in conjuction with PiBlaster for easy RGB LED control using a Raspberry Pi.




No packages published