Make a Pocket-Size Theremin With ESP32

by TechMartian in Circuits > Microcontrollers

4618 Views, 33 Favorites, 0 Comments

Make a Pocket-Size Theremin With ESP32

IMG_20170827_205033.jpg

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.

BoM

IMG_20170827_205154.jpg

* ESP32

* Light Dependent Resistor (LDR)

* Buzzer

* Jumper Wires

* Breadboard

Soldering

IMG_20170827_110850.jpg
IMG_20170827_110228.jpg
IMG_20170827_110414.jpg
IMG_20170827_110327.jpg
IMG_20170827_110608.jpg

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!

Wiring

IMG_20170827_204939.jpg
IMG_20170827_204955.jpg
IMG_20170827_204959.jpg

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

Code

Screen Shot 2017-08-27 at 10.10.44 PM.png
Screen Shot 2017-08-27 at 10.10.46 PM.png
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);
    }
}

Enjoy!

IMG_20170827_205048.jpg

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!