Coffee Cup Bells
Code + Schematics available on Github
A little back story on this one…
A while ago, I was at a coffee shop with my boss talking about important work things like paper clips, suits and Wayne Coyne’s gigantic hamster ball. ANYWAYS we must have come in close to closing time because the employees were cleaning up shop and cashing out.
One guy unwrapped a new stack of paper cups to prepare for the next day. Unfortunately, that stack fell to the floor. With a sigh of disappointment, he picked up the scattered cups and proceeded to dispose of them. I couldn’t bear to see the cups go to waste so I dashed after him in a manner illustrated below:
Just as he was about to purge the world of the rejected cups and end evil for all eternity, I intervened and took the cups for myself. I figured I could use them for a project. Here is the result…
As you can see from the video, when a cup is hit, it lights up and plays a certain tone. If you watch closely, you can see that if two cups are hit at the same time, two tones will play. This also applies for more than 2 cups as well (you can play all five simultaneously).
Construction
The project is pretty simple. It uses the Sparkfun Musical Instrument Shield to generate tones and the Lilypad LEDs for lighting. The cups have a strip of tinfoil lined on the inside and a fishing weight covered in tinfoil (the ball) attached to conductive thread:
The tinfoil lining is connected to a 5 V line and bus and the ball is connected to an Arduino input. The ball acts as a simple switch. When the cup is hit, the ball swings and touches the tinfoil lining closing the switch and the input pin is brought HIGH. When the ball swings down, the switch is open and the input pin is brought LOW (with the help of a 4.7k pull down resistor).
The LED is attached to the outside of the cup where a hole is drilled and the LED facing inwards. The +ve lead is connected to an Arduino output pin while the -ve is, of course, connected to the ground bus:
All cups are attached to a dowel rod. They are supported mainly by the 5 V lines which probably isn’t a great idea for support but so far it’s held up pretty well. The other lines twisted onto the 5 V line are the ground, input & output lines.
The 5 V and Ground buses are wires stripped bare and running along the dowel rod. I definitely made sure to keep the two well separated. The 5 V and GND lines in each cup connect to their respective buses. The Arduino provides the voltage and ground.
I’ve added a potentiometer there to act as a volume control for my speaker as tones are played. You can also see that I used cat5 cable to try to make the circuit more tidy.
Programming
The coding wasn’t actually all that tough. The hardest part was to figure out how to play more than one note simultaneously. To achieve this, I set up a system where “blocks” of information are sent per time interval. The microcontroller (uC) polls the cups continuously, checking to see if it on. An array stores info on whether or not a cup has been hit. This process repeats until a certain amount of time has passed – this is when the timer expires. When this happens, the program ships off the array to the tone generation function where the array is processed and tones played (and LEDs lit).
A little word about the arrays. In the program, there are actually two arrays that store on/off information:
- index[ ] stores on/off information for tones. When no cups are hit, all the elements in the array are “0x80” or “stop” in MIDI talk. When a cup is hit, the corresponding element is changed to “0x90” or “play” in MIDI.
- light[ ] stores on/off information for the LEDs. This array is simple. If a cup has been hit, the corresponding element changes from 0 to 1.
So, there are actually two arrays that get passed to the function genTone().
For the MIDI functions, I reused the code written by Rick Winscot (who extended off of Nathan Seidle’s code he wrote for the Music Shield). You can find his code here.
Here’s a video of the bells in more light:
Ending Notes
I remember there was a contest on Instructables that happened a while ago looking for the best use of coffee cups. Too bad I didn’t make this earlier. I have to admit, the winning entry of coffee cake would definitely have my vote!
In hindsight, this project would probably have been better named as “Coffee Cup Chimes” but oh well…
I’m thinking about extending this project a bit further and creating a larger version using maybe 25 or more cups. Of course, there will be some more hurdles to overcome. For now though, I’m just happy it worked. The folks at the coffee shop (who gave me the cups) seemed pretty excited when I showcased it to them.