This code is uploaded in my arduino uno with attached arduino motorshield. It doesnot works as needed . Is there a problem in the library or the arduino uno or arduino motorshield itself. It just keeps rotating.
</code?>
#include <AFMotor.h>
AF_DCMotor rightBack(1);
AF_DCMotor rightFront(2);
AF_DCMotor leftFront(3);
AF_DCMotor leftBack(4);
const int motorSpeed = 150; // Speed of the motors
void setup() {
rightBack.setSpeed(motorSpeed);
rightFront.setSpeed(motorSpeed);
leftFront.setSpeed(motorSpeed);
leftBack.setSpeed(motorSpeed);
}
void loop() {
moveForward();
delay(1000); // Adjust this delay as needed
}
void moveForward() {
rightBack.run(FORWARD);
rightFront.run(FORWARD);
leftFront.run(FORWARD);
leftBack.run(FORWARD);
}
I just want the car to move forward but instead the dc gear motor goes backward forward randomly. I was testing the code but doesnot acts as commanded.