1

I am building a remote control car using an Arduino and a l293d motor shield but only 1 port in the shield works among the other 4, why is that?

Below is my code:

char Incoming_Value = 0;
#include<AFMotor.h>
AF_DCMotor motor1(3);
AF_DCMotor motor2(2);

void setup() {
  Serial.begin(9600);
  pinMode(13, OUTPUT);
  motor1.setSpeed(255);
  motor2.setSpeed(255);
}

void loop() {
  if (Serial.available() > 0) {
    Incoming_Value = Serial.read();

    if (Incoming_Value == '1')
      digitalWrite(13,HIGH);

    motor1.run(BACKWARD);
    motor2.run(BACKWARD);

    if (Incoming_Value == '0')
      motor1.run(FORWARD);

    motor2.run(FORWARD);
    digitalWrite(13,LOW);

    if (Incoming_Value == '2') // LEFT
      motor1.run(BACKWARD);

    motor2.run(FORWARD);
  
    if (Incoming_Value == '3') // RIGHT
      motor1.run(BACKWARD);

    motor2.run(FORWARD);
  
    if (Incoming_Value == '5')
      motor1.run(RELEASE);

    motor2.run(RELEASE);
  }
}
1
  • 1
    1. You only use 2 Motors/Ports in your Program. 2. No matter what happend in the if statement your last statement is to switch off motor2. And this for each run of the loop method. So, what you observe and what you've programmed match well. I assume that there are missing braces? ;-) Jan 5 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.