Auduino Light Controller

For the last in this series about using Light Dependent Resistors (for now), I’m having another look at the Auduino Granular Synthesis project.

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
  • 2x 10k resistor
  • 2x Light Dependent Resistor (LDR)
  • 6x 5k potentiometers
  • Breadboard and jumper wires
  • Optional: Auduino output circuit (as described here)

The Circuit

If you recall from the Auduino project, there are currently five potentiometers arranged as follows:

  • A0 – Grain 1 frequency
  • A1 – Grain 2 decay
  • A2 – Grain 1 decay
  • A3 – Grain 2 frequency
  • A4 – the “sync” output (or base frequency)

In principle any, or all, of these potentiometers could be replaced with an LDR but from my experiments I’d recommend considering perhaps just replacing one, but feel free to experiment!

The basic idea is to replace one of the pots in the original circuit according to the following diagram:

Potentiometer-LDR_bb

The best one to start with is perhaps the SYNC potentiometer on A4 giving you control over the base frequency using an LDR.  The synthesis parameters are still set with the four GRAIN control pots but the frequency that the grains are played is now controlled by the LDR.

If you want to control the synthesis parameters then use a pot for SYNC and replace one of the GRAIN frequency controls with the LDR.  I recommend leaving the “decay” pot set to minimum decay (i.e. none) so you can really hear the effect of the LDR.

I did experiment with using an LDR for both SYNC and one of the GRAINs, but wasn’t convinced by that personally.

Putting LDRs on both GRAIN frequency controls worked quite well too, but I’m not sure it really gave much by way of expression over just having the one.

The Code

Just in case it wasn’t already apparent, these were all using the baseline Auduino code as described in the first project – Auduino Granular Synthesis.

Adding a Volume Control

A real Theremin would have some control over the volume as well as pitch and this is possible – we have an Arduino analog input spare!

The following changes are required.

Define the VOL_CONTROL input pin – in this case A5.

#define VOL_CONTROL (5) // Comment out to ignore volume

Add a global variable to record the volume.

uint8_t volume;

At the end of the loop() function add a line to read the volume from the input (I’ve included “#defines” so if the VOL_CONTROL pin isn’t defined then all volume handling is ignored).

#ifdef VOL_CONTROL
  volume = analogRead(VOL_CONTROL) >> 3; // 0 to 127 scaling
#endif

Finally in the PWM_INTERRUPT routine we need to include some processing to take account of the volume setting prior to writing the output value out to the PWM hardware.

#ifdef VOL_CONTROL
  output = output * volume;
  output >>= 7;
#endif

  // Output to PWM (this is faster than using analogWrite) 
  PWM_VALUE = output;
}

As you can perhaps see, this creates a volume setting of between 0 and 127 from the analog input reading which is then used to multiply the output.  This results in an output value that is now potentially 127 times too big, so a shift >> 7 will divide by 128 to bring it back in range once again.

As this new multiplication takes place after the previous scaling (and checking) of the output value this should never end up being too large for the PWM output.

Closing Thoughts

These have all been a fun set of experiments – it is certainly interesting to switch from discrete to continuous control for synthesis for a while.

There are many other options for input devices: force sensitive resistors, slider potentiometers, “membrane potentiometers”, strain gauges, and some amazing touch-sensitive controllers, but many of the principles are very similar to those we’ve already encountered.

One of my favourite input devices, and something I’d like to try at some point, is the core of the Ondes Martinot.  That is essentially a pully system that allows you to glide up and down a fingerboard with a ring-on-a-string and as the string moves it rotates a potentiometer.  There have been several DIY builds over the years so this is definitely doable with some care and thought.

Kevin

One thought on “Auduino Light Controller

  1. This is great! Weirdly, the first thing I did with the circuit after breadboarding it was to change the potentiometers for LDRs. Very similar train of thought, but you’ve gone much more in depth with it. Great post thanks for sharing 🙂

    Liked by 2 people

Leave a comment