A.U.M.I - Arduino Ultrasonic Musical Instrument




Introduction: A.U.M.I - Arduino Ultrasonic Musical Instrument

About: Simplicity is the ultimate sophistication.

This is a really simple tutorial for an Arduino Xylophone-ish Instrument. I've written this tutorial for beginners.

Even if you just bought your Arduino - You will probably understand!

A.U.M.I. was born because of the dearth of parts where I live - So I make do.
Ideally, you should understand basic coding. It would also be really great if you understood what a PING sensor is, and the code used for it. However, I will try to give a basic overview.

Edit: I've attached the video. I accidentally broke the speakers, so I couldn't make a better one. Sorry! My speakers are a little too cheap, so it sounds a little crackly.

Also, vote for me in the Audio Contest!

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: The Ultrasonic Sensor

We will be using this sensor to measure distances.

It detects the distance of the closest object in front of the sensor (from 3 cm up to 400 cm). It works by sending out a burst of ultrasound and listening for the echo when it bounces off of an object. It pings the obstacles with ultrasound.

The Arduino board sends a short pulse to trigger the detection, then listens for a pulse on the same pin using the pulseIn() function. The duration of this second pulse is equal to the time taken by the ultrasound to travel to the object and back to the sensor. Using the speed of sound, this time can be converted to distance.

It's a very logical process and isn't hard to understand.

Now I couldn't get my hands on the PING SEN136B5B Sensor. Instead, I have a HC-SR04. For all our purposes, they are EXACTLY the same.

If you do decide to use the SEN136B5B, then you'll have to change bits of code, and the pins you connect to. It isn't hard to do.

Step 2: Materials Required

• Arduino Uno - Recommended for Beginners. You could use any other Arduino Board.
• Piezo Buzzer or Speaker - I had mine left over from my previous instructable.
• Jumper Cables - Both Male to Male, and Male to Female are required.
• A functioning computer with the Arduino IDE installed. More on that later.
• HC-SR04 Ultrasonic Sensor, Available Here

That's all you'll need!

Step 3: Setting Up With Arduino IDE.

Start off by installing the Arduino IDE available here.

Before starting to code, you have to select the option in the Tools >> Board menu that corresponds to your Arduino board. For purposes of this project, I'm gonna consider the UNO.

Next, select the serial device of the board from the Tools >> Serial Port menu. Most of the time this is COM3 or higher. You can disconnect the board and reconnect, and the option that appears would be your port. Select the port.

Open a new file, and crack your knuckles. The toughest part of this project is coming.

Step 4: The Code

I'm going to start off by explaining how this thing works. We use the distance detection of the sensor to set up different musical notes. So if there is an obstruction at 4 cm it plays one note, and a different note if the obstruction is at 10 cm. Doing this, we can get an octave of notes, which we play using an obstruction.

I'll get back to the part about actually playing this thing later.

The code is a BIT complex for the beginner, but you shouldn't have trouble figuring it out.

Other than Ground and Voltage, the sensor has 2 other pins. These are 'trigger' and 'echo'. We use a combination of these 2 pins to find out the distance of the object.

(In case of the 3-pin PING model, these are one and the same.)

In a nutshell, the trigger pin sends out a pulse, and the echo pin receives its echo from the object. They work in unison to determine the time taken to return. We then convert this time into distance.

Now, more importantly, I shall explain the series of 'if' statements.

If the distance is between 2 values given in the parentheses, the sensor will play a certain note. The notes have already been stored in an array. We do this 8 times, for the 8 notes in an octave.

I've given some useful comments in the code itself, so jump right in!

void setup() {//I declare whether I'm using the pins for input/output
pinMode(10,OUTPUT); pinMode(7,OUTPUT); pinMode(8,INPUT); } int sp = 10; //Speaker Pin int tp = 7; //Trigger Pin int ep = 8; // Echo Pin int c = 523; int d = 587; int e = 659; int f = 698; //These are the frequency int g = 784; //values of the different notes int a = 880; int b = 988; int c2 = 1047; void loop() { //This is the main loop, that keeps repeating int notes[] = {c,d,e,f,g,a,b,c2}; //An array storing all the notes. It's kind of like a dictionary. long duration, distance; //Variables to store the values of time and length digitalWrite(tp,LOW); delayMicroseconds(2); digitalWrite(tp,HIGH); //This area sends out a pulse from the trigger delayMicroseconds(5); digitalWrite(tp,LOW); duration = pulseIn(ep, HIGH); //The echo is recieved, and saved as the duration distance = (duration/2)/29.1; // We convert the time into distance in centimeters, using the speed of sound and other factors. if(distance>4&&distance<42) { if(distance>4&&distance<7) //For a distance between 4 and 7, it plays C for 100 milliseconds tone(sp,notes[0],100); else if(distance>8&&distance<11) tone(sp,notes[1],100); //For a distance between 8 and 11, it plays D for 100 milliseconds else if(distance>12&&distance<15) tone(sp,notes[2],100); //For a distance between 12 and 15, it plays E for 100 milliseconds else if(distance>16&&distance<19) tone(sp,notes[3],100); //For a distance between 16 and 19, it plays F for 100 milliseconds else if(distance>20&&distance<23) tone(sp,notes[4],100); //For a distance between 20 and 23, it plays G for 100 milliseconds else if(distance>24&&distance<27) tone(sp,notes[5],100); //For a distance between 24 and 27, it plays A for 100 milliseconds else if(distance>28&&distance<31) tone(sp,notes[6],100); //For a distance between 28 and 31, it plays B for 100 milliseconds else if(distance>32&&distance<35) tone(sp,notes[7],100); //For a distance between 32 and 35, it plays high C for 100 milliseconds }


Step 5: Making the Connections

I'm not using a breadboard, although you can try to. I tried keeping it as simple as possible.

The HC-SR04 has 4 pins - Ground, VCC, Trig and Echo.

Start by connecting Ground to any GND on the board, and VCC to +5V.

Plug in Trig to Pin 7.

Plug in Echo to Pin 8.

Next, connect the -ve of your speaker to GND, and the Positive to Pin 10.

Make sure the connections are right, otherwise the code won't run correctly.

Okay - Now you're good to go! Upload the code onto the Arduino!

Step 6: How to Play the A.U.M.I.

So now is the tricky part - Actually playing this thing.

The hard truth is, you've gotta figure it out for yourself. However, I will tell you how I did it.

These are the notes and their ideal distances from the sensor. I've made allowances in the code, so you can be off by half a centimeter while actually playing.

• C - 5cm
• D - 9cm
• E - 13cm
• F - 17cm
• G - 21cm
• A- 25cm
• B - 29cm
• C - 33cm

I measured these distances and put them on a sheet of paper, writing down the corresponding notes. Then I put the sensor at the end of the paper and got perfect positions for each note.

To actually play, the instrument, you need a thin stick or something of the sort. A chopstick worked perfectly. If you're having problems with the chopstick, just put a piece of paper on the end to widen it.

That's about it! Eventually, you'll be able to instinctually play without the paper.

Step 7: Conclusion

What I showed you is merely a template. To make things awesome, you should mix it up!

Maybe you could figure out how to use 2 of these at ones, or do chords instead of notes (which would be amazing).

You could also change the scale of the instrument, or even add another octave. Have fun experimenting, and share this with your friends!

I tried making this as simple as possible, so please tell me if you liked it!

Audio Contest 2017

Participated in the
Audio Contest 2017

Be the First to Share


    • Backyard Contest

      Backyard Contest
    • Silly Hats Speed Challenge

      Silly Hats Speed Challenge
    • Arduino Contest 2020

      Arduino Contest 2020

    5 Discussions


    Question 1 year ago

    That's very cool. Bravo! If I want to change the sound, (e.x to play notes coming from synth, or guitar, or from SuperCollider) how can I do it?


    Reply 2 years ago

    There's one right above the introduction! Unfortunately my speaker broke, and I can't get another one lol. I'd make a completely new video if I could!


    Reply 2 years ago

    Arg! I'm an idiot. Nice job. I'll have to make one up myself.


    2 years ago

    coolllllllll :D