Having just picked up an arduino starter kit (the ARDX kit from oomlout) i had finished working through the example circuits. I played around with writing some custom code to drive some of the circuits in the kit and had a little fun. I now wanted to design my own circuit and code completely, as that’s really what the arduino is for. Hacking up a circuit and some code for the micro-controller to drive it.
It’s note the biggest leap from the simple switch test circuit and the piezo music circuit to construct a stylophone. So that’s what I did. The results can be seen in this youtube video, and for those interested the following circuit diagram should prove helpful in reconstructing such a project with your own arduino:

Circuit Diagram
Finally the actual code for the arduino is pretty simple, and relies on the known tone durations for the piezo from other experiements. The code can be found below. It basically loops over the input pins (2-9) and checks to see if any are LOW (they are all HIGH by default because of the circuit layout). If one is low, it calls a playTone function for the related note. It will play the tone until the corresponding pin registers as HIGH again (i.e the stylus is removed). The LOW signal is produce by the shorting of the circuit to he GROUND pin via the stylus, rather than the input pin.
Enjoy.
The Code:
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
char notes[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int speakerPin = 13;
void setup() {
for(int i =2; i < 10; i++) {
pinMode(i, INPUT);
}
}
void playnote(int note) {
int tone = tones[note-1];
while(digitalRead(note+1) == LOW) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
}
void loop() {
int note = 0;
for(int i=2; i< 10; i++) {
if (digitalRead(i) == LOW) {
note = i-1;
}
}
if(note > 0) {
playnote(note);
}
}











Heh, fun
I’ve been meaning to play with something like this, but I’m more interested in a beagleboard with dvi and some decent enough drivers…
I’ll need to build an LED dot matrix display at some point, and an arduino might be the ideal solution to drive that not sure yet.