Advertisement
Guest User

Untitled

a guest
Dec 14th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.02 KB | None | 0 0
  1. /*
  2.  * How to connect your "L298N Dual H-Bridge Motor Controller" to "Arduino Uno"
  3.  *
  4.  * ---TEAM PSI------
  5.  */
  6.  
  7. int In1 = 3;//this will connect to motor controller's IN1 male type pin
  8. int In2 = 4;//this will connect to motor controller's IN2 male type pin
  9. int ENA = 5;// this is PWM pin so it will connect to the motor controller's ENA pin
  10. int ENB = 0;// this is PWM pin so it will connect to the motor controller's ENA pin
  11. int In3 = 2;//this will connect to motor controller's IN1 male type pin
  12. int In4 = 1;//this will connect to motor controller's IN2 male type pin
  13. int SPEED = 255; // initialize the speed of the motor
  14. void setup()
  15. {
  16.  /*
  17.   * we need to initialize the digital pins on arduino, using inbuilt "pinMode()" function
  18.   * all the pins will give the output
  19.   */
  20.  
  21.   pinMode(In1,OUTPUT);// tells the arduino that In1 pin is set to give the output
  22.   pinMode(In2,OUTPUT);
  23.   pinMode(ENA,OUTPUT);
  24.   pinMode(In3,OUTPUT);// tells the arduino that In1 pin is set to give the output
  25.   pinMode(In4,OUTPUT);
  26.   pinMode(ENB,OUTPUT);
  27.  
  28.   /*
  29.    * to decides the polarity we need to set one pin "High" and other "LOW"
  30.    * to do so we will take help of "digitalWrite()" function
  31.    */
  32.    digitalWrite(In1,LOW);// to change the direction of the motor simply type "LOW" instead of "HIGH" in Ini and "HIGH" instead of "LOW" in In2
  33.    digitalWrite(In2,HIGH);
  34.    digitalWrite(In3,LOW);// to change the direction of the motor simply type "LOW" instead of "HIGH" in Ini and "HIGH" instead of "LOW" in In2
  35.    digitalWrite(In4,HIGH);
  36.    
  37.    /*
  38.     * now to change the speed of the motor we will need help of inbuilt function called "analogWrite()"
  39.     */
  40.     analogWrite(ENA,SPEED);
  41.     analogWrite(ENB,SPEED);
  42.     /*here we have set the SPEED to 255, you can change it's value between 0 to 255,
  43.      * where 255 means highest speed and 0 lowest speed, Remember there is a
  44.      * threshold value after which the motor will start rotating it may be 30 or 40
  45.      * depends on the type of motor you use
  46.      */
  47. }
  48.  
  49. void loop()
  50. {
  51.  
  52.  
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement