Simple Universal Motor Speed Controller

The goal of this project is to build a simple universal motor PID speed controller using a minimum number of components

Similar projects worth following
This project involves hooking live household current directly to an MCU pin. If you are not familiar with and comfortable dealing with household AC current, DO NOT ATTEMPT THIS PROJECT!!!

Based on datasheet information and a little testing, I've found that AC phase control is possible using a very small number of components. My goal is to design and build a universal motor speed controller based on an Atmel 328P MCU and an absolute minimum number of components. My reason for doing so is I need a speed controller for my CNC tool head (a Porter Cable PC690 router) that can be accurately controlled via a PWM output from LinuxCNC, and don't particularly want to spend $140+ for a commercially available controller if I can build one for around $10.

This design is for a very simple AC phase control circuit.  There is however no isolation between the low voltage side and AC side of the circuit.  You have been warned and anyone attempting to build this circuit does so at their own risk.  If you do not know what you are doing, please do not attempt to build this circuit.  There is the very real possibility of damaged components, fire, or injury to people and property if not done correctly.

Now that that is out of the way - this project is for those who don't want to spend over $100 for a digital/analog controllable AC phase control device.  I have laid out a circuit and PCB which is available in Eagle format via the Dropbox link.  The PCB is designed to handle up to about a 30A load (assuming 2oz copper/sqft PCB, 80F ambient, 20F max temp rise), however the current design uses a 24V rated triac to leave a little overhead on what the PCB traces can handle.  Zero crossing is detected via a 1M ohm resistor to AC HOT and a 1M ohm resistor to AC EARTH.  The resistors act as a current limiter (so you don't fry the MCU), while the internal clamping diodes on the atMega 328P clamp the voltage between VCC + 0.5V and GND - 0.5V.  This design is per Atmel's application note AVR182, available here

The zero cross detection is tied to INT0 and simply increments a global counter variable for each falling edge detected.  While more robust circuits use an optoisolator and support passives to detect both zero crossing events in a full AC cycle, this circuit only detects one zero cross per AC cycle.  This requires a little extra work in software to trigger the triac on both half cycles, but also reduces the overall circuit cost. 

To further reduce circuit cost, I am also using a triac that is triggerable directly from an MCU pin and eliminating a second optoisolator and support passives.  As the device I intend to use this with (my CNC mill), has a regulated 5V supply available, I have also neglected to include a 5V power circuit and power must be supplied from off-board. 

The circuit accepts a digital tach input on INT1 for closed loop operation.  This can be supplied by an infrared optical pickup and a bit of white paint on the motor shaft, and hall effect sensor and a magnet on the shaft, or any other sort of tach encoder you have available.  I am coding assuming a single pulse per revolution of the motor shaft, however I intend to make the PPR easily adjustable.  I however do not intend to support quadrature encoders.

Input from the CNC controller will be PWM to ADC1, which is easily supported from the most common CNC control programs (Mach3 and LinuxCNC).  Other control methods are possible, but I do not plan to support them myself.

All of this on a 2.4"x2.4" PCB for easy ordering from SeedStudio or your PCB house of choice on the cheap!

The firmware will be written in Arduino for easy maintainability and modification, and everything will be open source.  I plan to use off the shelf libraries and code as much as possible to make things simple.  If anyone has made it this far into the details and knows of an existing open source AC phase control firmware I can fork for this circuit, please let me know!

As always with my projects, comments, criticisms, and suggestions are always welcome!

  • 1 × Atmel atMega 328P-PU Bare DIP package chip programed with Arduino bootloader
  • 1 × 16MHz crystal
  • 2 × 22pF capacitor For crystal
  • 1 × 10K ohm 1/8W resistor Reset pullup
  • 2 × 1M ohm 1/4W 240V minimum resistor For zero cross detection circuit

View all 16 components

  • Life........

    Rhys09/12/2014 at 20:41 0 comments

    I finally had time to get the Rev-II board etched last night.  Still need to electrical test the traces, drill the holes, apply the top mask, and populate it.  Unfortunately, I have a funeral and such this weekend, so maybe I'll have time next week to work on it some more.  Stay tuned!

  • Rev II Update

    Rhys07/06/2014 at 02:34 0 comments

    Eagle files have been updated to Revision II :)  I added in a MOC3020 opto-triac driver and associated passives.  Hopefully the BTR24 will trigger properly now.  Also removed the ICSP header and added a 4pin serial header instead to make firmware updates easier. PCB size was increased a bit, designed to fit two on a 4x6 PCB blank.  Also replaced the screw headers with large holes and pads to solder the HV wiring to.  Should balance out the added costs of the MOC3020 and passives.

    I'll try to get a PCB etched and populated tomorrow for testing.  Here goes round II!

  • I have not abandoned you!

    Rhys06/27/2014 at 17:50 0 comments

    Just a quick update.  I have not abandoned everyone following this project.  I have the second revision prototype design nearly complete, and the last part I was waiting for to show up from China (PCB toner transfer paper) should be hear today or tomorrow.  However, I will be pulling four grueling 12-14hr days out of town next week pulling and terminating 72 Cat6 drops and installing all of the Telco/network/server equipment for a new office location.  Oh yeah, and building the server room.  Why yes, I do mean building walls with a lockable door and a roof and AC vent, I do carpentry work too lol..... Then Mon/Tues the week after I will be migrating them onto our new domain.  So, while I have the design and the parts in hand, it may be a bit before I have time to etch and assemble prototype mark II.  I will try to get the schematic and PCB files updated to revision mark II this weekend before I leave though :)

  • Hurray!!! Catastrophic Failure!!!

    Rhys06/13/2014 at 18:47 0 comments

    While doing some testing (well, more like probing with a loose wire....), I successfully achieved catastrophic melt your retina high voltage electrical arcing failure!  I'll post a picture momentarily of the post short circuit PCB.  This is why you never probe high voltage circuits unless you are insulated from said high voltage.  Good thing I had the atMega out of it's socket at the time.....  Well, on to revision two.  I think I am going to revise the design to use a MOC2021 opto-triac trigger as I'm not having any success triggering the triac directly from the atMega, datasheet be damned.  I may even decide to throw in an H11AA1 for zero cross detection simply to reduce the code complexity a smidge.  The H11AA1 will give me an interrupt at each zero cross instead of every other one.  Still researching :)

  • Hmmmmm??

    Rhys06/13/2014 at 13:47 0 comments

    Well, good thing first one was just a prototype.  I seem to be having an issue with actually firing the triac.  Still troubleshooting at this point, but I may end up having to either add a proper opto circuit to fire the triac, or switch to a random fire SSR (looking at cost differences before I decide).  While all the data I can find says I SHOULD be able to fire this particular gate sensitive triac directly from an MCU pin, I can't seem to actually get it to fire.  I can see the trigger signal and zero cross signal timing on my logic probe, but the triac does not appear to be latching on.  I've tried adjusting the timing, I've tried adjusting the trigger pulse width (up to about 200us), nothing seems to work.  Tried manually triggering the triac with 5V and 9V and still nothing.  Not sure what the issue is.  I will update again after I investigate some more.....

  • Prototype is assembled :)

    Rhys06/12/2014 at 01:24 0 comments

    Just finished assembling the prototype.  Now to throw some test code on it and see if it works :)  That and figure out what I did with my hall sensor, I seemed to have misplaced it :(

  • Updates

    Rhys06/10/2014 at 02:34 0 comments

    I've uploaded pictures of the prototype PCB and updated the Eagle files to reflect the current prototype.  I'll have a new picture of the top of the PCB once I've done a toner transfer silk screen on it tomorrow morning.  More pictures and an update to come hopefully tomorrow after I get the components mounted :)

  • PCB has holes!

    Rhys06/10/2014 at 00:45 0 comments

    Broke out the drill press and got the holes drilled in the PCB this evening.  Should have it populated tomorrow so I can do some testing of the firmware :)

  • Unforseen delays :(

    Rhys06/08/2014 at 15:14 0 comments

    Well, I succeeded in etching the prototype PCB Wednesday night.  However, I had to make an emergency trip out of state for work and have not had a chance to get the holes drilled in the PCB or pickup the rest of the parts I need so I can assemble it and begin testing.  That should happen early this week.  I plan on drilling the PCB this afternoon and will post pictures once it's done.  As soon as I can get the components picked up, I'll get it assembled and start testing.

  • Haha!!

    Rhys06/04/2014 at 20:45 0 comments

    So, apparently the issue wasn't my printer, it was my heat source.  Things are working much better using a laminator rather than an iron.  First try with the laminator and magazine paper was about 95% successful.  Hopefully the second try will work :)

View all 15 project logs

Enjoy this project?



trankhoaitayto012 wrote 09/01/2023 at 04:58 point

While it's clear that you've put thought and effort into the project, I'd like to emphasize the importance of safety when working with AC current, especially without proper isolation and precautions. Directly connecting household AC current to an MCU pin can be extremely dangerous and can result in electrical hazards, fire, and potential injury. Without proper insulation and isolation, there is a significant risk to both the person attempting to build this circuit and the devices connected to it.

I strongly recommend against attempting to build such a circuit without the necessary safety measures and expertise in electrical engineering. If you're looking to control the speed of a motor in a CNC tool head, there are safer and more reliable methods that can be used, such as commercially available motor speed controllers or designs that incorporate appropriate safety mechanisms and isolation. 

  Are you sure? yes | no

junkin wrote 01/14/2017 at 11:03 point

Is this a finished project? Did it work as expected? I would like to use this to control a small universal motor 0-24Vac I have set up an IR sensor for rpm's and can read speed reliably. I would certainly like to use the zero crossing you have posted (a couple of 1Meg resistors) :) Any guidance would be appreciated. Thanks John

  Are you sure? yes | no

Rhys wrote 06/08/2014 at 15:11 point
Give me another week or two and I should have a final schematic, PCB layout with 3D printable enclosure, and fully tested Arduino code for it. Or if you have the skills and confidence to take my currently incomplete/untested design and run with it on your own, keep us posted on your progress :)

I should have another update this evening with a picture of my prototype PCB once I get all the holes drilled. I had to make an emergency work trip out of state Thur/Fri, so I haven't had a chance to work on it since Wednesday when I managed to etch the PCB.

  Are you sure? yes | no

PointyOintment wrote 06/08/2014 at 00:42 point
I've been looking for a way to control the speed of a vacuum cleaner's motor and this looks perfect. Thanks for the idea and explanation.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates