For this Instructable, I have made a primitive musical soundboard using an ultra sensor as a keyboard. Here I will show you the basic steps on how to create such a device yourself. Later on, in December, I will demonstrate to you how to make a more complex or soldered version of this soundboard with the Arduino.
- Wooden board to make the keyboard sturdy, approximately 27cm x 32cm is wide enough.
- One passive buzzer
- One ultrasonic (HC-SR04) sensor module
- 1-2 breadboards
- Approximately 5-10 woodscrews
- Approximately 2-3 male-to-male wires
- 4 female-to-male or Dupont wires
- One Arduino
- 6-12 woodscrews
Other Basic Materials
- ruler (preferably one that measures in cm or mm)
- pencil and/or pen
- 1 RGB led
- 4 more male-to-male wires
- Possibly 3 220 Ω resistors.
- Arduino Libraries “pitches,” “SR04.h”
- Buzzer Code
MOST IMPORTANT REQUIREMENTS:
Step 1: Setting Up the Board
Anyway, I recommend you arrange your board like this, as you can see above in the diagram.
Step 2: Drawing the Notes
It would also probably help if you mark some distance that is even numbered so it would be easier to program later on.
Step 3: Securing the Board
If you want to, you can even take off the adhesive strip and attach the breadboard to the wood, but I wouldn’t recommend that if you plan to use that breadboard again.
When it comes the wood you have and the material,the minimum number of screws needed to secure your Arduino would be two, the minimum number of woodscrews for the breadboard would be four. You can add more if you wish, but its already secure as is. That is the number I went with for my prototype.
Step 4: Wiring the Ultrasensor
Also, know that the trigger part of the ultra sensor analyzes the distance of an object away from the sensor; the echo pin emits a low-frequency ultrasound 40,000 Hz or 40 kHz (Understanding How Ultrasonic Sensors Work, Rodrick) to detect distance. You can think of the ultra sensor in the same way as a bat using echolocation to find food. So make sure the components are connected to the pins before you begin coding.
Step 5: Wiring the Piezo
Step 6: Putting Them Together
Step 7: The Code
So now that we have the code components let us look at it very carefully. You’ll notice that the pins for the passive buzzer and the ultrasensor are already defined.
You’ll will also notice that there is an array with a vast amount of notes. I have already a prearranged notes that i selected for my prototype, however, you can adjust this notes by changing the notes and refering to the pitches library. You can also adjust note duration and delay in the if statement below. Or you can do a mix of both, go wild.
If you haven’t already downloaded this library, or the SR04 library for that matter, do it now.
If you plan to create a longer keyboard with moe notes, feel free to add them now. However, make sure to write down the names of each key on each spot where you wish that note to play so it will be a bit easier when testing it out. I used a pencil for mine, but if that is too light for you than use a pen.
Step 8: Quick Side Note: Downloading Arduino Libraries
Step 9: Uploading the Code
Now that you have all the adjustments you need. Feel free to run it, but make sure to test it out before you seriously play with it. If it plays a not from the specific distance you desire, than congratulations! You made your prototype Ultrasensor keyboard!
Step 10: BONUS
Now that you have read through my ramblings, you desrve a treat! This treat is in the form a RGB led. For the regular prototype, we used a ultrasensor as an input, and a speaker as an output. This bonus takes it one step further and adds a second output, a RGB led!
Step 11: Wiring the RGB LED
Step 12: Coding the RGB LED
Here is the finished product for this bonus. Here, you can tell I added extra stuff to the if-statement, light data is used from the input data from the ultrasensor. Its good to use as a sort of back-up for the speaker incase something happens to it, then you will know tht there is an issue with the speaker and not the ultrasensor. It is also good for a prototype before working on something like a Neo-pixel. Say, if you want to see what something will do before its encoded into a Neo-pixel strip, RGB leds, in my opnion, are the best go to. If not, then I apologize. Fair warning, I don’t really mind the way the rgb outputs ight in this current, but there is a slight chance it will flash due to the data from the ultrasensor. So if your sensitive to flashing lights or have epilepsy I would suggest a long delay on the light. Or if you feel too unsure with testing out the light then I reccomended ignoring this section entirely.
Step 13: Uploading and Running
Here is what it should look like with all its components.
Step 14: Code Sources and Inspirations
Here are links to the code referenced, I will also add the code I used to create my code, most are open source but I will still cite them anyway.
Arduino (2010) Pitches.h library (version 1.0) [source code] https://www.arduino.cc/
Arduino (2016) SR04.h libary (version 2.0.1) [source code] https://www.arduino.cc/
Burnett, Roderick. “Understanding How Ultrasonic Sensors Work.” Understanding How Ultrasonic Sensors Work Comments, Publisher Name MaxBotix Inc.Publisher Logo, 4 Mar. 2021, https://www.maxbotix.com/articles/how-ultrasonic-sensors-work.htm.
codebender_cc. “How to Use an RGB Led – Arduino Tutorial.” Instructables, Instructables, 7 Oct. 2017, https://www.instructables.com/How-to-use-an-RGB-LED-Arduino-Tutorial/
Elegoo (2016) SR04 example source code (version 2.0.1) [source code] https://www.elegoo.com/
Elegoo (2016) RGB_LED source code (version 1.0) [source code] https://www.elegoo.com/
Igoe T (2010) Passive_buzzer source code (version 1.0) [source code] https://www.arduino.cc/
Jabbaar, Arbi Abdul. “Ultrasonic Sensor HC-SR04 with Arduino Tutorial.” Arduino Project Hub, Arduino, 17 Sept. 2019, https://create.arduino.cc/projecthub/abdularbi17/ultrasonic-sensor-hc-sr04-with-arduino-tutorial-327ff6.
The Arduino Team. “HCSR04 Ultrasonic Sensor.” HCSR04 Ultrasonic Sensor – Arduino Reference, Arduino , https://www.arduino.cc/reference/en/libraries/hcsr04-ultrasonic-sensor/