The Force Piano! Midterm!!

For my midterm assignment, I decided to build a machine able to automatically play the piano at the same time that the user is playing the guitar. I called this machine” The Force Piano”.  This machine functions in the following way. The guitar functions as a switch, so when the user plays it activate three servos and each servo moves a stylus able to touch the touchscreen of an Ipad. In the iPad, an application that simulates a piano was downloaded. Through this application, the stylus interacts with the piano application.

The building process of this machine was the following. First, an Ipad Mini and Arduino breadboards were stuck with tape to a big piece of wood. Then the three servos were connected to the breadboards and a code was created that allows the servos to move once from angle 90 to 180 and vice-versa every time that a switch is turned on(The code was attached at the end of this post). Next, three stylus were created using aluminum, cotton swabs, and water. The plastic stick of the cotton swabs was surrounded with aluminum and the aluminum was positioned to slightly touch the cotton tip, then, the cotton tip was submerged into water (water allows electricity to flow electricity to the touchscreen of the iPad) and  each one was connected to an alligator cable coming from Power from the breadboard. After building the stylus, these were attached to the servos using hot glue and then the servos were stuck to the piece of wood, considering the position of the notes F4, A4 and C5 in the piano app of the iPad. The switches to activate the servos were build using the metal strings of the guitars. Three alligators cables were attached to the 5th, 4th and 3rd string of the guitar and these alligators were connected to ground in the breadboard. Then an alligator cable coming from power was connected to a metal pick (every time the pick touches the string the circuit is closed). And finally, the guitar was played to test that the servo moved with the angle needed to touch the correct note of the piano.

The biggest challenges in this assignment were figuring out how to create a stylus. My original idea was made a drum with wood and hit it  with drumsticks to create sound, but then, I thought it was going to be cooler to make the servo to play the song with me, and as It was impossible to use a real piano, I improvised and decided to use my old IPad mini. The challenge was that I thought that I was going to be able to interact with the touchscreen with any material. But, It did not take long until I realized that it was not that simple. So, after doing some research, I learned that, in order to interact with a touchscreen,  I needed to make electricity flow through the material. Hence, my first prototype of a stylus it only had aluminum, but when I did the testing I realize that it only interacted with the touch screen 1 out 3 times, that’s why  I decided to use softer material pour water on it.. The other challenge was positioning and finding the angles for the servos by trial and error. To finally, figure it out I needed to rebuild several times the servos-stylus prototypes.

 

#include <Servo.h>

Servo myServo5F;
Servo myServo10A;
Servo myServo9C;
bool prevStringFState2 = LOW;
bool prevStringAState3 = LOW;
bool prevStringCState4 = LOW; 
int StringFPin2 = 2;
int StringAPin3 = 3;
int StringCPin4 = 4;


void setup() {


  pinMode(StringFPin2, INPUT);
  pinMode(StringAPin3, INPUT);
  pinMode(StringCPin4,INPUT);
  Serial.begin(9600);
  myServo5F.attach(5);
  myServo10A.attach(10);
  myServo9C.attach(9);

}

void loop() {

  int currentStringFState2 = digitalRead(StringFPin2);
  int currenStringAState3 = digitalRead(StringAPin3);
  int currentStringCState4 = digitalRead(StringCPin4);
  if (prevStringFState2  == LOW && currentStringFState2 == HIGH) 
  {
    myServo5F.write(180);
    delay(100);
    myServo5F.write(90);
    delay(100); 
  } 
  else if (prevStringAState3 == LOW && currenStringAState3  == HIGH)
  {
     myServo10A.write(180);
    delay(150);
    myServo10A.write(90);
    delay(150); 
  } 
  else if ( prevStringCState4 == LOW && currentStringCState4 == HIGH)
  {
    myServo9C.write(0);
    delay(150);
    myServo9C.write(90);
    delay(150); 
    
 }
  prevStringFState2 = currentStringFState2;
  prevStringAState3 = currenStringAState3;
  prevStringCState4 = currentStringCState4;
}



Leave a Reply