ac motor speed adjustment with PWM control


i have AC motor and need regulation in loaded.

For test merge some codes , but no work PWM modulation - pulse width “0” it can not change to a minimum, because program run some microseconds.

Anyone can help me with PWM regulation - how write code for “separate” run PWM?

Here code:

volatile float time = 0;
volatile float time_last = 0;
volatile int rpm_array[5] = {0,0,0,0,0};

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

const int  buttonPin5 = 5; // tlacitko dolu
const int  buttonPin6 = 6; // tlacitko nahoru
int t1 = 0;   // declares variable t1
int t2 = 0;   // declares variable t2
//int t3 = 0;

int pwm = 3; // assigns pin 4 to variable pwm
int buttonState1 = 0;         // současný stav tlačítka
int lastButtonState1 = 0;     // předchozí stav tlačítka

int buttonState2 = 0;         // současný stav tlačítka
int lastButtonState2 = 0;     // předchozí stav tlačítka

int rpm = 0;
int sett= 0; // promenna pozadovanych otacek

void setup()
//Digital Pin 2 Set As An Interrupt
attachInterrupt(0, fan_interrupt, FALLING);
pinMode(buttonPin5, INPUT);  // inicializujte pin tlačítka jako vstup
pinMode(buttonPin6, INPUT);  // inicializujte pin tlačítka jako vstup
pinMode(pwm, OUTPUT); // declares pin 4 as output
// set up the LCD's number of columns and rows: 
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print("RPM:      SET:");


//Main Loop To Calculate RPM and Update LCD Display

void loop()


   //Slow Down The LCD Display Updates
//Update The Rpm Count
lcd.setCursor(0, 1);

//Update The set Count
lcd.setCursor(10, 1); // pozice pro posunutou hodnotu pozadovanych otacek na lcd 
lcd.print(sett);      // hodota pozadovanych otacek na lcd

    buttonState1 = digitalRead(buttonPin5);
    if (buttonState1 != lastButtonState1) {
      if (buttonState1 == HIGH) {
          sett=sett+10; }  
    buttonState2 = digitalRead(buttonPin6);
    if (buttonState2 != lastButtonState2) {
      if (buttonState2 == HIGH) {
          sett=sett-10; } 
          if ( sett < 0) sett = 0 ;

//Update The RPM
if(time > 0)
  //5 Sample Moving Average To Smooth Out The Data
    rpm_array[0] = rpm_array[1];
    rpm_array[1] = rpm_array[2];
    rpm_array[2] = rpm_array[3];
    rpm_array[3] = rpm_array[4];
    rpm_array[4] = 60*(1000000/(time*2));    
  //Last 5 Average RPM Counts Eqauls....
    rpm = (rpm_array[0] + rpm_array[1] + rpm_array[2] + rpm_array[3] + rpm_array[4]) / 5;
    if ( rpm < 0)
    if ( rpm > 5000)
  if ( sett < rpm ) t2 = t2+5; 
  if ( sett > rpm ) t2 = t2-5;
  //if ( t2 < 0) t2 = -1*t2 ;
  if ( t2 < 0) t2 = 0 ;
  if ( t2 > 4500) t2 = 4500;
  //t2= sett;
  t1= 4500-t2;         // subtracts t2 from 1000 ans saves the result in t1
  //analogWrite (3,100);
  digitalWrite(pwm, HIGH); // sets pin 4 HIGH
  delayMicroseconds(t1);   // waits for t1 uS (high time)
  digitalWrite(pwm, LOW);  // sets pin 4 LOW
  delayMicroseconds(t2);   // waits for t2 uS (low time)


//Capture The IR Break-Beam Interrupt
void fan_interrupt()
 time = (micros() - time_last); 
 time_last = micros();

If you add code tags you might get more response ;) See, How to use this forum.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

What are the specifications of your AC motor, can you post link to data and if possible a picture of it.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :)

Speed of an AC motor is determined by frequency, not voltage, so your basic premise is incorrect....

Regards, Ray L.

Your while(1) is unnecessary because it is contained within loop() which acts like while(1).

delay(...) takes one parameter which is an unsigned long, so delay(2.5) gets interpreted as delay(2).

Frequency is 50 hz so PWM regulation work . Pulse width is 20 milisecond but ON or OFF is different and that is why this work.

But need repair code for faster run if possible :confused:

Delay on PWM regulation counts with Length of program and this is error.

I can remove some display print for faster run and better (lower) delay but this is bad result.

Schematics now havent complete.

Hi, Again, what sort of AC motor is it, can you provide a link to its data/spec, or tell us what is written on the name plate, and post a picture of the motor.

I suspect it is not 3phase motor, it may be single phase that needs AC triac phase control. Even a brush type "universal" motor.

We need more information, including circuit diagram PLEASE!! Please post a copy of your circuit, in CAD or a [u]picture of a hand drawn circuit[/u] in jpg, png?

Thanks.. Tom.. :)


here schematic, motor FAN standart 1 phase , i test more motors and same trouble.

Hi, Still no information on motor. How can you sync the PWM to the AC mains. You need to tell us what type of single phase motor it is. And research AC motor control arduino

google is your friend.

Tom.... :) Picture of your motor and its name plate.. please!!!!!!!!!!

It sounds like a shaded pole induction motor - if so you need a V/f speed control, triac circuit
is likely to burn up or set the motor windings on fire due to stalling. The only type of AC
motor you can control with a triac is a universal (ie brushed) motor.

If you want a speed controlled fan, use a DC brushless fan with speed control input. They are
more efficient anyway…

Hi all. I know that this topic is now old (done and dusted) but the guy who was raising the questions about controlling an AC motor wasn't willing to help you guys with the necessary info so you can help him back.

Well, I've a very similar problem that I'm trying to solve but here is the story:

I've got a heavy duty A3 size laminator that I,m trying to tune in such a way that is usable for the toner transfer for making PCB's at home. Now, what I would like to do is Make an arduino based control board that can control the temperature of the heating elements (maybe via a PID type programming) and also be able to control the speed of the motor (i need to slow the motor right down )

Now here is where we stand @ the moment: The heating elements are in total of 350W (mains powered) the motor is a SYNCHRONOUS AC single Phase with 3 wires ( 1 is the common neutral and the other 2 are Forward and reverse. The Model Number is : 60KTYZ and the specs. 10 revs./minute but has a gear box attached to it and the result is 5 revs per minute. Power consumption is Watts or 7mA .

Here is what I've tried so far regarding the motor.

  1. Using a 250W lighting dimmer. It did not work!!!

  2. Using a cheap fan controller that is based on a simple TRIAC and a pot. The same results here.

  3. Using a big rheostat but lost the torch. Speed was the same.

  4. Using a DC motor is out of the question since this is a complete unit and I don't want to risk ruining it.

I know that I need to somehow change the frequency not the voltage but the question still remains: How and using what type of circuit and what kind of components?

So....any ideas anyone on how the heck am I suppose to solve this issue???

Any help is much appreciated. Tnx.

PS: I do electronics as a hobby me putting things together and building stuff...not a problem.

It's really not practical to significantly change the speed of a single-phase AC motor. Variable speed means either a 3-phase AC motor, an AC servo motor, a DC servo motor, a stepper motor, or a "Universal" motor with a TRIAC (i.e. - light-dimmer-type) control.

Regards, Ray L.

Hi, About 15years ago, I was involved in seeing if an office laminator could be modified to do toner transfer.

Temperature control was possible. The problem we found, was to do with roller speed. We ended making a one off motor gearbox assembly, it worked, but was too prohibitive in cost.

Tom... :)