Wednesday, July 1, 2015

Sound activated LED PWM circuit



Although I've doing a lot of electronics, I haven't written about it in a while.  I'm in school for electrical engineering and most of my projects have taken place over 2 or 3 months, so by the time they are finished, it is hard to remember my thought process through the whole project.  This project was pretty quick and so it was easy to write about.

This is a simple Sound/voltage Sensitive LED circuit.  LEDs are dimmed most efficiently with pulse width modulation.  For LEDs, this means turning the LED on and off faster than our eyes perceive while varying the ratio of "on time" to "off time" to change the perceived brightness of the LED.  unlike lightbulbs, LEDs have a fixed voltage drop and changing the voltage across an LED does not directly effect the LEDs brightness.

I designed this simple circuit to convert changes in voltage at the input to changes in PWM on LEDs. I achieved this with a 555 and a few op amps. Once I built a the basic Voltage to PWM circuit, it was easy to add a sound input, mic, and "afterglow"(slew circuit).  I designed the system but each of the elements were simple circuits that I've encounter in a lot of different analog projects.

Voltage controlled PWM basics: 
simple voltage controlled PWM shows up a lot in modular synthesizers.  If you have access to a triangle wave (or can create one), you use an op amp to compare a triangle wave to some input voltage(this could be a mic signal).  This will create a square wave and the duty cycle (on vs off time) will be dependent on that voltage signal.

Virtual Ground
Because my circuit uses 5 op amps and a simple 12vdc supply (6 op amps including the virtual ground circuit), I opted to build a virtual ground circuit rather than just a voltage divider at each of the non-inverting input.  Speaking of all this ground/virtual ground stuff.  I spent an few minutes the other day with some 9v batteries and my arduino and a DC adapter and the basic question "when am I allowed(electrically) to connect the grounds of two separate systems. We take for granted that when we plug our headphones output into other circuits, that we are doing just that...connecting the grounds so that the voltage potential between the systems has the same reference. Through my experiments with the batteries, it seemed safe, so long as neither circuit has a reference to the other (electrically isolated through transformers or by being battery powered), you can choose any point in either circuit to equalize as ground reference. For this circuit, incoming signals are reference to the virtual ground.



Getting a triangle wave from a 555: 
If you probe around a basic astable 555 setup, you can find that a triangle (or triangle-ish) wave is available from the charging capacitor on the 555. Because we are using PWM in a more qualitative way, it is not necessary for the wave to be a precise triangle wave.  If we were really picky, we could use 2 op amps to create a very nice triangle wave oscillator without the 555.

I calculated my frequency using this 555 calculator.  In order to get a reasonable triangle wave from the capacitor on the 555, you should shoot for a 50% duty cycle on the 555.

555 calculator



After-glow: 
This is a slew-limiter circuit.  The diode allows the circuit to only control fall time.  When the potentiometer is set to a low resistance state, the capacitor is allowed to fill and empty at a reasonably fast rate. This filling and emptying only happens on the potentiometer side of the circuit because the non-inverting input doesn't sync any current. When the potentiometer is in a high resistive state, the diode allows the capacitor to fill very fast but drain at whatever rate is determined by the resistance of the pot.  This essentially creates a controlled "fall time". For the LEDs, it basically means "after glow".



Electret Mic circuit: 
This is about the simplest electret mic circuit you can find. The 1M resistor is working as a feedback resistor.  Because we are not particularly interested in precision or supplying power, we are using capacitors to separate the DC from AC signal and so we don't need to bias the transistor.



Input Mixer/Offset:
This is the input buffer/amplifier section of the circuit.  It takes my incoming signal and adjust it to a reasonable magnitude and voltage range such that it can be compared to the 555 triangle wave. If you've ever worked with op amps as summing amplifiers, you kinda take for granted that the non-inverting input is usually held to ground. One of the best upsides to having the non-inverting input tied to ground, is that you can calculate each arm (or channel) of the mixing amplifier separately and the voltages at the output will add. This is still basically true for the op amp when the non-inverting input is tied to some other voltage but the math is a little trickier. For example, when the non-inverting input is tied to ground, unconnected inputs to the mixer act pretty much like 0v and "fall out" of the node voltage equations. This will become more clear if you sit around doing node voltage on some op amps for an afternoon.

*note that the "kill all positive voltage diode" actually only kills voltage above the voltage drop of the diode, around .7v. We do this because we want our voltage swing to be 0 to -3v and AC signals, depending on our offset value, can end up greater than 0v after the inversion of the op amp.




555 triangle conditioner: 
This circuit adjusts our 555 triangle signal into a range and magnitude that will easily be comparable to our adjusted input voltage. I made a note that the original waveform (pictured in the box) has a magnitude of around 5v and is off center from our virtual ground.  Again, I did node voltage to calculate my resistor values.  I used a 270k resistor instead of the 280k shown in the diagram.



This is the final comparator circuit before which creates our PWM wave.  One thing of note is the LED and resistor after the op amp and before the 2n2222 transistor.  Because the op amp does not swing "rail to rail", the output from the comparator would never actually turn out because its emitter is tied to -6v and the maximum negative voltage for the op amp is around -5v.  The LED greats a voltage drop which eliminates this problem.  The resistor which isn't labeled was a 1k. 


The node labeled "L" represents the cathode of some series of LEDs (plus a resistor).  my LEDs had a 3.2v drop, so I used 3 in series with a 68Ω resistor.  Because the 2n2222 can handle 800mA of current and each set of 3 LEDs only draws 20mA of current, I designed my light to use 90 LEDs(30 sets of 3).

Basically, thats it.