Tuesday, 11 February 2020

How to Build an Arduino Theremin

In this short tutorial, you will learn how to build an Arduino Theremin. You only need three components plus the Arduino, wires, and breadboard.

Use the breadboard diagram or the video below to see how to connect everything.

The Components You’ll Need

  • Buzzer (passive)
  • Photoresistor
  • Resistor 220Ω
  • Arduino
  • Wires
  • Breadboard
Shows the breadboard connections for the Arduino Theremin

How The Arduino Theremin Works

An Arduino theremin isn’t the same as the original theremin invented by Léon Theremin where you can control both amplitude and frequency.

But it’s a fun and simple project anyway!

The photoresistor is connected with the resistor to form a voltage divider. The Arduino reads the voltage out from the voltage divider.

This means that when the photoresistor changes its resistance (that is when the light changes) the voltage that the Arduino reads changes.

The Arduino controls the frequency of the buzzer. By using the voltage value the Arduino reads in, the Arduino changes the tone of the buzzer so that the tone you hear is directly dependent on the light that the photoresistor sees.

The Arduino Code

Copy and paste the code below into a new project. Then compile and upload the code to your Arduino.

int analogPin = A0; // Input from photoresistor connected to A0
int buzzerPin = 4; // Positive buzzer pin connected to pin 4

long max_frequency = 2500; // Max frequency for the buzzer

long frequency; // The frequency to buzz the buzzer
int readVal; // The input voltage read from photoresistor


void setup() {
    pinMode(buzzerPin, OUTPUT); // set a pin for buzzer output
}

void loop() {
    readVal = analogRead(analogPin); // Reads 0-1023
    frequency = (readVal * max_frequency) / 1023;
    buzz(buzzerPin, frequency, 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);
    }
}

Questions?

Did you build this Arduino Theremin? Are you having problems building it? Let me know in the comments below.

Copyright Build Electronic Circuits

No comments:

Post a Comment

Physicists develop new method to visualize magnetic nanostructures with high resolution

A new method enables researchers to analyse magnetic nanostructures with a high resolution. The new method achieves a resolution of around 7...