Go Caroling with a Raspberry Pi, LED Lights, and Jingle Bells 💡🔔🎄🛷
Step by step instructions to set up and program a Raspberry Pi to light up to Jingle Bells
Growing up, I looked forward to the time off from school the minute I filled my backpack and returned to class in the fall. Everything about winter break was the best: no school, family, parties, friends, no school, presents, games and yeah, no school.
One of my favorite parts of the holidays was jigsaw puzzles with my mom. We’d set up a card table in the living room and constantly have a jigsaw puzzle we would work on together.
Now as a mom myself I carry the same tradition on with my kids. Okay, well, not the jigsaw puzzles, but the family time over the holidays doing an activity together. Some years the table is filled with Legos the entire break. Other years, it’s board games with an impromptu Exploding Kittens tournament. This year, we are learning to build and create.
I love all that you can do with a Raspberry Pi and the simplicity it brings to how computers work. They help remove any intimidation kids (and adults) feel looking at a large computer, wondering what all the pieces do and how the code we write makes the computer pieces do the things we code them to do.
To get you and your family started, here is a Raspberry Pi Jingle Bell project for your winter break family time.
There are so many add-ons for the Raspberry Pi, but the goal here is to start simple and get comfortable with how and why it works. For this project, you will need three products, or equivalent parts if you already have some or would like to pick them up separately:
Raspberry Pi Kit
The one I used in this exercise is the CanaKit Raspberry Pi 3 B+ w/ 2.5A Power Supply that has built-in WiFi. Earlier models are still available but may require a separate USB WiFi adapter. This just adds some convenience when you start working with the Pi. Currently (at the time of writing), the Raspberry Pi 3 B+ is less than $50 on Amazon, comes with the power adapter and the additional bits you need so that you can use the Pi for lots of different uses.
I picked up the UNIROI Breadboard Kit with Arduino Raspberry Pi Breadboard Holder, as having the holder makes it all way more convenient and it came with the wiring, lights, and resistors needed for this project. At about $13 on Amazon, it seemed a better deal than ordering lots of various parts at larger quantities.
Micro SD Card
The Raspberry Pi does not come with any storage. It is built to load from a Micro SD Card. I recommend nothing smaller than 32GB so that you have plenty of space for the operating system and additional files you will be creating through all your projects. You can usually find these for under $10.
Beyond these items you will need:
- USB mouse
- USB keyboard
- HDMI monitor
- A device that can read/write to a micro SD card
Nothing special in regards to these items. The Raspberry PI will have 1 HDMI port for the monitor and USB ports for you to use for the mouse, keyboard, and anything else you might want to create beyond this project. The micro SD card reader will be needed to install the operating system for the Pi on to it from a different computer or laptop.
- CAREFUL! We will be using the wires to create electrical circuits. Feel free to experiment but pay attention to where you are plugging the wires in to avoid short-circuiting the Pi. Cause once that happens its game over.
- Wires get plugged into the breadboards first before you plug them into the Raspberry Pi. This is so you don’t have an exposed pin carrying electricity which increases the chances of short-circuiting the Pi.
- Don’t touch the pins of the Pi with metal or it will ☠️.
If you ordered the breadboard kit linked above it comes with a holder. If you are using your kit for the first time take a minute to attach the Raspberry Pi and the breadboards to the holder.
1. Gather up all the items you will need for this project
- Raspberry Pi and breadboards (attached to the holder if you have it), including the power adapter and switch
- (5) jumper wires; one end pin and the other end receptacle (also referred to as male/female) — these will be used to carry electricity and signal from the Raspberry Pi to the breadboard
- (4) jumper wires; pin at both ends (also referred to as male/male) — these will be used to carry the same signal to lights of the same color
- (7) resistors — used to reduce the amount of current flowing through a part of the circuit; since our LED lights need minimal current to light we don’t want to overpower them and burn them out, resistors keep that from happening.
- 2 red LED lights
- 2 green LED lights
- 2 yellow LED lights
- 2 additional LED lights of any color (for this example I used 1 blue and 1 purple)
2. Download and set up the operating system for the Pi
Since the Raspberry Pi uses the micro SD card for storage, this is where we need to install our operating system. To do this we need to use a different computer or laptop with a device that can read/write to the micro SD card.
There are several operating systems, but the most popular and one we are using in this project is Raspbian. To get this installed we need to download two applications:
- Raspbian operating system for the Pi, specifically the
Raspbian Stretch with desktop and recommended software version (link to download page)
- Etcher, an application we need to install Raspbian onto the micro SD card
Both sites provide great instructions on completing the download and install. Follow the steps they provide. When complete your micro SD card will have the Raspbian operating system installed on it and you can insert that into your Raspberry Pi.
3. Plug it all together
Start by plugging your power adapter into the wall and then into the switch. Then take the plug for the switch and plug it into the micro USB port on the Raspberry Pi. Get your monitor, mouse, and keyboard all connected to the Raspberry Pi. Turn it all on, watch it boot up and you are in business.
Creating the Circuit
Each pin on the Raspberry Pi has a function. With your kit, you will find a card with the mapping of each key. You will need that to help guide you through which pins we will be utilizing for this project. If you don’t have it, here is a mapping of each pin and its function:
1. Power up the breadboard
Take a male/female jumper wire. Plug the pin into the positive side of the breadboard. Once plugged in, attach the receptacle end to pin 1 on the Pi. This will bring power to just that quarter of the breadboard.
To take power to the other side of the breadboard grab a male/male jumper wire, plug an end into the positive side of the portion with power to the positive side of the board you want to take power to.
2. Use resistors to bring the power to the rows.
Use the resistors to power each of the rows we need for the lights. The breadboard kit comes with super long resistors. I found it easier to trim them down to an easier length so they sit neatly at the surface of the breadboard. Put one pin of the resistor into the positive/power side, and the other into the row we are going to power up for a light.
3. Add LED bulbs to the breadboard
The LED bulbs have 2 pins: cathode (negative) and anode (positive). The anode (positive) pin is easy to identify as it is longer than the other. We are going to plug that pin into the row we powered, and the cathode (negative) pin into the next row that has no power.
The sequence I went with was red, yellow, green, red, yellow, green and the two other colored bulbs at the end.
4. Connect GPIO pins to each color light
There are several GPIO (General Purpose Input/Output) pins on the Raspberry Pi. These are used to send and receive data through the breadboard. What we will be using them for is to complete the circuit we have created for each colored light. When the circuit is complete the light will turn on. When the circuit is broken the light is off.
If you look on your Raspberry Pi pin mapping card you will see all the GPIO pins. We are going to use four of them for this exercise, one for each color light. Remember, to plug your jumper wire into the breadboard first before you plug into the pin on the Pi.
Take your 4 remaining male/female jumper wires. Plug one into the row with an LED cathode (negative) for red. Another for yellow, green and the last one plug into the LED cathode (negative) for the multi-colored lights.
For the example here I used the following pins:
- Pin 7 to the multi-colored lights on the right (gray wire in the example below)
- Pin 11 to one of the LED cathode (negative) row for the green light (black wire in the example below)
- Pin 13 to one of the LED cathode (negative) row for the yellow light (green wire in the example below)
- Pin 15 to one of the LED cathode (negative) row for the red light (purple wire in the example below)
5. Connect the red, yellow and green lights to their pair
For this example, we want to control the same color light with one GPIO wire. Since we have already wired one of the lights up we need to take a jumper wire and connect both LED cathode (negative) rows for each colored light.
To do this, take your remaining 3 male/male jumper wires. Put one end in the same row that the GPIO is plugged into. Put the other end into the LED cathode (negative) row for the light of the same color.
Set up complete! 🎉
You have completed all of the set up you need for this project. Now is time to move to the code and get these lights flashing.
There are several programming languages you can work with on a Raspberry Pi, but Python has been the runaway favorite to use and has plenty of supporting libraries to make development pretty straightforward. This is what we will be using to get the lights flashing to Jingle Bells.
The code below is ready for you to copy and paste to get your lights flashing to Jingle Bells immediately. Notice the variables at the top of the file to hold the pin numbers. These relate directly to the GPIO pins we connected to the breadboard to control our lights.
The goal here is for you to see it run and make it your own. Play around with the amount of time the lights are lit or stay off. Print text out differently. The best way to learn is to break it. Don’t be nervous to mess it up. If there is a syntax error, the Python terminal will tell you and give you the line number. If you don’t know how to get it all working again, just copy/paste the sample code again and you are in business.
Getting this code running on your Pi
- When your Raspberry PI boots up, click on the raspberry in the upper left to reveal the options menu.
- Select Programming from the menu.
- From the Programming menu select Python
- This will load up the shell the Python script will run in. We are going to save our code as a file, so from within this terminal click File in the top menu. Within the File options select New.
- This will bring up an editor for you to build your Python script. Enter the code you see above.
- Once your code is entered, save your file. You can give it any name you wish but best to stay simple and use one or two words. Give it the file extension of .py (example: jingle-bells.py)
- You can then tell it to Run Module from the menu or just press F5 on your keyboard.
- Within the Python terminal, you will see the code execute and the lights blink on the breadboard.
You are now a Raspberry Pi, Jingle Bell singing master!
Not only have you learned about the components of a Raspberry Pi, you learned a bit about electricity, circuits, created a Python script and probably sung Jingle Bells about a dozen times. You’re welcome. 😄
Now it’s your turn to continue exploring, building and creating. Raspberry Pis are a great hands-on way to get familiar with all the bits of technology. Gather up the family and enjoy some time together seeing what all you can create this holiday break. I encourage you to try new ideas, see what the other pins on the Pi can do, change the code to do new things, and explore fun ideas you have as a family.
Ideas To Try With Your Family
Google is a great resource to find all kinds of projects you can build with your Raspberry Pi. There are countless devices you can get to plug into your Pi and board. Here is a quick list of what my family is looking forward to creating this holiday break:
- Challenge: Currently, the 2 multi-colored LED lights share the same electrical current to illuminate. How can you rewire what you have to keep those bulbs lighting at the same time but not sharing the same current without adding another pin?
- Change the code to configure the lights to blink the tempo of a different song.
- Instead of printing out the lyrics to Jingle Bells in the Python terminal, have them display out to an OLED display.
- The Raspberry Pi has an audio jack. Set it to play the audio Jingle Bells while the lights flash.
- Create a measuring device with the OLED display and a distance sensor.
- Order an additional micro SD card and install the Retro Pi operating system onto it so that you can use it to convert your Pi into a retro gaming system (will require controllers to play games).