How many times have you heard a song - on the radio, during a movie, or at a concert - and thought "Man I wish I could play that"? Now you can! This project allows you to learn a song note by note on the piano by lighting up appropriate LED lights that correspond to each individual key on the piano. In fact, even if you don't have a piano but have a smaller electronic keyboard, you can customize it for that. Some electronic keyboards actually have light-up keys for just this purpose, but doing it on a real piano is so much more satisfying. Have fun, and learn some songs!
The three main components of this project (like many) are:
2) Hardware (non-electronic)
3) Electronics and Wiring
Although they're separate parts of the project, in reality you'll frequently be working on more than one at a time simply because how you decide to do one part affects how you'll do another. A good thing about doing them in parallel, however, is that you keep the big picture in mind and if you get tired of writing code, you can design your acrylic parts, and if you're tired of the computer altogether you can wire up some resistors and LEDs and have some fun with that. The parts are in a specific order in the Instructable, but how you do it is up to you.
The biggest question when I started out was "How the heck do you individually control 88 LEDs?!?!" Fortunately, after some research I found some chips designed to do just that and some Arduino tutorials and code that helped along the way. Aside from that question, everything else was fairly straightforward or at least only required me to pick from several options - what to make the strip out of, how to hold the LEDs in place, how to write the code to make it all run, and so forth. Let's talk about the big question in a little more depth so you have an idea of how it all works before you get started.
The chips I got are LED matrix (or 7 segment display) drivers, which means that as far as the chip is concerned, we have our LEDs wired as if they're in a square grid, with a certain number of rows and columns - the positive terminals are common in each column, and the negative terminals are common in each row. This allows 64 LEDs (in an 8x8 grid) to be controlled by each chip and only requires three (that's right THREE!!!) control inputs. No matter which or how many of the LEDs you want to turn on, the system can handle it.
But wait, if you want to turn on LEDs (1,1) and (2,2), wouldn't that also light up (1,2) and (2,1), because in order to achieve the original goal all of rows 1-2 and columns 1-2 would have to be on? This is where the clock inside the chip comes in - the LEDs aren't actually on continuously. Rather, they're blinking so fast that the human eye observes them as continuously on. This is how unwanted LEDs can remain off!
So although we see the strip as just a line of LEDs, they're wired as if they're in two square matrices - one 8x8 (first chip) and one 5x5 (second chip), which adds up to 89 keys (the final "row" of the 5x5 matrix only has 4 LEDs, so that brings us down to 88). Voila!
How do we tell the chip which LEDs to illuminate? That's all done using binary numbers. Using some code borrowed from developers online (see the code for the attribution), I created the program in such a way that all you have to do when translating a song is to call the command playKey(...). This plays the given numbered key, starting with 1 on the left and ending with 88 on the right. This command takes the key number and translates it so the chips can do their duty by doing the following: the key number is translated into a row and column number, which is then translated into a row number and a binary number that represents which LED should be on (read from the left, not the right). For example, if I call playKey(13), which is A, the functions translate that as row 2, column 5; then since 2^5 is 32, that would be the number that goes to the chip. Reading from the left, 32 is 00000100, which represents the state of the second row. The same concept applies when we're dealing with lighting up multiple LEDs - it's all about binary numbers! Check out the code for the exact functions and a little more explanation.
Finally, there's a potentiometer attached to it all to control tempo - something really, really important when you have no idea what you're doing...
NOTE: This was not an easy Instructable to write because of how complicated it was to put everything together and make it all work. Don't hesitate to let me know if something is confusing or unclear, or if you have specific questions!
Let's get going!
Step 1: Get All the Components
There isn't one right way to make a strip of LEDs fit nicely and elegantly atop your piano keys, so definitely spend some time and see what cool spins you can put on the idea. Before settling on this design, I bounced around a number of other ideas, some of which would have been uglier and some of which could have been much prettier. My goal was to achieve balance: making something worth leaving on the piano all year long without spending too much time being a perfectionist. I was glad with that decision when I started messing with the electronics and software and realized (as expected) that most of the work up front would be focused on those two things. So see what you can design! Either way, the electronics and software should work regardless of what your strip looks like.
- Arduino (Uno from Adafruit, $30)
- 88 red LEDs (100 pack from Jameco, $10)
- 2 MAX7219 LED driver chips (Jameco, $16)
- 1 potentiometer (had)
- 2 100nF capacitors (had)
- 1 10uF capacitor (had)
- 2 18K resistors (had)
- PCB prototyping board (Jameco, $6)
-- Note - it's good to have a breadboard too, for prototyping and testing electronics
- 2 24 pin sockets (10 pack from Jameco, $2.40)
- spool(s) of wire (had)
- Arduino USB cable
- Arduino wall adapter (LEDs will draw a lot of current)
- small 8x8 LED matrix for debugging code if necessary - it was SO nice to be able to test this way instead of wiring up the entire strip before I knew the software was right. Only "debug" one thing at a time!
- black acrylic 7.5" x 13.5" (TAP Plastics, ~$7)
- acrylic glue (TAP, $7)
- solder (thinner is better)
- zip ties
- a piano!
- laser cutter
- soldering iron
- wire strippers
- wire cutters
- small needle-nosed pliers
- acrylic glue hypo applicator (TAP, $3.25)