Happy Holidays!!

After a bit of a scramble late last week, we were able to get v1.0 of the Makerspace sign up at my sons’ middle school Friday morning!

This is the conclusion to the project I mentioned before  (Music and Lights), where an Arduino was used to drive a small speaker and some LEDs.  My initial code was done to play Imperial March (from Star Wars) and Super Mario Bros Overworld Theme.  But the kids would hopefully take it from there and make it their own.

It’s Time to Play the Music…

One of the kids with his dad’s help was able to extend my code to include many more measures of Jingle Bell Rock.   The Arduino code, written in C, was written in a way to make it easy to play any song (single tone at a time).  For example, the first line of the tune:


Looks like this in the code:

// Jingle Bell Rock
int bpm = 120;
int song[100][2] = {

Basically it’s a  2-dimensional array where the entire song is in braces { } where each ‘note’ is a pair of values indicating the note/tone and duration.  Given that it’s single tone music, generally you want to hit only the highest note for each beat to play out the tune.

There are 8.5 octaves of notes available, starting with the lowest at C0 going up through C1, C2, … C7, to the highest at C8.

All 12 pitches of the chromatic scale are represented as follows:

      Cx, Dbx, Dx, Ebx, Ex, Fx, Gbx, Gx, Abx, AAx, Bbx, Bx, …

Where x represents the octave.  NOTE: Lowest note is C0, highest is Eb8.

Note also that the A is represented here by ‘AA’ since A0, A1, etc. are reserved terms in Arduino code-land (represent names of external pins).

A rest is represented by an R (no sound).

Note durations are represented with the following symbols:

  • W = whole note
  • H = half note
  • Q = quarter note
  • E = Eighth note
  • S = Sixteenth

You can represent any other fractions of time simply by writing as an equation in the code, e.g. {C6, Q+E}.

It’s Time to Light the Lights…

Now that we had a tune, we had to decide what our light show would look like.   We had wanted to use Christmas lights controlled by the Arduino.  I decided for simplicity to use an off the shelf relay board (SunFounder 2 channel 5V relay shield) that could be driven by the 5V Digital I/Os.

61bL8+Rf9IL._SL1000_Generally you can use a relay to help you control something high-power or high-voltage like 120V AC electricity with low-voltage, low-power electronics.   Relays have been used in everything from cars to sprinkler systems, having started out from the telegraph.

We decided in the end for simplicity to use 2 sets of lights alternatively blinking for our ‘light show’.  This made my job that much easier.

Hijacking the plugs off an old strand of lights, where one of the wires goes ‘straight through’ connected via a twist-on wire connector and the other wire goes through the relay, here is the setup for controlling 1 set of lights:


Relay set to control one string of lights.

Connecting up the Arduino to the relay involves connecting the 5V outputs previously used to drive LEDs now to drive the input lines on the relay board associated with the light strand we wanted to light.   Due to inverted logic used by the relays, instead of driving a HIGH like we did before with LEDs, the relays now would need to be driven LOW in order to ‘activate’ (connect the lights).

IMG_20141212_073755(Yes, my engineer friends will tell me that if I had connected to the ‘normally closed’ ends of the relay then I probably could have left the drive logic alone, but as a Test Engineer at Freescale who has driven relays in this way for 10+ years, old habits die hard.  Besides for safety reasons just felt that lights should be normally off when the system wasn’t powered).

With the kids we worked out roughly which notes we wanted to light which lights.

IMG_20141212_073731 IMG_20141212_073733

Then the kids made a couple of signs, one of which would house the Christmas lights and our holiday message.

It’s Time to Raise the Curtain…

Will share the code and hookup in a future post (stay tuned for the link).

The cool part is that hopefully with this setup we’ll be able to get the kids a bit more hands-on with the code in the spring!   Wonder what song they’ll think up to do next…


Statler: That was a real wire act.
Waldorf: On this show, everything’s a wire act.
Statler: Why’s that?
Waldorf: Because, you keep asking “Wire they doing it?”

Bookmark the permalink.

Comments are closed