Introduction: Raspberry Pi Christmas Tree

About: Software engineer and open source enthusiast

Have you ever wanted to have full control of your Christmas lights? This tutorial will reveal the exact steps for making a Christmas tree powered by a Raspberry Pi, ANAVI Light pHAT and a cheap 12V RGB LED strip. This is definitely not the cheapest solution for a holiday decoration but it is fun and an efficient way to practice your programming skills.

Step 1: Required Hardware

To build the Raspberry Pi Christmas tree you will need:

  • Christmas tree
  • Raspberry Pi (any model or version of Raspberry Pi with 40 pin header)
  • ANAVI Light pHAT
  • 12V RGB LED strip
  • USB Power Supply
  • 12V Power Supply with DC jack 5.5x2.1mm
  • MicroSD card with Raspbian

You can use any 12V RGB LED strip. Select the length of the strip corresponding to the size of your Christmas tree. These 12V RGB LED strips are a commodity. They are very affordable and easy to find. In this video I am using 1 meter long strip with 30 LEDs in it.

Step 2: Assemble the Hardware

Assemble the hardware with your bare hands. Attach the RGB LED strip to ANAVI Light pHAT using a screw driver and boot the Raspberry Pi as shown in the video.

ANAVI Light pHAT is an open source hardware Raspberry Pi add-on board specially designed to control colors the low cost 12V RGB LED strip via three MOSFETs. Using it is very easy to build the project in just a few minutes.

Step 3: Install PiGPIO

On your Raspberry Pi open a terminal and install the latest versions of piGPIO and Git by typing the following commands:

sudo apt-get update
sudo apt-get install -y pigpio git

Step 4: Get the Source Code

The demo application for controlling the 12V RGB LED strip is free and open source. It is available at GitHub. Execute the following command in the terminal to get the source code:

git clone 

Step 5: Build the Application

Execute the following command in a terminal to build the demo application:

cd anavi-examples/anavi-light-phat/light-demo

The demo application is written in the C programming language. It creates a software defined pulse-width modulation to set the color of the RGB LED strip through the three MOSFETs on ANAVI Light pHAT.

On every second the program sets a random value in the range from 0 to 255 of each of the three main colors. The total combination make more that 16 million colors! Although the color is determined randomly, the source code is written in a way to increase the chances that one of the three main colors is brighter than the others.

Step 6: ​Launch the Application

Execute the commands below to start the application:

sudo pigpiod

The demo application runs an infinite loop. To terminate it the user has to press simultaneously on his keyboard Ctrl and C.

That's it! Enjoy the holidays and happy hacking!

LED Contest 2017

Participated in the
LED Contest 2017

Raspberry Pi Contest 2017

Participated in the
Raspberry Pi Contest 2017