Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * How to connect your "L298N Dual H-Bridge Motor Controller" to "Arduino Uno"
- *
- * ---TEAM PSI------
- */
- int In1 = 3;//this will connect to motor controller's IN1 male type pin
- int In2 = 4;//this will connect to motor controller's IN2 male type pin
- int ENA = 5;// this is PWM pin so it will connect to the motor controller's ENA pin
- int ENB = 0;// this is PWM pin so it will connect to the motor controller's ENA pin
- int In3 = 2;//this will connect to motor controller's IN1 male type pin
- int In4 = 1;//this will connect to motor controller's IN2 male type pin
- int SPEED = 255; // initialize the speed of the motor
- void setup()
- {
- /*
- * we need to initialize the digital pins on arduino, using inbuilt "pinMode()" function
- * all the pins will give the output
- */
- pinMode(In1,OUTPUT);// tells the arduino that In1 pin is set to give the output
- pinMode(In2,OUTPUT);
- pinMode(ENA,OUTPUT);
- pinMode(In3,OUTPUT);// tells the arduino that In1 pin is set to give the output
- pinMode(In4,OUTPUT);
- pinMode(ENB,OUTPUT);
- /*
- * to decides the polarity we need to set one pin "High" and other "LOW"
- * to do so we will take help of "digitalWrite()" function
- */
- 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
- digitalWrite(In2,HIGH);
- 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
- digitalWrite(In4,HIGH);
- /*
- * now to change the speed of the motor we will need help of inbuilt function called "analogWrite()"
- */
- analogWrite(ENA,SPEED);
- analogWrite(ENB,SPEED);
- /*here we have set the SPEED to 255, you can change it's value between 0 to 255,
- * where 255 means highest speed and 0 lowest speed, Remember there is a
- * threshold value after which the motor will start rotating it may be 30 or 40
- * depends on the type of motor you use
- */
- }
- void loop()
- {
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement