Hello guys, I am trying to control 2 motors for robot wheels with a l293dne, and the issue I am having i that they both need to be the same speed. My issue is that when I make the speed slower on the faster motor, it spins, stops momentarely, then spins again instead of a smooth movement. Any ideas?
EDIT: they are running on a 9v battery. I also noticed that the faster motor I am having trouble with stops immediately when it does not recieve power, so I think its a problem with the motor
const byte MOTOR1_PIN_A= 2;
const byte MOTOR1_PIN_B= 4;
const byte MOTOR1_ENABLE= 3;
const byte MOTOR2_ENABLE= 11;
const byte MOTOR2_PIN_A= 12;
const byte MOTOR2_PIN_B= 13;
void setup(){
pinMode(MOTOR1_PIN_A, OUTPUT);
pinMode(MOTOR1_PIN_B, OUTPUT);
pinMode(MOTOR1_ENABLE, OUTPUT);
pinMode(MOTOR2_PIN_A, OUTPUT);
pinMode(MOTOR2_PIN_B, OUTPUT);
pinMode(MOTOR2_ENABLE, OUTPUT);
void loop(){
forward(MOTOR2_PIN_A, MOTOR2_PIN_B, MOTOR2_ENABLE, 255);
forward(MOTOR1_PIN_A, MOTOR1_PIN_B, MOTOR1_ENABLE, 180);
delay(5000);
stop_(MOTOR1_ENABLE);
stop_(MOTOR2_ENABLE);
delay(5000);
}
void stop_(int enablePin){
analogWrite(enablePin, 0);
}
void forward(int pin1, int pin2, int enablePin, int speed_){
digitalWrite(pin1, HIGH);
digitalWrite(pin2, LOW);
analogWrite(enablePin, speed_);
}