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

Click for a larger view

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

Share

{ 8 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?

Tuan Mathurin May 22, 2015 at 7:38 pm

Davvero un ottimo articolo. Mi piace il vostro blog. Continuate cosi 😉

yair June 2, 2015 at 2:38 pm

hey, i found your design and made a schema/board layout (in process)
https://github.com/5shekel/light2PWM

kar540 November 26, 2015 at 8:38 am

I want to know exactly duty cycle range of the above circuit.

Eduardo September 4, 2017 at 5:02 pm

I’ve made the circuit and it is working.
But I need to know if there is the possibility to make it working the inverse way.
I mean, right now, the PWM is increasing as the LDR is in darkness. I want to implement this in a circuit to adjust the brightness of a 7 segment display, so in the darkness the brightness will be lower, and in daylight the brightness will be higher.

Leave a Comment

Comments links could be nofollow free.

Previous post:

Next post: