Light Controlled Voltage Source

Introduction: Light Controlled Voltage Source

This Instructable is about how to generate a voltage to power something only by a varying light source. It doesnt matter if this light source is the sun or an PWM LED. This voltage source can drive currents up to a few amps (depend on the voltage regulator you choose) and can be created in minimal configuration (LED as a light source) with:

2 resistors and 2 capacitors,



1Arduino or an other PWM source,


and a raw voltage source (whatever you want).

The reason why i came up to this is that I currently work on an controlling circuit for a turntable motor. Thereby I faced some problems with controlling the speed of my DC motor with an AC signal like a PWM signal from my microcontroller.

For this purpose I developed a light controlled voltage source, which does what the name states.
Basically this voltage source uses a combination of a PWM controlled LED, an LDR and the LM317 linear voltage regulator.

Teacher Notes

Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.

Step 1: The Problem

Driving of a motor with a pulse width signal coming from a digital source is often used for controlling the motors speed. Of course you have to implement some transistor/MOSFET to enlarge the currents for the motor.

I want to implement a motor for driving a turntable, which means it shall have a very smooth run over time, exactly at 33,33 rounds per minute. Driving my motor with pwm leads to a very annoying coil noise due to the frequency of my pwm.

Changing this frequency leads to a not well working drive of my motor.

That's why I decided to implement a voltage source, which can be changed by the microcontroller over a certain range to control the speed of my motor.

Remark: pay attention, if you want to implement that on a motor as well: my motor is mainly voltage driven, but there are different motors available, e.g. current driven motors. In this case you can choose the current source circuit from the LM317 datasheet and do the same i did for the voltage source configuration.

Step 2: The LM317

The LM317 is a very famous linear voltage regulator and its very easy to use. As you can see in the image, it only regulates the output voltage in a way, that the voltage on pin *adj* is on a certain level (1.25V). The first resistor is recommended to be at around 240 ohm, so one can use the second resistor to select the output voltage. The capacitors are used for smoothing purposes.

The output voltage can be calculated with Uout = 1.25*(1 + R2/R1).

One can now use a variable resistor R2 to change the output voltage in a certain range. Another good thing about this IC is, that he can handle currents like 500mA and higher, depending on the model we use.This is a must-have in my case, since I want to drive a motor which needs currents like that (I measured my motor, which needs max. 300mA, depending on the load and torsional moment).

Step 3: Variable Resistor

One can think about a variable resistor as a simple potentiometer now, but my main requirement is that the voltage is uC controlled. Therefore the resistor shall be uC controlled as well.
Of course, there are such digital controllable resistors available, but they all have one main disadvantage:

I have to order it, because its not one of the main stream parts I always have available in my little lab.
And i hate ordering stuff - its expensive and needs time, i dont want to spend!

That's why I thought about an other solution to get a resistor which is controllable by my microcontroller. I remembered again my main problem, the pwm signal from my uC and thought about the following:

why not simply dimming and brightening a LED and this led is directly connected to a photoactive resistor or LDR. Both components are often used, very cheap and easily available.

The resistance of a LDR can change, dependent on the light, between a few kiloohms to several hundred very linearly as the picture shows. With white light, my LDR varies between approx. 40kohms and 250ohms. These elements have also a dependency on the wavelengths (picture), which is often between green and yellow - also depend on the type. A pulsed light will also cause pulses in the resistance of the LDR, but because of the time constants in the photoreactive layer, this recognizable frequency is limited - in my case its limited to something around 100Hz. Therefore my 500Hz PWM will be sufficient to illuminate the LDR without disturbing frequencies.

Since this is in theory a very good way to control a resistor with a PWM from a microcontroller, I connected a green led with a LDR via epoxy glue, as you can see in the picture. The connection of both leads now to the main element for my light controlled voltage source.

Step 4: Circuit and Simulation

The circuitry is shown above and consists mainly out of the datasheet circuit from the LM317. The LED part shows the PWM signal, coming from my Atmega368 (pin 9) and a current limiting resistor to prevent the LED from high currents (not really necessary in my case because of limited uC output currents).

I measured the necessary voltage, which i need to drive my motor at the speed range i need. The result is a voltage range between 3V and 6V. With a R1=200 ohm (because i dont had a 240 ohm resistor, 200 ohm are still ok) R2 can be calculated with the given formula to be in the range of approx. 250 to 750 ohm. Although this is nearly the lowest possible value of my LDR it still worked perfectly fine for me in practice.

The low resistance means a bright LED. A big positive here is that the illumination from the surrounding doesnt influence the voltage source, if the LED is very bright. The LDR still recognizes changes from the LED, even if you change the values just a little bit.

i control the LED with 8 bit = 0 -> 255, or in steps from 5V/8bit=20mV. In order to fade my LED off and on, the integers gradually increase the PWM value from 0 (all the way off) to 255 (all the way on) with 500Hz and varying duty cycle. In my case, i drive the LED with something about 170. That is a good value, because there is still space for higher the brightness (=more volts) and the other way around.

I recommend to use the LED at high illuminations = the LDR at low values, but you can connect resistors in parallel to the LDR to lower its relative resistance and therefore prevent the LED from being permanently very bright. This always depends on the intended use.

The potentiometer shown in the schematic can change the range of working, if my calculations arent correct actually that wasnt necessary afterwards).

The simulation in the second picture above shows a resistance change from 250 ohms to 750 ohms in steps of 50 ohms.

Step 5: Build Up and Test

As i already mentioned, this is part of a whole motor control build up.

at first i measured the voltages with a multimeter and i changed the values of the PWM manually. Everything worked fine and the voltage regulation works very quick.

The following video may be a little bit confusing without explanation, so in advance:

The Arduino measures speed values from my turntable and adjusts the light of the LED in a way, that the speed is constant (33.3 rpm is the normal turntable speed). The measurement is done by a second motor as a generator and two LEDs+light barrier on the turntable. Whats really important here, is that the ucontroller tries to higher the voltage, when the turntable is too slow. You can see that in the end, when the LED brightness gets lower and the sound of the rotating turntable gets louder.

Actually this is a really cool side effect, because everytime my turntable lower or higher its speed (starting or stopping) the LED varies its brightness.

--> Light controlled voltage source in use

The controlling (basically a flip flop control) is shown in the second picture with voltages on the y axis in steps from 0 to 255 with 1=20mV and samples on the x axis (recorded with an arduino). What you can see is how subtle the voltage is regulated with the LED. This whole system is theoretically all over a linear system:

linear regulation of the LED brightness due to PWM controll-->LDR resistance and brightness are linear-->resistance and voltage at the LM317 are linear

That implies the whole system to be linear and therefore perfect for the us as a regulator for motor speed and so on.

By the way: This oscillation is an effect of my regulation and the high values at the beginning are an effect of the turntable starts to rotate.

I know that this is a bad choice for controlling motor speed (you can see the permanent control deviation) and i will definately switch to a PI or PID controller in the original project.

I hope you liked my short instructable about this voltage source. If you have questions or comments, just write.

The main instructable about the motor control will follow soon - the other parts of my turntable series are:

RIAA equalization with analog electronics and build up a turntable from 100yo german oak

Sensors Contest

Participated in the
Sensors Contest

Be the First to Share


    • LED Strip Speed Challenge

      LED Strip Speed Challenge
    • Sculpting Challenge

      Sculpting Challenge
    • Clocks Contest

      Clocks Contest

    2 Discussions


    8 months ago

    I can't quite follow. It sounds like you are using a PWM regulated power supply to control motor voltage, and a led, photosensor combo to also control the speed. You particularly lost me at points involving 8 bit programming.

    I am wanting to build a diy turntable, and was looking for a way to accurately control a two pin dc brush motor. I was looking for a purely analog method using a 40A regulated PSU similar to a pc unit, but with a PWM unit built in, and this sounds very interesting. Could you explain the premise of the circuit a little better, perhaps without the arduino?

    It looks like you connected a motor to the drive belt via a tensioner pulley to be a generator powering the LED. The Photo sensor will yield differing voltages based on motor speed, but how is this useful. My PSU has two wires leaving it to go to the two motor leads.


    5 years ago

    My brain now hurts, but I followed it.
    I now know more than I did before.
    Thanks for a well written Instructable.