Arduino Theremin
Background Knowledge:
How to read a Schematic
Resistors, Variable Resistors, Transistors, and LEDs in a Circuit
How to use an Arduino
How to read and use a Multimeter
What you'll need:
1 - 9 Volt Battery
1 - 9 Volt Battery Harness
1 - Breadboard
1 - Arduino UNO
2 - LDR Light
1 - 3904 NPN Transistor
1 - Piezo Buzzer
1 - LED
1 - 10K Ohm Potentiometer
2 - 10K Ohm Resistor
1 - 470 Ohm Resistor
A theremin is an electronic musical instrument known for its unique and ethereal sound. Invented by Russian physicist and musician Leon Theremin in 1920, the theremin stands out as one of the earliest electronic instruments. It's recognized for its distinctive feature of being played without physical contact, as the musician controls pitch and volume by moving their hands through the air near the instrument.
Playing the theremin requires a delicate and precise technique. The musician's hands act as virtual antennae and the interaction with the electromagnetic fields determines the pitch and volume of the sound produced. Movements must be controlled and precise to achieve the desired musical expression.
This project is a version of a theremin that uses a piezo buzzer to make sound and changes volume and pitch based on the amount of light detected by LDRs instead of the distance of your hands from distance sensors (the theremin works essentially the same way with LDRs).
Set Up the Circuit:
Use the schematic to build the circuit. Connect the battery harness directly to the Arduino Vin and Ground Pins. The LDR on the left controls pitch and the one on the right controls volume. You will notice that the volume LDR works ver similarly to how the Night Ligth Circuit works in on the Electronic projects page.
2. Write the Arduino Sketch
This code expands on the open-source 'LightTheremin' project code provided by Arduino. There is an initial 5-second calibration period to allow the theremin to adjust to the ambient light in the room.
// variable to hold sensor value
int pitchValue;
// variable to calibrate low value
int pitchLow;
// variable to calibrate high value
int pitchHigh;
void setup() {
// Make the LED pin an output and turn it on
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
// calibrate for the first five seconds after program runs
pitchHigh = analogRead(A0);
pitchLow = analogRead(A0);
while (millis() < 5000) {
// record the maximum sensor value
pitchValue = analogRead(A0);
if (pitchValue > pitchHigh) {
pitchHigh = pitchValue;
}
// record the minimum sensor value
if (pitchValue < pitchLow) {
pitchLow = pitchValue;
}
}
// turn the LED off, signaling the end of the calibration period
digitalWrite(13, LOW);
}
void loop() {
//read the input from A0 and store it in a variable
pitchValue = analogRead(A0);
// map the sensor values to a wide range of pitches
int pitch = map(pitchValue, pitchLow, pitchHigh, 50, 4000);
// play the tone for 20 ms on pin 8
tone(8, pitch, 20);
// wait for a moment
delay(10);
}
3. Upload and Adjust the Circuit
Upload the sketch to the Arduino board. Next, turn the potentiometer until you can comfortably hear the piezo buzzer. The potentiometer is meant to allow you to adjust the amount of voltage that is shared by the LDR and the 10k resistor that feeds into the base of the transistor, ultimately dictating the base volume of the piezo buzzer.
4. Understand the Code
// calibrate for the first five seconds after program runs
pitchHigh = analogRead(A0);
pitch low = analogRead(A0);
The program begins with a calibration method that allows the theremin to adjust to the ambient light in the room. The LED turns on to signal the start of the calibration period. First, the Arduino reads the initial input value from the pitch LDR and sets that as the minimum and maximum values of the light level.
while (millis() < 5000) {
// record the maximum sensor value
pitchValue = analogRead(A0);
if (pitchValue > pitchHigh) {
pitchHigh = pitchValue;
}
// record the minimum sensor value
if (pitchValue < pitchLow) {
pitchLow = pitchValue;
}
}
Next, it continuously reads the light level from the LDR for five seconds, updating the maximum and minimum values whenever the reading is higher or lower than each, respectively. This is why it is important to temporarily completely cover the pitch LDR while it is calibrating.
After the calibration period is over, the Arduino constantly maps the input level to a full range of frequencies (5,000 Hz to 40,000 Hz) using the map() method. It then plays the corresponding note on the piezo using the tone() method.
5. Calibrate and Play
While the LED is on, make sure to temporarily cover the LDRs so that the Arduino can properly calibrate the entire range of pitches to play.
Change the amount of light the Arduino reads by moving your hands closer and farther from the LDRs. This will change the pitch and volume of the tone that the theremin outputs.
Questions:
How does this project differ from a real Theremin?
Could you get
Special Note:
Maker Lessons is proud to help teach both in front and behind the scenes. Maker Lessons provides internship opportunities where STEM students have the opportunity to make pages like this one. This page was made by I.G.