Friday, 7 October 2016

Controlling speed of a DC motor with PWM and L293D

I've already written a post about PWM (Pulse Width Modulation), but in that post you can see that I have connected the motor directly with the Arduino board there. And in this one I've used a L293D motor driver which can handle high voltage so that you can use high powered dc motor.
Ad

About the pins:
As you can see in the picture above tha pin number 1, 16 and 9 are for Arduino 5v.
- Pin number 2 is to control the motor and according to my sketch it is pin number 2 in Arduino aswel.
- Pin number 3 and 6 are for motor.
- Pin number 4, 5, 12 and 13 are for Arduino GND and GND (-) of external power aswel.
- Pin number 8 is only positive (+) of external power.


int motor = 2;

void setup() {            
  // initialize the digital pin as an output.
  pinMode(motor, OUTPUT);
  pinMode(motor, OUTPUT);

}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(motor, HIGH);   // turn the motor on.
  delay(5);      // wait for miliseconds
  digitalWrite(motor, LOW);  // turn the motor off.
  delay(500);                  
}

The yellow highlighted number is the duration of motor given power from the external battery.
And the green highlighted number is the duration when motor will not spin and of course you can change these numbers to make the motor spin faster and slower.


Ad

No comments:

Post a Comment