Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Define the pins connected to the L298N motor driver
- const int motorA1 = 2; // A-1
- const int motorA2 = 3; // A-2
- const int motorB1 = 4; // B-1
- const int motorB2 = 5; // B-2
- void setup() {
- // Define the motor control pins as OUTPUT
- pinMode(motorA1, OUTPUT);
- pinMode(motorA2, OUTPUT);
- pinMode(motorB1, OUTPUT);
- pinMode(motorB2, OUTPUT);
- }
- void loop() {
- // Move motor A forward
- digitalWrite(motorA1, HIGH);
- digitalWrite(motorA2, LOW);
- // Move motor B forward
- digitalWrite(motorB1, HIGH);
- digitalWrite(motorB2, LOW);
- // Delay for some time (motor runs forward)
- delay(2000);
- // Stop both motors
- digitalWrite(motorA1, LOW);
- digitalWrite(motorA2, LOW);
- digitalWrite(motorB1, LOW);
- digitalWrite(motorB2, LOW);
- // Delay for some time (motors are stopped)
- delay(1000);
- // Move motor A backward
- digitalWrite(motorA1, LOW);
- digitalWrite(motorA2, HIGH);
- // Move motor B backward
- digitalWrite(motorB1, LOW);
- digitalWrite(motorB2, HIGH);
- // Delay for some time (motors run backward)
- delay(2000);
- // Stop both motors
- digitalWrite(motorA1, LOW);
- digitalWrite(motorA2, LOW);
- digitalWrite(motorB1, LOW);
- digitalWrite(motorB2, LOW);
- // Delay for some time (motors are stopped)
- delay(1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement