In this short tutorial, you will learn how to build an Arduino Theremin. You only need three components plus the Arduino, wires, and breadboard.
Use the breadboard diagram or the video below to see how to connect everything.
The Components You’ll Need
- Buzzer (passive)
- Photoresistor
- Resistor 220Ω
- Arduino
- Wires
- Breadboard
How The Arduino Theremin Works
An Arduino theremin isn’t the same as the original theremin invented by Léon Theremin where you can control both amplitude and frequency.
But it’s a fun and simple project anyway!
The photoresistor is connected with the resistor to form a voltage divider. The Arduino reads the voltage out from the voltage divider.
This means that when the photoresistor changes its resistance (that is when the light changes) the voltage that the Arduino reads changes.
The Arduino controls the frequency of the buzzer. By using the voltage value the Arduino reads in, the Arduino changes the tone of the buzzer so that the tone you hear is directly dependent on the light that the photoresistor sees.
The Arduino Code
Copy and paste the code below into a new project. Then compile and upload the code to your Arduino.
Build Something Practical This Evening
Download this tutorial that shows you step by step how to build an old-school USB charger for your mobile.
int analogPin = A0; // Input from photoresistor connected to A0 int buzzerPin = 4; // Positive buzzer pin connected to pin 4 long max_frequency = 2500; // Max frequency for the buzzer long frequency; // The frequency to buzz the buzzer int readVal; // The input voltage read from photoresistor void setup() { pinMode(buzzerPin, OUTPUT); // set a pin for buzzer output } void loop() { readVal = analogRead(analogPin); // Reads 0-1023 frequency = (readVal * max_frequency) / 1023; buzz(buzzerPin, frequency, 10); } void buzz(int targetPin, long frequency, long length) { long delayValue = 1000000/frequency/2; long numCycles = frequency * length/ 1000; for (long i=0; i < numCycles; i++) { digitalWrite(targetPin,HIGH); delayMicroseconds(delayValue); digitalWrite(targetPin,LOW); delayMicroseconds(delayValue); } }
Questions?
Did you build this Arduino Theremin? Are you having problems building it? Let me know in the comments below.
More Circuits & Projects Tutorials
Build Something Useful This Evening
This gadget lets you use any IR remote-control to control your lamp, garden lights, heater oven, garage door, or anything else.
where can I find a program to program a 8052 micro
This sounds like a good project for semi-beginners! Thanks for sharing.
I used the code you used and it didn’t work. My circuit was correct and I used your code, but it still didn’t work. I have a SparkFun RedBoard, and not an Arduino Uno. Is that the reason? Since it didn’t work, I wrote a different code (teto is the buzzer, photo is photoresistor, and fullfre is the max frequency:
int teto = 5;
int photo = 0;
long fullfre = 200;
long frequency;
int value;
void setup() {
pinMode(teto, OUTPUT);
}
void loop() {
value = analogRead(A0);
frequency = fullfre + value / 25;
tone(teto, frequency);
}
After I uploaded the code above, the buzzer started making a sound finally. However, I am not able to ‘play’ with it like you did in the video. It doesn’t change when I move my fingers. It does change when I use a flashlight on it however, but not when I move it closer although.
I see that you are using pin 5 for the buzzer, while I used pin 4. Could that be it? Or that you connected the buzzer in the opposite direction?
the code isn’t working I’m using the mega 2500 and it is saying redefinition of void setup()
Sounds like you have two void setup() in your code. I don’t have that in my code, so try copying again and make sure you delete any old code from your sketch.
it didn’t work
Error:
void setup() {
pinMode(buzzerPin, OUTPUT); // set a pin for buzzer output
Hi Gauthier, I am not seeing the error.
What else can you use besides a photo resistor?
A thermistor would work out of the box. But maybe not as easy to play music with temperature…
In general, you can replace the light sensor with a distance sensor (IR or sonar), UWB radar, or a proper theremin circuit.
How would you go about using a sonar distance sensor in this way? I’ve tried doing that but because the sonar (at least to my knowledge) requires loops with their own delays, these delays seem to mess up the timings which are what determine the different frequencies (pitches) of the buzzer