The project started with using an ultrasonic sensor to detect distances.
Then I thought of using two ultrasonic sensors to tell the passing object‘s movement direction by detecting the change in the measured distance between two sensors.
During the testing, the hand wave I used for testing, reminds me of guitar strumming. So I thought of using this to make an air guitar. I mean who can say no to air guitars.
By detecting the change of the distance between the two sensors, the moving direction of the object in front is obtained.
// Clears the trigPin condition
digitalWrite(trigPin1, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin1, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin1, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration1 = pulseIn(echoPin1, HIGH);
// Clears the trigPin condition
digitalWrite(trigPin2, LOW);
delayMicroseconds(2);
// Sets the trigPin HIGH (ACTIVE) for 10 microseconds
digitalWrite(trigPin2, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration2 = pulseIn(echoPin2, HIGH);
// Calculating the distance
distance1 = duration1 * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
distance2 = duration2 * 0.034 / 2; // Speed of sound wave divided by 2 (go and back)
d1 = distance1;
d2 = distance2;
if ((t1 < t2)) {
// one direction
}
else if (t2 < t1){
// another direction
}
After making the strumming works. Next step is to add a way for our air guitar to make sound.
By adding an active buzzer we now have ability to making sound.
To get more than just one sound from our air guitar. Three more buttons are added. In theory, there can be 7 combinations out of 3 buttons. Respectively assigen to C4, D4, E4, F4, G4, A4, B4.
if (buttonState1 == 1 && buttonState2 == 0 && buttonState3 == 0) {
tone(buzzerPin, NOTE_C4);
}
else if (buttonState1 == 0 && buttonState2 == 1 && buttonState3 == 0){
tone(buzzerPin, NOTE_D4);
}
else if (buttonState1 == 0 && buttonState2 == 0 && buttonState3 == 1){
tone(buzzerPin, NOTE_E4);
}
else if (buttonState1 == 1 && buttonState2 == 1 && buttonState3 == 0){
tone(buzzerPin, NOTE_F4);
}
else if (buttonState1 == 1 && buttonState2 == 0 && buttonState3 == 1){
tone(buzzerPin, NOTE_G4);
}
else if (buttonState1 == 0 && buttonState2 == 1 && buttonState3 == 1){
tone(buzzerPin, NOTE_A4);
}
else if (buttonState1 == 1 && buttonState2 == 1 && buttonState3 == 1){
tone(buzzerPin, NOTE_B4);
}
Next I want to add more buttons. to simulate guitar chords. Use 6 laser sensors to simulate six strings. It's still a bit clumsy to only simulate up and down strumming. The six laser sensors can be expected to detect the interaction of the individual six strings with great precision. Therefore not just strumming, picking might also be availed for the air guitar.
Connect via Bluetooth to use external audio maybe a good idea too. Chords cannot be expressed with just one buzzer. Using 6 buzzers might be a way to create chords. Because guitar has 6 strings. However buzzers still sounds bad, external speaker and sound source is necessary if the experience needs to be good.
Comments