Skip to Content

How can I control sounds using a microcontroller?

Think About

  • How do people design instruments to control sound?
  • How do people control sound with instruments and interfaces?
  • How can I control sounds using a microcontroller?

Get Started

Step 1. Take a look at some ways people interact with sensors to control sound

In this project we are going to make a button (sensor) using aluminum foil to sense touch 

To use buttons (sensors) in projects, we need to know about inputs and outputs.

Output – causes something to happen in your local environment.

Input – read or senses something from the local environment

  1. Categorize the following as outputs or inputs:
  • Button
  • Slider
  • Temperature
  • Knob
  • LED
  • Photo sensor
  • Speaker
  • Motor

Interested in finding out more about inputs and outputs?

Here is some technical information on using digital pins as input or output on the Arduino.

There are two parts to building your interface:

  • building the circuit
  • coding the microcontroller

Step 2: Building the Circuit

You will need all of the materials from XP 5C1 along with the following materials:aluminum-alliagorclips

  • alligator clips
  • scissors
  • wires
  • aluminum foil
  • (optional) arcade button or other type of electronic button

 Rebuild the circuit you built in the earlier XP

Step 3. Add your button

  1. Start with two small pieces of aluminum foil.
    1. One piece will be the positive side of your “button”
    2. The other piece will be the negative side of your “button”

aluminumfoil

  1. Attach one alligator clip to a piece of foil

foilbutton-1

  1. Clip the other end of the alligator clip to a wire in pin 5 on the microcontroller

foilbutton2a

  1. Using a second alligator wire, attach one end to the other piece of foil

foilbutton3

  1. Clip the other end of the alligator clip to a wire in the GND pin on the microcontroller

foilbutton4a

You created a circuit for your interface!

Step 4: Next, we’ll upload an Arduino sketch that uses an output (the speaker) and an input (the foil button).

Coding The Microcontroller

  1. Download the file music_inputs_outputs
  2. Open the music_inputs_outputs file in your Arduino IDE
  3. Look at the void setup () section (see the image below)
    1. In the setup section, we declare that the button (pin 5 since that is where we inserted the wire) is an input.
    2. We then set the button to HIGH

music-input-output-code1

  1. Now, look at the void loop section (See image below)
    1. Since we set the button to HIGH in our setup, the loop tells the speaker to play a tone if the sensorValue of the button is LOW
    2. Otherwise, or “else” make no tone

music_input_output2

  1. Upload the code to your microcontroller

You have now built your interface. It’s time to play it!

  1. Touch the two pieces of foil together
    1. You should hear a tone.

foilbutton-4

Share What you Learned

If you are using the LRNG platform:

  • Go back, find out what to submit, and complete the XP
  • If you want, you can then learn even more with the optional “Go Further!” activities below

If you are not using the LRNG platform:

  • Continue below and share with your teacher or organization:

Sharing What You Learned

  • Upload a video of you making a sound with your microcontroller
  • Show your circuit, button, and code sketch in the video

Next Steps

Curious about learning more? 

Go Further! (optional) Explore how to develop your instrument with the code or interface

OR

Move On

Return to the XP How can I create instruments and interfaces with microcontrollers? (continue to the next XP in the mini-playlist)