Project tutorial
DIY Arduino Musical Instrument-Theremin with 4 Sound Modes

DIY Arduino Musical Instrument-Theremin with 4 Sound Modes © GPL3+

This instrument produces tones or sounds based on the light that falls on the surface of the photoresistor.

  • 1,246 views
  • 0 comments
  • 0 respects

Components and supplies

Necessary tools and machines

09507 01
Soldering iron (generic)
4966285
Solder Wire, Lead Free

About this project

The Theremin is an electronic musical instrument controlled without physical contact by the thereminist (performer). It is named after its inventor, Leon Theremin, who patented the device in 1928.

This time I will show you how to make such an instrument that produces tones or sounds based on the light that falls on the surface of the Photoresistor. By moving your hand over the photoresistor, the intensity of light falling on it, changes, and that change the pitch. The device is very simple to build and can be successfully made by a beginner. It also does not require a separate power supply and is powered via the USB port of Arduino.

Contains only a few components:

- Arduino Nano microcontroller

- Photoresistor

- Speaker

- Two trimmer potentiometers

- and two resistors

In the sketch, the measured brightness is assigned a minimum and a maximum tone frequency (pitchMin and pitchMax). However, these values ​​can still be changed during runtime with two trimmer potentiometers. An additional button switches between 4 different modes one after the other. When the program is started, a 440 Hz tone is output for 5 seconds. During this time, the LDR is calibrated, and the minimum and maximum incidence of light are measured. As soon as the calibration process is finished, the "no sound" mode starts and you only hear sounds when you have pressed the button.

Finally, the device is mounted in a suitable box made of PVC board, lined with colored wallpaper.

Code

Arduino codeC/C++
#define PIN_PIEZO    9
#define PIN_BUTTON   2
#define PIN_LDR      A0
#define PIN_POTI_MIN A1
#define PIN_POTI_MAX A2

#define CALIBRATION_DURATION 5 // in seconds

// Pitch definitions in Hz
#define PITCH_MIN_LOWER 5
#define PITCH_MIN_UPPER 170
#define PITCH_MAX_LOWER 20
#define PITCH_MAX_UPPER 1000

int sensorValue = 0, sensorMin = 700, sensorMax = 0;
int pitchMin = PITCH_MIN_LOWER, pitchMax = PITCH_MAX_LOWER;
unsigned long lastPressedButton = 0;
byte buttonState = 0;

void setup()
{
    pinMode(PIN_PIEZO, OUTPUT);
    pinMode(PIN_BUTTON, INPUT_PULLUP);
    pinMode(PIN_POTI_MIN, INPUT);
    pinMode(PIN_POTI_MAX, INPUT);

    tone(PIN_PIEZO, 440);
    while (millis() < (CALIBRATION_DURATION * 1000)) {
        sensorValue = analogRead(PIN_LDR);
        sensorMax = max(sensorValue, sensorMax);
        sensorMin = min(sensorValue, sensorMin);
    }
    noTone(PIN_PIEZO);
}

void loop()
{
    if ((millis() - lastPressedButton > 250) && digitalRead(PIN_BUTTON) == LOW) {
        lastPressedButton = millis();
        buttonState++;
        buttonState %= 5;
    }

    pitchMin = PITCH_MIN_LOWER + map(analogRead(PIN_POTI_MIN), 0, 1023, 0, PITCH_MIN_UPPER);
    pitchMin = constrain(pitchMin, PITCH_MIN_LOWER, PITCH_MIN_UPPER);
    pitchMax = PITCH_MAX_LOWER + map(analogRead(PIN_POTI_MAX), 0, 1023, 0, PITCH_MAX_UPPER);
    pitchMax = constrain(pitchMax, PITCH_MAX_LOWER, PITCH_MAX_UPPER);

    if (buttonState > 0) {
        sensorValue = analogRead(PIN_LDR);

        // apply the calibration to the sensor reading
        sensorValue = map(sensorValue, sensorMin, sensorMax, pitchMin, pitchMax);

        // in case the sensor value is outside the range seen during calibration
        sensorValue = constrain(sensorValue, pitchMin, pitchMax);

        tone(PIN_PIEZO, sensorValue);

        if (buttonState == 2) {
            delay(160);
        } else if (buttonState == 3) {
            delay(50);
        }
        else if (buttonState == 4) {
            delay(250);
        }
    } else {
        noTone(PIN_PIEZO);
    }
}

Schematics

Schematic diagram
Untitled sketch 2 bb bdnk88bjny

Comments

Similar projects you might like

DIY Analog Style Stereo VU Meter on I2C OLED

Project tutorial by Mirko Pavleski

  • 916 views
  • 1 comment
  • 3 respects

DIY Unusual Linear Clock

Project tutorial by Mirko Pavleski

  • 1,503 views
  • 2 comments
  • 5 respects

DIY FFT Audio Spectrum Analyzer

Project tutorial by Mirko Pavleski

  • 22,240 views
  • 2 comments
  • 23 respects

DIY 10Hz-50kHz Oscilloscope on 128x64 LCD Display

Project tutorial by Mirko Pavleski

  • 16,496 views
  • 6 comments
  • 33 respects

DIY Audio Signal Spectrum Analyzer

Project tutorial by Mirko Pavleski

  • 5,892 views
  • 1 comment
  • 10 respects

DIY Balancing Dot on LED Strip

Project tutorial by Mirko Pavleski

  • 4,438 views
  • 1 comment
  • 12 respects
Add projectSign up / Login