The following information is a single lesson in a larger project. Find more great projects here.
It's time to make some noise! In this project, you will make a theremin (an instrument controlled by hand motion sensing) using a photoresistor and a piezo sound buzzer. You will be introduced to a new function that controls the tone or pitch of the buzzer.
Step 1: Project Description
It's time to make some noise! In this project, you will use a photoresistor and piezo buzzer to make a light-based theremin.
You’ve probably heard a theremin in scary movies. A theremin is an instrument that makes sounds based on the movements of a musician’s hands around two antennas. One antenna controls pitch while the other controls volume. While the Arduino can’t quite replicate the mysterious sounds of this instrument, we can emulate them using the tone() function. And instead of using antennas, your input device will be a light sensor that you cover with the shadow of your hand.
Take a look at the circuit diagram below. Again, you will use a photoresistor as an analog input: as the resistance of a photoresistor changes, input pin A0 sees different voltage.
The piezo buzzer is simply connected between digital output pin 8 and ground. To change pitch, you will use send pulsed signals to the buzzer using the tone() function. You will learn how to program the Arduino to use the input from the light sensor to change the pitch of the piezo buzzer.
- Continue to the next step.
Step 2: Bill of Materials
You will need the following electrical components for this project:
1 piezo buzzer
1 10 k-ohm resistor
...and of course your Arduino Uno and a breadboard!
Can you match each component on the list to its location on the breadboard?
Continue to the next step.
Step 3: The Tone() Function
In previous projects, you used pulse width modulation (PWM) to control LED brightness. In this project you want to control the vibration frequency of the film in the piezo buzzer to change the musical pitch.
The picture below shows the differences between pulses emitted by PMW and pulses emitted with the tone() function.
- Using PWM, the period of the pulses remains constant. You can control what percentage of the time the film is up vs. down within each single period. As you learned in the Color Mixing Lamp project, this is called the duty cycle.
- With the tone() function, the duty cycle is always 50% (half of the time up and half down). Unlike PWM, it enables a transducer like a piezo to move back and forth at different frequencies, or in other words to change the length of the period. This change in frequency creates different musical pitches.
- The tone() function takes three arguments: the output pin, the frequency in Hz, and the duration in milliseconds (see hint).
- Continue to the next step.
- Stuck? HINT: Frequency is the # of periods per second, expressed in units of Hertz or Hz. A 440 Hz tone cycles through 440 periods per second.
Step 4: Photoresistor and Piezo
You will be using a photoresistor to detect the amount of light hitting your instrument. This is similar to what you created in the Color Changing Lamp project. The change in the voltage on the analog pin will determine which musical tone will play.
The piezo is a small element that vibrates when it receives a voltage. When it moves, it displaces air around it, creating sound waves.
Find the photoresistor and piezo components in the Components + menu (All Components tab) for more information.
Step 5: Mapping Values
When you read this voltage on the photoresistor pin using analogRead(), your readings might not range all the way from 0 to 1023. You’ll have a chance to calibrate the sensor, mapping the real high and low values to sound frequencies using the map() function.
To review the map() function, visit the Mood Cue project.
- Continue to the next lesson to learn how to build the Light Theremin circuit.
Next Lesson:Setting Up the Circuit