Ultrasonic Keyboard

It’s time to make some music using the ultrasonic sensor! This is a project that I derived from the previous tutorial, the Ultrasonic Rangefinder.

Overview

ard_usMsc1

How can we make music using the ultrasonic sensor? By adding a piezo speaker, we will assign certain tones to the various range of distance detected by the ultrasonic sensor, which will be generated using the piezo speaker.

For this project, I will be constraining the distance range detected by the ultrasonic sensor from 0cm to 50cm. Hence, when the ultrasonic sensor detects distances exceeding 50cm, no tone will be produced. After constraining the distance value, I mapped the range from 0 to 12. Base on calculations, there will be a tonal change for every approximately 4.1667cm apart the respective distances.

However, there are certain problems that we will encounter. For example, the sensitivity of the ultrasonic sensor will decrease as the distance between it and a small object increases, as the small object will not be able to reflect the ultrasonic signals back to the sensor.

ard_usMsc2

NOTE:  As for the programming part, we will have to make the pitches.h file for the tones to be generated. This can be done by pressing on the “down” arrow beside the main program tab & click “New Tab”.  Name the new file as pitches.h.

ard_add_file

 

Parts Required:

  • Ultrasonic Sensor x 1
  • Piezo speaker x 1
  • Arduino Uno x 1
  • Jumper wires x 1

 

Schematics

ultrasonic_music

Demo

After testing the sensor, I attempted to play “Happy Birthday” in the following demo.

 

Code

 

Share this post:

You may also like...

Leave a Reply

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