Light Sensitive Theremin

/**/

Light Sensitive Theremin

In this project, I am going to demonstrate how to make a theremin-like instrument that makes weird spacey sounds.

Things used in this project

Hardware components

  • Arduino UNO x 1
  • Idiotware Shield x 1
  • USB-A to B Cable x 1
  • Generic Jumper (0.1″) x 2

Story

Learn about theremins at: https://en.wikipedia.org/wiki/Theremin

Light Sensitive Resistors

A light dependent resistor or LDR is a light controlled variable resistor. The resistance of a LDR decreases with increasing light intensity. However on the idIoTware shield, the LDR is wired such that with a higher light intensity we get a higher Analog Voltage on Pin A3.

Mode of Operation

The theremin is a musical instrument that makes spacey sounds as you move your hand near it by responding to changes in capacitance.

In this example we are going to use LDR sensor to make weird spacey sounds. When we wave our hand over the LDR the light intensity changes. This data is then captured by Arduino through a voltage divider. We set the frequency according to the light value by using a map and tone functions in the Arduino IDE to generate specific frequency.

Configuring idIoTware Shield

Once you upload the code, test the theremin by waving your hand up and down over the sensor. You will hear different sets of tones.

No more connecting LEDs to breadboard and messy wiring. With the idIoTware shield the sky’s the limit.

Schematics

Code

const int ldrPin = A3;
const int buzzerPin = A1;

// variable declaration
int value;  // sensor value
int low;    // low sensor value calibration
int high;   // high sensor value calibration
// LED pin alert calibration
int led = 13;
 
void setup() 
    {
      pinMode (buzzerPin, OUTPUT);
      pinMode (led, OUTPUT);
      // turn LED on
      digitalWrite(led, HIGH);
      // calibration for the first 3 seconds after program runs
      while (millis() < 3000) 
            {
              // record the maximum sensor value
              value = analogRead(ldrPin);
              if (value > high) 
                 {
                   high = value;
                 }
              // record the minimum sensor value
              if (value < low) 
                 {
                   low = value;
                 }
            }
      // turn LED off
      digitalWrite (led, LOW);
    }
 
void loop() 
     {
       //read the input from A0 and store it in a variable
       value = light();
       // map the sensor values to a frequency range 50 Hz - 4000 Hz
       int pitch = map(value, low, high, 100, 4000);
       // play the tone for 20 ms on buzzer pin 8
       speaker(pitch, 20);
       // wait for a moment
       delay(10);
     }
     
//function to calculate potentiometer value
int light()
   {
    int val = analogRead(ldrPin);
    return val;
   }

void speaker(unsigned int frequency, unsigned long duration)
            {
              tone(buzzerPin, frequency, duration);
            }     
     

Video