Ultrasonic Musical Keyboard (Version 2)

This is an updated version of the Ultrasonic Keyboard, which uses the distance of the ultrasonic sensor to play the various tones.


This is an improved version of the previous project: Ultrasonic Keyboard

It’s been sometime since I last created the Ultrasonic Keyboard, and since I have not been doing much project for some time, why not just make an improve version of the previous project? So with that, I added a 0.96″ OLED I2C Display to display the distance & the note that is currently playing. As the Maker Uno board includes a Piezo Speaker onboard, it will be used in place of an Arduino Uno with a Piezo speaker.

In order to play the various note, a range of 10cm-65cm is used, with 5cm interval that represents different notes. (A total of 13 different tones that can be played)

0 < dist < 10cm: No tone would be played

10 <= dist <= 65cm: Tones would be played accordingly

dist > 65cm: No tones would be played



As mentioned previously in the other post, the few limitations of using a ultrasonic sensor would include:

  • Certain types of material (soft materials) would absorb the ultrasound emitted, which results in less ultrasound being reflected back & subsequently recieved by the sensor.
  • As the distance of the object increases, the amount of reflected ultrasound may be reduced, which results in noisy (fluctuating) distance data recieved. (Also depends on the size/shape of the object that is being detected by the sensor.)

For more accurate distance sensing, one can consider using a time of flight sensor, which works similar to an ultrasound sensor but uses a laser beam instead of ultrasound.


  • Maker Uno x 1
  • Parallax PING)) Ultrasonic Sensor x 1 [Actually any ultrasonic sensor would do, just have to change the code accordingly]
  • Jumper Wires
  • 0.96″ OLED Display (I2C) x 1


Ensure that the buzzer toggle (on the top left corner) is set to the left, which would enable the piezo buzzer to be used.




Before uploading the sketch, ensure that the u8g2 graphic library is installed as it is used to display the text.

The code is also available on Github.


You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *