In-class: Musical instrument with ultrasonic distance sensor

Get the code: ping_scale

My partner and I used the PING))) Ultrasonic Distance Sensor to play a musical scale with square waves generated by Arduino's tone().  

The sensor provides a time value for how long a sound wave takes to return after bouncing off of an object, which can be used to determine the distance from that object.  In this case, the object was my own hand.

We physically limited the scale to 32" to keep things manageable (the sensor a maximum range far greater than that).  Dividing this distance into 8 discrete parts gave us the "keys" for a one-octave scale.

We mapped the parts to the notes, and when my hand was a certain distance from the sensor, the corresponding tone was played.

No comments:

Post a Comment

Speak now...