Adventures in Arduino: Project 06 | Light Theremin

I’m working my way through the Arduino Starter Kit and having a blast doing it. This is the most fun, wholesome use of 70 bucks ever for me!

Project 06 has us building a Light Theremin, basically a “musical instrument” that will use a phototransistor to detect the amount of light that is available, then report that change to a device that plays a tone, informing it when to change the tone to play. The piece playing the tone is known as a piezo.

Calibrating sensors

This seems like it would be an important thing for future projects, glad to have learned it along the way while setting up the Light Theremin.

In previous projects, the fixed resistor and presence of light waves had limited output of sensors… but if the sensors are correctly calibrated, we should be able to explore the sensor’s full range, so the lowest results will indeed be the lowest possible and the highest will be the highest. This was a process and a piece of code that I imagine I will come back to frequently on future projects with sensors.

In booting up the program and waving my hands back and forth over the phototransistor to help it calibrate (as suggested) I wondered if maybe that wasn’t the most efficient way to do it. Would this produce a program that was calibrated accurately for other users, for instance? What if someone decided instead to use a piece of cardboard instead of hands to block the phototransistor lights… would the phototransistor react accurately enough to that?

I think in the future I will try to push the limits as much as possible in the calibration stage to offset this.

Setting Up the Circuit

This time around, I tried reading the diagram and setting up the circuit myself — I missed a few critical elements (like connecting my phototransistor back to the analogIn pin A0 on the Arduino board) but overall I think I’m slowly getting the hang of this strange way of diagramming things….


Once again I have not been super invested in learning the coding aspects of these projects as I am trying to soak up as much as possible about electronics hardware, circuitry and general principles of electrical engineering. I have some knowledge of code and software development, and glancing at the code it looks pretty straightforward (though might be hard to devise myself, I’d probably jump back to this project as a reference before starting a similar project on my own).

But the pseudocode for this build would be something like this:

  1. Declare variables for low/high values of the light sensor, as well as sensor return value (empty at beginning)
  2. Identify/declare the ledPin value on the Arduino board
  3. To calibrate, in the first 5 seconds of booting up, read/identify highest sensor value and lowest sensor value and rewrite variables
  4. Map low and high values to between 50 and 4000, the suggested range of frequencies the Adruino will generate
  5. call tone(), telling it a) what pin to play sound on, what frequency to play, and how long to play note (20 milliseconds to start)
  6. delay playing note for 10 milliseconds

Simple enough, and it worked!

Running the Program

Once again, this Arduino project was not super hard. It took around 45–60 minutes to set up, and it worked pretty quickly. Had a slight problem (again) with my computer not recognizing the board at first but after solving that, was able to get the “Theremin” producing different tones based on whether or not I was waving my hands or covering the phototransistor with a piece of cardboard.

The change in tone was not super dramatic, but I played with the settings in the code and that seemed to yield changes so was overall satisfied with the experience.

Useful Terms from this Project

Piezo: a small element that vibrates when it receives electricity. When it moves, it displaces air around it, creating sound waves. I actually felt this happening by putting my finger over the Piezo. So cool!

Capacitive Change: a capacitive switch is a type of touch-controlled electrical switch that operates by measuring change in capacitance. Upon touching a capacitive switch, this electrical charge disturbs the switch’s own electrical charge; thus, causing a change in capacitance.

map(): this function can map the values you enter to actual sound frequencies, allowing the device to get the most range in the current environment as possible (re-running the setup function will re-modulate, which is good to do in new rooms/environments).



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store