Light controlled PWM generator

by Stephen Hobley on September 17, 2010

Post image for Light controlled PWM generator

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 – 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.

Click for a larger view

Add a transistor or a mosfet if you require more current handling capability.


{ 4 comments… read them below or add one }

Ajol Kahn October 5, 2010 at 3:20 pm

Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment.

sudha March 16, 2011 at 2:49 am

i think i found this page quite useful ……….. might actually help me with a project i’m doing in my college

Kaium November 6, 2012 at 1:05 pm

Nice post man, really helpful.

steyn February 22, 2013 at 2:03 pm

This is very useful in the circuit that i want to construct. Can someone please advice on how to include a preset value. For example to set a value manually and then the ldr must adust to the set value?

Leave a Comment

Comments links could be nofollow free.

Previous post:

Next post: