Arduino Light Mozzi Generator

Now we have our simple LDR circuit there are a number of other experiments we can try.  This page suggests a few more ideas based on the examples provided with the Mozzi synthesis library.

  • In part 2 I build this up on stripboard.

Tutorials used in this project:

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

Parts list

The Circuit

ArduinoLightToneGenerator - Part 2_bb

In this circuit I’ve replaced the speaker and 220Ω resistor with a 3.5mm Jack Socket and moved the output to digital pin 9.

I’ve also added a second LDR and both LDRs are now on A0 and A1, which are more compatible with the Mozzi examples “out of the box” (although it is usually pretty easy to change them in the code).

LDRs with Mozzi

A number of the demonstration sketches from the Mozzi Library use LDRs.  Here are a selection of some of the fun ones.

For details of how to get Mozzi installed and running, see Arduino PWM MIDI Synthesis with Mozzi.  After that, just download the appropriate example and start playing!

Mozzi -> 02.Control -> Control_Echo_Theremin

This example uses one LDR.  It changes the pitch according to the sensor reading, but does it within a delay function which creates some wonderful other-worldly sounds.  It is great fun to try.

Mozzi -> 03.Sensors -> Knob_LightLevel_FMSynth

This is actually designed for a potentiometer and an LDR but works great with two LDRs. Once controls the pitch and the other the synthesis parameters.  The closer to the LDR the more complex the synthesis.  Again it makes a great sound.

There are a number of other FM demos under 03.Sensors designed for one potentiometer and one or two LDRs using A0, A1 and A2.  They are all worth experimenting with!

Mozzi -> 03.Sensors -> Light_Temperature_Detuned

This is actually designed for use with a thermistor and an LDR, but works pretty well with two LDRs.  The default code uses A1 and A2 though, so if you are still using A0 and A1 (as described above) find the pin values near the top of the file and change them to 0 and 1:

#define THERMISTOR_PIN 1
#define LDR_PIN 0

One LDR controls the speed of vibrato and the other will detune the sound as you cover the sensor. If you want a bigger “detuning” effect, you can increase the value of OFFSET_SCALE.  Anything up to 0.5 worked well for me.

Mozzi -> 03.Sensors -> Volume_Knob_LightLevel_Frequency

This is designed for use with a potentiometer and an LDR, but using it with two LDRs creates an effect much closer to the function of a Theremin.  One LDR will control the pitch and the other will control the volume.

One slight enhancement that makes the volume control more sensitive, and lets you take it down to zero, is to scale the input that would have been from the potentiometer to fit a range more appropriate to the LDR.  The simplest way is to add the following two lines into the updateControl() function after the call to mozziAnalogRead as follows:

void updateControl(){
// read the potentiometer
int knob_value = mozziAnalogRead(KNOB_PIN); // value is 0-1023

// Add the following two lines to scale the knob_value for an LDR.
knob_value = knob_value - 200;
if (knob_value < 0) knob_value = 0;
// The rest of the code stays the same.

Closing Thoughts

I was going to revisit some of my own Mozzi projects but they are all geared up for MIDI-driven operation so don’t really work very well with something like this that is much better with a continuous tone.

But to be honest, the built-in examples that come with Mozzi cover so much ground between them that there is plenty of scope for experimentation already.  My favourite is definitely the Control_Echo_Theremin though – I’m seriously tempted to build this into a proper project with a case and everything!

Having said that, pretty much any one of the projects on this site that rely on potentiometers as a control input could in principle have the pots replaced with LDRs.

Kevin

Leave a comment