• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Build Electronic Circuits

Build Electronic Circuits

Electronics explained in a simple way

  • Start Learning
    • Basic Electronics
    • Digital Electronics
    • Circuits
    • Practical Skills
      • Printed Circuit Boards
    • Microcontrollers
      • Arduino
    • Maker Lifestyle
      • Podcast
  • About Me
  • Blog
  • Products
  • Contact
You are here: Home / Microcontrollers / Arduino / How to Build an Arduino Theremin

How to Build an Arduino Theremin

February 11, 2020 By Øyvind Nydal Dahl 7 Comments

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.

Filed Under: Arduino

Reader Interactions

Comments


  1. ron hathcock says

    February 17, 2020

    where can I find a program to program a 8052 micro

    Reply

  2. Jaimie says

    February 19, 2020

    This sounds like a good project for semi-beginners! Thanks for sharing.

    Reply

  3. A says

    April 28, 2020

    I used the code you used and it didn’t work. My circuit was correct and I used your code, but it still didn’t work. I have a SparkFun RedBoard, and not an Arduino Uno. Is that the reason? Since it didn’t work, I wrote a different code (teto is the buzzer, photo is photoresistor, and fullfre is the max frequency:

    int teto = 5;
    int photo = 0;
    long fullfre = 200;
    long frequency;
    int value;

    void setup() {
    pinMode(teto, OUTPUT);

    }

    void loop() {
    value = analogRead(A0);
    frequency = fullfre + value / 25;
    tone(teto, frequency);

    }

    After I uploaded the code above, the buzzer started making a sound finally. However, I am not able to ‘play’ with it like you did in the video. It doesn’t change when I move my fingers. It does change when I use a flashlight on it however, but not when I move it closer although.

    Reply

    • admin says

      April 30, 2020

      I see that you are using pin 5 for the buzzer, while I used pin 4. Could that be it? Or that you connected the buzzer in the opposite direction?

      Reply

  4. Nizar says

    January 18, 2021

    the code isn’t working I’m using the mega 2500 and it is saying redefinition of void setup()

    Reply

    • admin says

      January 19, 2021

      Sounds like you have two void setup() in your code. I don’t have that in my code, so try copying again and make sure you delete any old code from your sketch.

      Reply

      • Nizar says

        January 22, 2021

        it didn’t work

        Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Primary Sidebar

Search:

Footer

Topics

  • Basic Electronics
  • Digital Electronics
  • Circuits
  • Practical Skills
  • Microcontrollers
  • Maker Lifestyle
  • Newsletter Archive

Social:

  • Facebook
  • Twitter
  • YouTube

Copyright © 2021 · Ohmify AS · Terms and Conditions · Privacy Policy