Sunday, August 29, 2010

Universal motor speed control by a microcontroller

I am showing a method of using a CdS photoresistor to control a standard triac dimmer circuit that is wired to an electric drill motor (a universal motor). The CdS photoresistor is driven by an LED that is controlled by a PWM pin an an arduino microcontroller. This system provides a very easy way to control 120V AC devices with a single PWM pin, and not use any timing code or worry about zero-crossing of the AC power since this is done intrinsically in the circuit. It also offers true electrical isolation between the AC line voltage and microcontroller.


  1. Hi! In one of my Arduino-based projects I need to place some resistance between two points.

    Currently I am using relays: when 10kOhm is required, use the 10k-connected relay, etc. Alas, this is neither cheap nor reliable.

    How much current can you let through the photoresistor? Is there some simple solution to generate a resistance using only one Arduino pin?

    Thank you!

  2. Maybe you could replace your LED/photoresistor pair with another optocoupler.

  3. elronxenu, most (if not all) optocouplers use a photodiode or phototransistor. This would not work for the described motor speed control since the semiconductor would not allow variable charging of the triac capacitor across a broad range of transmitter LED brightness levels. If you know of any optocouplers that use a photoresistor (and also have a high voltage rating), please let me know.

    Urgentissimo, if your application uses low voltage, I would recommend a digitial pot ( If your circuit needs to handle high-voltage, or if you need true circuit isolation, I would recommend the CdS photoresistor method that I showed in the video. Cds photoresistors (photocells) are available in many resistance and power ranges. Search for photocell. Good luck. If you use PWM to vary the light falling on the photocell, smooth it with a big capactitor and/or increase the PWM frequency coming out of the arduino (search the net for instructions -- I may do a blog post on this as well). Good luck!

  4. Awsome, I have been in the process of building a small CNC machine that uses a standard router. I have PWM out but have not been able to get any circut to work very well however there is a great speed controller similar to the one on your drill. I will keep the SS relay and swap out the pot the same way you have and should have much better controll over the thing :)
    Thanks heaps.!

  5. couple this sort of thing with a heater coil and an opamp/thermocouple and you have a simple temperature controller.

    can you use a phototransistor within an optoisolator? just run it below saturation level?

    why didn't i think of it? i was about to use a servo on a dimmer knob :P

  6. jarrod, I am not sure about running the phototransistor below saturation. It could work, but I think the voltage rating would be the real killer. The triac dimmer circuit will have over 150V across the RC timing circuit, and it would be nearly impossible to find a phototransistor with this high of a voltage rating. You'll also lose the other half of the AC cycle unless you have anti-parallel transistors.

  7. yeah its not so straight forward using phototransistors i now realize.
    I spent the afternoon making a temperature controller for a soldering station heat gun. works really well. and its 100% analog electronics :) i used a dimmer module to drive the heating coil, replacing the upper limit resistor with a photoresistor (leaving the pot in so i can limit the power if i need to) the LED is driven from an op-amp which, using a crazy thrown together circuit with at least 3 voltage dividers, amplifies the thermocouple voltage.
    I love throwing stuff together on a breadboard, then writing and analyzing the schematic later :P

    Cheers for the inspiration.

  8. Hi Ben,

    Nice work. You made Hack-a-Day. congratulations...


    What about a part number for that (supposed) triac on the little board?

    Please give us the name-plate voltage, power, etc. data of the drill you took the board from?

    I would guess the "triac" part on that little board is actually a triac with an internal diac in series with the gate. This arrangement makes the current waveform more symmetrical. There may also be internal components to protect the device against spikes. I don't have a part number for something like this off-hand, but I have seen them before - in another life (anyone else have a part number?)

    More on the diac improvement and the triac circuit "probably" used in this application at the following link. (I say "probably" because you have not supplied a schematic.)

    The Light Dependent Resistor (LDR) with LED combination manufactured as a single part is often called a Vactrol, mostly for historical reasons. But you can still buy actual Vactrol parts on the Internet, but they're hard to find (VTL5C3 is a popular part, around $5 USD ea.) Vactrols are quite popular in audio, music synthesizer and guitar-effect applications.

    Many say yellow LEDs are best with home-made vactrols, I've found green is best. LDR's are most sensitive to light at specific wavelengths (look at an LDR data sheet). Light dependent resistance can take some time to change and has hysteresis with high to low resistance being the slower, if memory serves. Vactrols are definitely not a fast-acting devices.

    You can salvage an LDR and a triac from a cheap screw-in light-controlled AC light bulb fixture.

    There are i2c and SPI serial bus controlled potentiometers available from the likes of Maxim. They're not exactly cheap and you will need at-least a bit-band i2c or SPI driver, which is often a drop-in that may be even easier to use than PWM. But i2c or SPI isolation is another matter. i2c optical isolation may seem simple at first, but there are gotchas. SPI is likely simpler. There are galvanic i2c isolators available from Analog Devices, but they're pricey.

    Don't forget the obligatory DANGER DEADLY VOLTAGES SO DON'T DO THIS baloney in your post. Especially if you are in the U.S. where there is a greedy Trial Lawyer under every door mat.

    Regards, David in Jakarta

    P.S. If you are a non-greedy Trial Lawyer then congratulations - now please do something about all the rest of them.

  9. Perhaps I should clarify a bit. The DIAC in series with the TRIAC gate improves the current waveform symmetry. A DIAC in this application is perhaps better termed a SIDAC or Silicon Diode for Alternating Current. Still looking for a SIDAC/TRIAC part like this, they're out there.

    Rgds Again, David

  10. Hello Ben,
    Do you think that this arrangement would work with a permanent magnet synchronous motor (PMSM), 115V, about 500W?
    Thank you,

  11. Anon, I don't think you can control the speed of a permanent magnet synchronous motor without varying the AC frequency. You will need a variable frequency drive (VFD) to control the speed. Similarly, regular induction motors cannot be speed-controlled by a simple "dimmer circuit" because the frequency of the AC determines the rotor speed.

  12. Hi, Ben. Thanks for this -- this is really useful.

    Please, what are the values of the drill's capacitor, it's original variable resistor, and what kind of triac does it have?

    I have been trying to modify an off the shelf lamp dimmer, but it's designed so that the variable resistor has to handle almost a watt of power, and I can't find a photocell that can take that much; they seem to handle about 1/8 watt typically. I might just ditch this circuit and build one like your drill has.

  13. Anonymous, I was probably overloading the CdS cell a little in the drill's circuit. I don't know the values of the components in the circuit, but you could probably find an SCR with a sensitive enough trigger to make the circuit work with a small CdS. Many cheap electronics (such as the SCR) in a drill motor controller are unlabeled or unhelpfully labeled.