Victoryus82

L293D with 2 motors

Jul 8th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //L293D with 2 motors
  2. //Motor A
  3. const int motorPin1  = 16;  // Pin of L293
  4. const int motorPin2  = 12;  // Pin of L293
  5. //Motor B
  6. //const int motorPin3  = 10; // Pin  7 of L293
  7. //const int motorPin4  = 9;  // Pin  2 of L293
  8.  
  9. //This will run only one time.
  10. void setup(){
  11.  
  12.     //Set pins as outputs
  13.     pinMode(motorPin1, OUTPUT);
  14.     pinMode(motorPin2, OUTPUT);
  15.   //  pinMode(motorPin3, OUTPUT);
  16.   //  pinMode(motorPin4, OUTPUT);
  17.    
  18.     //Motor Control - Motor A: motorPin1,motorpin2 & Motor B: motorpin3,motorpin4
  19.  
  20.  
  21.    /*
  22.     //This code will turn Motor B clockwise for 2 sec.
  23.     digitalWrite(motorPin1, LOW);
  24.     digitalWrite(motorPin2, LOW);
  25.     digitalWrite(motorPin3, HIGH);
  26.     digitalWrite(motorPin4, LOW);
  27.     delay(2000);
  28.     //This code will turn Motor B counter-clockwise for 2 sec.
  29.     digitalWrite(motorPin1, LOW);
  30.     digitalWrite(motorPin2, LOW);
  31.     digitalWrite(motorPin3, LOW);
  32.     digitalWrite(motorPin4, HIGH);
  33.     delay(2000);    
  34.    
  35.     //And this code will stop motors
  36.     digitalWrite(motorPin1, LOW);
  37.     digitalWrite(motorPin2, LOW);
  38.     digitalWrite(motorPin3, LOW);
  39.     digitalWrite(motorPin4, LOW);
  40.     */
  41.  
  42. }
  43.  
  44.  
  45. void loop(){
  46.  
  47.    //This code  will turn Motor A clockwise for 2 sec.
  48.     digitalWrite(motorPin1, HIGH);
  49.     digitalWrite(motorPin2, LOW);
  50.  
  51.     delay(2000);
  52.     //This code will turn Motor A counter-clockwise for 2 sec.
  53.     digitalWrite(motorPin1, LOW);
  54.     digitalWrite(motorPin2, HIGH);
  55.  
  56.     delay(2000);
  57.  
  58.     digitalWrite(motorPin1, LOW);
  59.     analogWrite(motorPin2, 75);
  60.  
  61.     delay(2000);
  62.  
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment