Web Controllable Christmas Lights using Raspberry Pi and RGB LED Strip

Published October 23, 2023

This is a blog post on how to set up web controllable Christmas lights. You can change our Christmas lights at https://aruljohn.com/christmas/. We used SMS 5050 5 meter long RGB strip lights.

I've wanted to set up our own web controllable Christmas lights using our Raspberry Pi since 2012. And we finally did it. We used a 5 meter RGB LED strip (analog).

This is what our lights look like - the word JOY. You can also watch a demo video here.

Arul's Raspberry Pi Christmas Lights RGB LED Web Controllable Lights, up and running since 2013

What you need:

  • Raspberry Pi Model B version 1: Bought it from MCM Electronics in February 2012 {pre-ordered}. Cost: $40.
  • RGB LED Strip, 5 meters, with 12V power supply: Bought it from Amazon. Cost: $25.
  • Female-Female jumper wires: Bought them from MCM, but they cost lesser from Amazon.
  • Male-Male jumper wires: Bought them from MCM, but they cost lesser from Amazon.
  • Half Breadboard: Bought this from Adafruit. Cost: $5.
  • Male DC Power adapter: Bought this from Adafruit. Cost: $2.
  • Three MOSFET Transistors TO-220 (MOSFET N-Channel 60V 16A): Bought them from digikey.com. Cost: $0.95 each.
  • Sticky tape: Bought this from Staples. Used for securing the LED strip light on the window.

If your analog RGB LED strip does not come with a power supply, buy a 12V power supply because the Raspberry Pi cannot power it from its GPIO.

There are different N-Channel MOSFET transistors out there, but this TO-220 was recommended because at 5 meters and 300 LEDs, the resistance would be 1 Amp per transistor. These can handle up to 16 Amps of continuous current.

Schematic Design and Connections

Use my Fritzing schematic for reference.

Arul's Raspberry Pi Christmas Lights RGB LED Fritzing schematic design

Begin with a blank half breadboard. The MOSFET transistor has from left to right, pins referred to as Gate, Drain and Source. Stick the MOSFETs into the breadboard.

Connect the MOSFET Source pins to the negative rail of the breadboard.

Connect the first MOSFET Drain pin to the red colour of the RGB LED strip, the second MOSFET Drain pin to the green colour of the strip and the third to the blue colour of the strip. Connect the black colour of the strip to the positive rail of the breadboard.

MOSFETs Connecting the cables to MOSFETs

We need to connect the GPIO pins. We will use GPIO 17 for red, GPIO 18 for green, GPIO 22 for blue. Connect the first MOSFET Gate pin to GPIO 17, the second MOSFET Gate pin to GPIO 18 and third MOSFET Gate pin to GPIO 22. Connect GND to the negative rail of the breadboard.

MOSFETs Connecting the cables to GPIO pins

Connect the DC power jack to the negative and positive rails of the breadboard. The other end of the jack goes into the 12V power adapter.

MOSFETs Connecting the DC power jack

Double-check your connections, and then test the LED strip with the Raspberry Pi. We'll use pi-blaster to enable PWM pins on the GPIO pins.

Software Setup with the Raspberry Pi

If you've not already installed pi-blaster, here are steps to install:

  1. Login to your Raspberry Pi.
  2. Run this:
sudo apt-get install autoconf
sudo apt-get install git
git clone https://github.com/sarfata/pi-blaster
cd pi-blaster
./autogen.sh
./configure
make
sudo make install

To test pi-blaster and get green on, remember green is GPIO 18.

echo "18=1" > /dev/pi-blaster

Green on RGB LED strip

To get purple (blue+red), enable blue (GPIO 18) and red (GPIO 17).

echo "18=1" > /dev/pi-blaster
echo "17=1" > /dev/pi-blaster

And, you'll get purple.

Purple on RGB LED strip

To add one of more colours with varying percentage, change the value of PWM, like this:

echo "22=1" > /dev/pi-blaster
echo "17=0.5" > /dev/pi-blaster

You could end up with violet (more blue, less red).

To turn off GPIO 17, this is what you'd do:

echo "release 17" > /dev/pi-blaster

Python script to set colour to purple-ish:

import os

os.system('echo 17=1 > /dev/pi-blaster')
os.system('echo 18=0.5 > /dev/pi-blaster')
os.system('echo 22=0.5 > /dev/pi-blaster')

Python script to set the colour to black / no colour:

import os

os.system('echo 17=0 > /dev/pi-blaster')
os.system('echo 18=0 > /dev/pi-blaster')
os.system('echo 22=0 > /dev/pi-blaster')

If everything works fine and the LED strip glows up correctly, let's move on to the web part.

Creating the Web Application

I ~have~ had a simple webpage at https://arul.mobi/christmas/ that receives all the web requests and sends JSON requests to a Python Flask application running on Raspberry Pi, sitting at home.

This is the flow:

User โ˜ƒ -> {user-facing webpage} https://aruljohn.com/christmas -> {back-end web service} raspberry pi

This is sample code for the user-facing webpage.

This is sample code for the Python Flask app running on the Raspberry Pi.

You can get the whole code on my Github account:

https://github.com/aruljohn/RaspberryPi-Christmas-Lights-RGB-LED

Arrange the LED strip in your design

When everything is done, arrange the LED strip in any design you want. The strip is quite flexible, but don't force it to bend too much. There are ways to cut the strip and reconnect using cables (and a little soldering), but that's not covered in this post.

My wife designed the LED strip as the word JOY. This is what it looked like.

JOY on RGB LED strip

Demonstration Video

Questions

  • Colours don't display exactly as the colour hex code

Yes, that happens with the cheap analog RGB LED strip. Depending on quality of the RGB LED strip, you may find #a4c639 showing the same colour as #a8d7e9.

  • How do I get the lights fade individually or colour individually?

You'll need a digital RGB LED strip to individually address each LED. Look in Adafruit. Be warned that they are far more expensive than the analog RGB LED strip.

  • What if I want to light up multiple 5m LED strips?

The easiest way is to get a 16-Channel 12-bit PWM/Servo Driver (PCA9685) board from Adafruit. you can control up to 16 PWM outputs.

References: Most of the hardware information here is from RaspberryPi.org forum, Adafruit and StackOverflow.

Related Posts

If you have any questions, please contact me at arulsutilities@gmail.com. You can also post questions in our Facebook group. Thank you.

Disclaimer: Our website is supported by our users. We sometimes earn affiliate links when you click through the affiliate links on our website.

Last Updated: October 23, 2023.     This post was originally written on January 04, 2015.

Comments

gravatar

Your email address will not be published. All fields are required.


gravatar
Arul wrote on 2016-12-09 14:20:00
Hi @pinkyblitz:disqus, the 12V power supply powers the lights. It connects to the jack from the other end.
gravatar
PinkyBlitz wrote on 2016-12-02 17:49:00
Tell me if I am wrong but the key to understanding is the male connector on the DC power supply.
gravatar
PinkyBlitz wrote on 2016-12-02 16:01:00
Cannot understand how to connect to the power supply from the pictures.
gravatar
PinkyBlitz wrote on 2016-12-02 15:59:00
I don't understand how to connect to the power supply with wires from pictures. I want to be able to show this to my students and I think this would be neat project.
gravatar
Arul wrote on 2016-03-18 09:00:00
Hello Danilo, the MOSFET I'm using is this one.http://www.digikey.com/product-search/en?keywords=497-2765-5-ND
gravatar
Danilo Dene wrote on 2016-02-17 20:31:00
Hi, can you share exactly the name of mosfet ? and datasheet ? I`m trying to switch a relay using mosfet (using raspberry Pi), but the gate voltage of my mosfet (FQP33N10) is around 4 v. Can you help me ?
gravatar
Arul wrote on 2015-12-19 15:18:00
Great! Thanks, Desire!
gravatar
Dรฉsirรฉ BANSE wrote on 2015-12-15 17:54:00
Thank you Arul ! It works great.
gravatar
Arul wrote on 2015-12-02 21:47:00
Hello Desire, yes, it will work. However, it doesn't include the 12V power supply and you'll have to buy it separately. Here's the link to the the exact LED strip that I bought. It includes the power supply and a remote as well (not needed, but useful if you're trying to see if it works).http://www.amazon.com/gp/product/B00ASHQQKI
gravatar
Dรฉsirรฉ BANSE wrote on 2015-12-01 16:37:00
@aruljohn:disqus , would this http://amzn.com/B00DTOAWZ2 LED strip work with your setup ? Thank you.
gravatar
Arul wrote on 2015-10-18 21:43:00
Yes, but beyond a point, it will serve pages slower. Remember that the Raspberry Pi runs off your SD card, so there are limited reads/writes.
gravatar
Amandine wrote on 2015-10-09 02:26:00
Can the Raspberry Pi be able to stand heavy traffic?
gravatar
Arul wrote on 2015-09-18 19:45:00
Hey Gรกbor, yes, you can definitely do that. However, the Raspberry Pi may not be able to stand heavy traffic. It may also be slow because of the SD card. That's why I personally prefer to use my VPS web server as the front-facing server.
gravatar
Gรกbor wrote on 2015-08-25 09:27:00
Hi Arul, Is it possible to run the webpage from the rpi ?it would be better if i can reach the page from outside my home network. any advise ? thanks a lot, Gรกbor
gravatar
Arul wrote on 2015-04-09 16:01:00
I'm not sure whether it's safe on 10m, but for longer than 5m or multiple strips of 5m, I would personally use a PWM/servo driver like PCA9685.
gravatar
Alex Jenkins wrote on 2015-03-08 08:51:00
would this be ok to use on a 10m strip of RGB lights?
gravatar
BrianG wrote on 2015-01-12 13:54:00
If you want to make one I have the two boards I used. The PCB for the LEDs is $8 (you supply components) and the Save My Pi board you can buy through eBay or from me (I bought 10 for one of the classes).
gravatar
Arul wrote on 2015-01-12 12:54:00
Yes! And, I just checked the December issue of TheMagPi. I remember reading your article about the traffic light board a few days ago! It's a good article. :)
gravatar
BrianG wrote on 2015-01-12 11:33:00
You are correct. So now you know something about me.Look in the December issue of The MagPi magazine - I have an article (but the photo is not by best).
gravatar
Arul wrote on 2015-01-12 10:47:00
Hi Brian, that would be great! Please let me know if you need any help.And, does SDG mean Soli Deo Gloria? Just wondering. :)
gravatar
BrianG wrote on 2015-01-10 13:23:00
I will adapt this project to the RPi classes I conduct at the science museum I work for (www.scienceandhistory.org). However, I'll be using Python instead of Perl or Ruby. BTW Arul, if I include this personal greeting, SDG, do you know what it means? :-)