Interfacing with the Arduino
Here are 3 ways of interfacing the Arduino with various electronics, especially bent circuits and analog audio circuits. The circuits are actually pretty non-specific and can be used for interfacing with pretty much any micro controller, but we’ll just talk about the Arduino to keep it simple.
The circuits above allow the Arduino to control physical electronics in three ways:
-digitally controlled variable resistor
-variable voltage (using a digital to analog convertor).
I’ll talk about each one in detail below.
A simple, brute force way of using one of the PWM (pulse width modulation) outputs of the Arduino to create variable effects in other circuits.
HOW IT WORKS:
This simple circuit uses PWM to modulate the brightness of an LED. The LED is mechanically connected to an LDR which is a light sensitive resistor. As the brightness of the LED modulates, the resistance of the LDR changes as well. Read at the bottom of the page for more info on PWM.
HOW TO BUILD:
Making a vactrol
For this circuit you first need to make a vactrol. There’s lots of tutorials for how to do this online if you want more info.
-Connect an LED to a light dependent resistor face to face. I found that high brightness LEDs are TOO bright. Average red LEDs will work fine. You’ll also need a 220 ohm current limiting resistor in there to keep the LED from getting too bright and burning out.
-The LED is polarized and the LDR is NOT. Mark the negative leg of the LED with a marker or piece of tape.
-Make sure the face of the LED and the LDR are touching and wrap a piece of electrical tape or heat shrink tubing around them, something that will ensure that no light gets in.
*If you want to be organized about it you can bend all of the legs in the same direction and solder them to a piece of perf board. This is a good way to do it if you want to make several vactrols for one system. Make sure the material you use to connect and insulate the LED/LDR is secure and wont let ANY light in.
Now you can connect the vactrol to your system.
Connecting the vactrol to the Arduino.
-Connect the negative leg of the LED to the ground terminal of the Arduino.
-Connect the positive leg of the LED to one of the PWM output pins of the Arduino.
-Assigning a number value to the chosen output terminal will set the pulse width of a square wave at that terminal.
Connecting the vactrol to your circuit.
First you have to find a feature that you want to alter and CAN be alter by varying a resistance in your circuit. A good example of this is pitch. Most audio circuits have a pitch resistor. Altering the value of this resistor changes the pitch. For more info on this check out my pitch adjustment tutorial(If you follow that tutorial you will be using the vactrol in the “attenuator method”).
-Find a resistor in your circuit that you want to control with the vactrol.
-Remove that resistor. You may want to install a switch that lets you switch between vactrol control and a preset resistance.
-Connect the two legs from the LDR in your vactrol to the two points on your board where the original resistor used to be.
I strongly recommend installing a limiting resistor, especially if you are controlling pitch. Lowering the resistor too much can fry the circuit. a limiter resistor will guarantee that even if the LDR resistor drops to zero there will still be some resistance in the circuit.
I’ve illustrated a few other configurations below which I have found useful in tuning in the Vactrol resistance range.
A FEW NOTE ON LDRs
- LDRs come in many different ranges of resistance. A common range is between 100 – 500k ohms. This range is from bright light to complete darkness.
- Make sure the LDR in your vactrol is completely insulated from environmental light. ANY light that gets in, even in a dim room, can drastically alter the range of the LDR.
- It is important that you use the LDR to replace a resistor of a similar value. For instance replacing a 1k resistor with a 500k LDR wont do much. It is possible to place a resistor in parallel with the LDR to tighten its range but this can drastically change its resistance curve.
DIGITAL TO ANALOG CONVERTOR
This design is cheap and dirty but it works. It’s noisy and vulnerable to loading effects from low load resistance. There are lots of other schematics online which will give you more stable results. Most use op amps instead of transistors. I wanted something cheap and small so went with this design. It’s clean enough for what I’m doing and works fine if you are using it to drive an op amp input like the CV inputs of an analog synth.
PWM – PULSE WIDTH MODULATION
PWM is a way of creating a varying (analog) signal using a digital signal. Digital outs either generate 5 volts or 0 volts. That’s 2 states. If you want to generate a signal somewhere between those states you have to get clever. That’s where PWM comes in. The Arduino has several PWM output pins. These output a high frequency square wave with a variable duty cycle. Duty cycle is the ratio of time the wave is high vs low. Lets say 1 cycle of the wave is 100 micro seconds. A 50% duty cycle means the wave will be high for 50mS and low for 50mS. A 20% duty cycle will be high 80mS and low 20mS.