Arduino Light Tone Generator

Having played a little with my 556 Timer Light Theremin I thought it time to get an LDR attached to an Arduino.  A common extension to the Arduino Tone Generator is to replace the potentiometer with a light dependent resistor (LDR) to give a fun instrument that responds to light in a way similar to how a Theremin works – at least at the most simplistic level.

These are the key Arduino tutorials for the main concepts used in this project:

If you are new to Arduino, see the Getting Started pages.

Parts list

  • Arduino Uno
  • 8 ohm speaker or old headphone speaker
  • 1x 220Ω resistor
  • 1x 10k resistor
  • 1x Light Dependent Resistor (LDR)
  • Breadboard and jumper wires

The Circuit

ArduinoLightToneGenerator_bb

The potentiometer from the previous circuit is replaced with a fixed resistor and LDR acting as a potential divider as shown above.  Moving your hand nearer to the LDR will decrease the amount of light hitting it – the more light the lower the resistance, so as you cover it up the resistance goes up.  This means the voltage read at the mid-point will decrease so the value read from the analog input will vary within the range of 0 to 1023.

The output is our simple resistor/speaker circuit we’ve now used many times before.

The Code

The simplest code is actually exactly the same as for the Arduino Tone Generator – it runs as is and gives a fun result.

Find it on GitHub here.

If you want to play further, options include:

  • Use Serial.print to send the read value to the serial port to work out the maximum and minimum values from the sensor and change the range accordingly.
  • Provide some calibration code at the start to work out the above automatically and scale the tone range accordingly.
  • Include an off-switch!

Some code to do the first and last has been added to the following.  Grounding pin 12 will disable the tone output – you could use a switch here if you wish, but I just use a wire.

Find it on GitHub here.

Closing Thoughts

This is a fun project to play with for a while, but where it gets really interesting is to combine light (or other) sensors with some of the synthesis projects.  So that is probably where I’ll go next.

Kevin

Leave a comment