Arduino Starter Series - Light Theremin

Arduino Aug 20, 2015

This is a project from my Arduino starter series.

In this project I'm going to make the Light Theremin project from the Arduino Projects Book. This project is ideal for beginners. Enjoy!

Project Requirements
  • Arduino Uno/Duemilanove/Diecimila
  • USB cable to program Arduino
  • Breadboard
  • A Buzzer (Small speaker)
  • One Photo Resistor
  • One 10K Resistor
  • Wires to power the components on the breadboard
The Breadboard Setup

The Light Theremin breadboard setup

The Code

I left the code for this project almost identical to that of the book. I've only removed the LED code they had and I added some constants for the piezo/buzzer pin and the photo resistor pin

// variable to hold sensor value
int sensorValue;

// variable to calibrate low value
int sensorLow = 1023;

// variable to calibrate high value
int sensorHigh = 0;

// Piezo pin
const int piezoPin = 8;

// Photo resistor pin
const int photoResistorPin = A0;

void setup() {
  // calibrate for the first five seconds after program runs
  while (millis() < 5000) {
    // record the maximum sensor value
    sensorValue = analogRead(A0);
    if (sensorValue > sensorHigh) {
      sensorHigh = sensorValue;
    }
    // record the minimum sensor value
    if (sensorValue < sensorLow) {
      sensorLow = sensorValue;
    }
  }
}

void loop() {
  //read the input from photoResistorPin and store it in a variable
  sensorValue = analogRead(photoResistorPin);

  // map the sensor values to a wide range of pitches
  int pitch = map(sensorValue, sensorLow, sensorHigh, 50, 4000);

  // play the tone for 20 ms on piezoPin
  tone(piezoPin, pitch, 20);

  // wait for a moment
  delay(10);
}

This project is available on my Github page

Nicholas Bester

I have 15 years of experience in design, development and implementation of digital marketing solutions ranging from virtual reality, 3D projection mapping, mobile apps and massive web platforms.