Saturday 10 March 2018

Speed control or Dimmer using PWM

Motor Speed Control

In Arduino Uno board, ports 3, 5, 6, 9, 10 and  11 are digital ports that also can be used to send out varying DC voltages using PWM method. All these ports have a tilde(~) mark next to them on the board.

The command used to send out PWM signal is analogWrite(PWM_pin, PWM_value). Here will see how to control DC motor speed  using PWM.

Circuit Diagram:

Diode is used to prevent back emf (generated in motor's coil when the motor current is cutoff) from destroying any semiconductor components. The capacitor is used to filter out electrical noise.

The dc value produced at the PWM port 3 will determine the amount of current flowing from the 9V battery  to the motor. The command analogWrite(3,0) will cutoff the transistor and the motor will not run while the analogWrite(3,255) will sent 5V to the base of the transistor and allow maximum current to flow to the motor and hence produce maximum speed. Varying the PWM value from 0 to 255 will produce the affect of increasing speed.
The following program will cause the motor to increase in speed until the maximum and then gradually reduce to 0. This will repeat indefinitely.

Arduino Code:

const int MOTOR=3; 
void setup() 


  pinMode (MOTOR, OUTPUT);
}

void loop() 

  for (int i=0; i<256; i++) 
{
  analogWrite(MOTOR, i); 
  delay(10); 

delay(2000);
for (int i=255; i>=0; i--)

    analogWrite(MOTOR, i); 
    delay(10); 
}   
 delay(2000); 
}

Note: Instead of motor, a bulb can also be used and this cause dimmer effect. For bulb, the diode can be removed because there is no back emf problem.





No comments:

Post a Comment