Introduction: Make a Pocket-Size Theremin With ESP32

Picture of Make a Pocket-Size Theremin With ESP32

Theremin are those unique instruments use to make those alien show theme songs or sound effect. You may have also heard it in Star Trek, Big Bang Theory, or even a haunted house. They produced a unique sound from the electromagnetic effects between wires.

Here we will duplicate a similar sound digitally using a buzzer controlled by Pulse Width Modulations and an Light Dependent Resistor (LDR) for the input of reading values as the hand moves over it.

Step 1: BoM

Picture of BoM

* ESP32

* Light Dependent Resistor (LDR)

* Buzzer

* Jumper Wires

* Breadboard

Step 2: Soldering

Picture of Soldering

We will solder a voltage divider onto the LDR to make the wiring simpler.

* Take a 10kΩ resistor and solder it to one of the pins of the LDR.

* Then take two different coloured wires and solder it to each pin of the LDR.

That's it! Now you have a voltage divider!

Step 3: Wiring

Picture of Wiring

Follow the following table when wiring the LDR and Buzzer to the ESP32:

I/OPin #ESP32 Pin #
Buzzer*1D4
Buzzer*2GND
LDRResistorD5
LDRGrey3.3V
LDRRedGND

* Order is arbitrary

Step 4: Code

Picture of Code
int photopin = 5; // Pin where the photo resistor is connected to
int photValue; // The analog reading from the photoresistor
int buzzerPin = 4; // Connect Buzzer to Pin 4
long buzzerFreq; // The frequency to buzz the buzzer
// You can experiment with these values:
long buzzMAX = 2500; // Maximum frequency for the buzzer
long photoMAX = 1023; // Maximum value for the photoresistor
void setup() {
    pinMode(buzzerPin, OUTPUT); // set a pin for buzzer output
}
void loop() {
    // read the values of the potentiometer
    photValue = analogRead(photopin); // Values 0-1023
    // normalize the readings of a photoresistor to thatof the buzzer and photoresistor
    buzzerFreq = (photValue * buzzMAX) / photoMAX;
    buzz(buzzerPin, buzzerFreq, 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);
    }
}

Step 5: Enjoy!

Picture of Enjoy!

It's easy to use but takes a lifetime to master and to play good music. Move your hands over the LDR to change the tone.

Enjoy your pocket sized theremin!

Comments

About This Instructable

505views

16favorites

License:

Bio: Aerospace Engineer working in Software Development with a passion for Hardware.
More by TechMartian:Flying Captain America's Shield - RC PlaneWide Angle ShotsLED Ping Pong With Shift Register
Add instructable to: