9.10 Example: MotorReverserSpeed

/* MotorReverserSpeed
This script drives a motor in one direction, then the other with 
several seconds of time delay in between, repeating indefinitely. 
This script uses analogWrite to drive the motor using pulse width 
modulation (PWM). Speed can be changed by altering the value of 
the integer variable speed between 0 and 255. The digital output 
pins on the Arduino UNO that have PWM capability are 
pins 3, 5, 6, 9, 10, 11. */

#define MOTORA1 11 
#define MOTORA2 10 
int speed = 50; 

void setup(){ 
   pinMode(MOTORA1, OUTPUT); 
   pinMode(MOTORA2, OUTPUT); 
} 

void loop(){ 
   analogWrite(MOTORA1, HIGH); 
   analogWrite(MOTORA2, LOW); 
   delay(5000); 
   analogWrite(MOTORA1, LOW); 
   analogWrite(MOTORA2, HIGH); 
   delay(3000); 
}

 

<PHOTO>

 

 

 

License

Icon for the Creative Commons Attribution 4.0 International License

Applied Electrical Engineering Fundamentals by David J. McLaughlin is licensed under a Creative Commons Attribution 4.0 International License, except where otherwise noted.

Share This Book