Catch a Ball, Make It Sing

For this assignment, we were asked to make a switch which combines our knowledge of Arduino digital input and output programming. Based on that, I created a switch that connects two long wires through openings on a glove to a series of three blinking LEDs and a 12mm round speaker. To complete the circuit, you’d have to catch a ball which is plastered with copper tape–– thus switching on the LEDs and playing the short tune from the speaker. This project sort of plays on the idea of carnival games which use bright lights and catchy tunes, and I wanted to create something which I can both play with and learn from.

Initially, I had intended for the copper to be on the ball as well as the glove’s fingertips. Here’s a rough sketch of that thought:

However, I realized it would be better to have some copper tape between the wires in the center of the glove instead. This was so I could expand the conductive surface, and also have it all placed in one central position. In the end, this is how my glove and ball looked like:

Here’s a video demonstration of the final result:

When I started programming this on Arduino, I was able to figure out how to make the blinking LEDs work using knowledge from our previous class (and some extra help), but getting the speakers to work was challenging since I’ve never worked with music and code, so I resorted to some Arduino built-in examples which are credited below. Here’s my final code:

 

#define NOTE_G3  196
#define NOTE_A3  220
#define NOTE_B3  247
#define NOTE_C4  262


int redLed = 9;
int blueLed = 8;
int greenLed = 7;
int button = 3;

int melody[] = {
  NOTE_C4, NOTE_G3, NOTE_G3, NOTE_A3, NOTE_G3, 0, NOTE_B3, NOTE_C4
};

// note durations: 4 = quarter note, 8 = eighth note, etc.:
int noteDurations[] = {
  4, 8, 8, 4, 4, 4, 4, 4
};

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(redLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(button, INPUT);
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  int buttonState = digitalRead(button);

  if (buttonState == HIGH) {

    digitalWrite(redLed, HIGH);   
    delay(80);                      
    digitalWrite(redLed, LOW);    
    digitalWrite(blueLed, HIGH);    
    delay(80);                     
    digitalWrite(blueLed, LOW);     
    digitalWrite(greenLed, HIGH);   
    delay(80);                     
    digitalWrite(greenLed, LOW);     

    for (int thisNote = 0; thisNote < 8; thisNote++) {

      // to calculate the note duration, take one second divided by the note type.
      //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc.
      int noteDuration = 1000 / noteDurations[thisNote];
      tone(4, melody[thisNote], noteDuration);

      // to distinguish the notes, set a minimum time between them.
      // the note's duration + 30% seems to work well:
      int pauseBetweenNotes = noteDuration * 1.30;
      delay(pauseBetweenNotes);
      // stop the tone playing:
    }
  }
}

//credits: toneMelody Arduino built-in examples.

 

 

 

 

One thought on “Catch a Ball, Make It Sing”

Leave a Reply