Recently I was asked it I could put together a light controlled dimmer circuit that used pulse width modulation (PWM) to drive the apparent brightness of a bank of LEDs. A PWM signal has a variable duty cycle (on time v. off time) for a fixed frequency – so a square wave is a PWM signal with 50% duty cycle.
This would be easy with a microprocessor, just read the value of a light dependent resistor connected via a voltage divider circuit and adjust the duty cycle of a PWM output line.
Initially I thought about using a 555 timer based PWM circuit, but the standard “recipe” for this kind of thing does not work too well with an LDR – as this changes not only the duty cycle, but the frequency too.
I had the idea to ‘sweep’ over a triangle wave with the output of the LDR + voltage divider – using a comparator to combine the the two signals. The diagram below shows the basic idea. As the voltage level from the LDR varies with the amount of light falling on it, the proportion of the triangle waveform that is *above* the blue line will vary. So whenever the triangle wave is above the blue line the output (green) will be high, and low otherwise. I chose a value of 1K for the lower portion of the voltage divider purely by experimentation, I don’t really know the values of the LDR, but 1K gave a good sweep of output voltage for the amount of light falling on it.
Hopefully it is clear from the above diagram, that as the blue line moves up and down, the width of the pulses on the green line will increase/decrease. This pulse width is the duty cycle.
I was not alone in this train of thought it seems – http://pcbheaven.com/circuitpages/Voltage_Controlled_PWM_Generator/ is doing something very very similar.
I used an LM324 quad opamp to generate the triangle wave – in a simple square wave + integrator configuration. Adjust the pot until the scope registers a nice clean and symmetrical output. In this configuration the frequency is governed by R2 and C1 and remains fixed over the whole duty cycle.
Add a transistor or a mosfet if you require more current handling capability.