Mood lighting with Raspberry Pi
Mood lighting or ambience lighting refers to using different colors of light to create an ambience reflecting a particular mood. With incandescent or CFL bulbs, mood lighting was very restrictive - color of the light would be restricted to the color of the enclosure of the bulb. However advent of RGB (Red Green Blue) LEDs has opened up a new dimension in mood lighting. A good example is Philips Hue (http://www2.meethue.com/en-xx/). Not only one is not restricted by the color of the enclosure, one gets a choice of colors not previously possible which can be dynamically changed too!!
If you don't want to invest in a proprietary solution, here's one way to achieve the same using RGB LED strip and RPi.
A typical RGB strip needs 12V. However, RPi provides only 3.3V at the GPIO pins. Hence we need a bridge between these two circuits. A ULN2803 chip acts as this bridge - it takes TTL input and allows one to drive a high voltage circuit.
We will use raspberry-gpio-python to control the GPIO from python (v2.7). We will write a simple webserver which will take color hexcode as a query string and apply Pulse Width Modulation (PWM) to generate the same at RPi output.
Install raspberry-gpio-python package
Download tar from http://sourceforge.net/p/raspberry-gpio-pythonIn a different directory, create two files pwm.py and server.py as listed below.
tar xvf RPi.GPIO-0.5.11.tar
sudo python setup.py install
Since we will be handling low level IO functions, we need to run this server as root.
Now we can use curl to change the color as we want by passing color hexcode in argb format (1 byte each for alpha, red, green and blue). e.g. to get red color, use
Or use a browser: