Tuesday, July 1, 2014

PWM Motor Speed Control using Arduino - Circuit Diagram and Program

Eltronicschool. - In this time we will give you circuit schematic diagram and also the listing program of PWM Motor Speed Control using Arduino that we get from circuitstoday.com site. We hope this article will hopeful to you in learning arduino microcontroller for many application.

Circuit diagram

Figure 1. PWM Motor Speed Control using Arduino - Circuit Diagram (Source:circuitstoday.com)

Component List
  1. Keypad 4x4
  2. Arduino UNO
  3. R1 = 100
  4. Q1 = 2N2222
  5. D1 = IN4007
  6. C1 = 0.1uF
  7. M1 = DC Motor 9V 150mA

Description

Circuit diagram as like in figure 1 above is PWM Motor Speed Control using Arduino. According circuitstoday describe that Row pins R1 and R2 of the hex keypad are interfaced to digital pins 6 and 7 of the arduino. Column pins C1, C2, C3 and C4 are interfaced to the digital pind 10, 11, 12 and 13 of the arduino. 

The key pressed on the hex keypad is identified using the column scanning method and it is explained in detail in this article. Interfacing hex keypad to arduino. The digital pins of the arduino can source or sink only up to 4omA of current. So the digital pin 3 cannot drive the motor directly. 

To solve this problem an NPN transistor (2N2222) is used to drive the motor according the the PWM signal available at digital pin 3. 100 ohm resistor R1 is used to limit the base current of the transistor. The motor is connected as a collector load to the transistor. 

The 0.1uF capacitor C1 connected across the motor is used to by-pass the voltage spikes and noises produced during the switching of the motor.

Listing Program

int pwm=3; // declares digital pin 3 as PWM output
int r1=6;
int r2=7;
int c1=10;
int c2=11;
int c3=12;
int c4=13;
int colm1;
int colm2;
int colm3;
int colm4;

void setup()
{
  pinMode(r1,OUTPUT);
  pinMode(r2,OUTPUT);
  pinMode(c1,INPUT);
  pinMode(c2,INPUT);
  pinMode(c3,INPUT);
  pinMode(c4,INPUT);
  pinMode(pwm,OUTPUT);
  digitalWrite(c1,HIGH);
  digitalWrite(c2,HIGH);
  digitalWrite(c3,HIGH);
  digitalWrite(c4,HIGH);
  digitalWrite(pwm,LOW);
}
void loop()
{
  digitalWrite(r1,LOW);
  digitalWrite(r2,HIGH);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)         //checks whether key "1" is pressed.
  { analogWrite(pwm,42); // writes "42" (duty cycle 16%).
   delay(200);}
  else
  {
   if(colm2==LOW)        //checks whether key "2" is pressed.
   { analogWrite(pwm,84); // writes "84" (duty cycle 32%).
    delay(200);}
   else
   {
   if(colm3==LOW)        //checks whether key "3" is pressed
   {analogWrite(pwm,126); // writes "126" (duty cycle 48%).
   delay(200);}
   else
   {
   if(colm4==LOW)        // checks whether key"A" is pressed.
   {digitalWrite(pwm,LOW); // makes pin 3 LOW (duty cycle 0%).Motor OFF.
    delay(200);}
   }}}

  digitalWrite(r1,HIGH);
  digitalWrite(r2,LOW);
  colm1=digitalRead(c1);
  colm2=digitalRead(c2);
  colm3=digitalRead(c3);
  colm4=digitalRead(c4);
  if(colm1==LOW)         // checks whether key "4" is pressed.
  {analogWrite(pwm,168); //writes "168" (duty cycle 64%).
  delay(200);}
  else
  {
   if(colm2==LOW)        // checks whether key "5" is pressed.
   {analogWrite(pwm,202); // writes "202" (duty cycle 80%).
  delay(200);}
   else
   {
   if(colm3==LOW)        // checks whether key "6" is pressed.
   {analogWrite(pwm,244); // writes "244" (duty cycle 96%).
    delay(200);}
   else
   {
   if(colm4==LOW)          // checks whether key "B" is pressed.
   {digitalWrite(pwm,HIGH);//makes pin 3 HIGH (duty cycle 100%). FULL POWER
   delay(200); }

   }}}}

Source: circuitstoday.com




0 comments:

Post a Comment

Thank's for your reading in this article, please don't forget to comment.