Hello!
I am trying to control 2 DC motors, with 4 buttons, using L293D Shield.
The problem:
Engines are not responding to the buttons, even tough the serial screen accepts all button inputs.
If I erase the code regarding to 3 buttons and leave only the code for 1 button, it will turn on the engine while pressing the button, but when I add the code for the rest of the buttons, the engines do not respond to the button input.
Here is the code:
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
int b1 = 9;
int b2 = 11;
int b3 = 8;
int b4 = 7;
int bs1 = 0;
int bs2 = 0;
int bs3 = 0;
int bs4 = 0;
void setup() {
pinMode(b1, INPUT);
pinMode(b2, INPUT);
pinMode(b3, INPUT);
pinMode(b4, INPUT);
Serial.begin(9600);
}
void loop() {
motor1.setSpeed(255);
motor2.setSpeed(255);
bs1 = digitalRead(b1);
if (bs1 == HIGH)
{motor1.run(FORWARD); Serial.println("button1");}
else {motor1.run(RELEASE);}
bs2 = digitalRead(b2);
if (bs2 == HIGH)
{motor1.run(BACKWARD);Serial.println("button2");}
else {motor1.run(RELEASE);}
bs3 = digitalRead(b3);
if (bs3 == HIGH)
{motor2.run(FORWARD);Serial.println("button3");}
else {motor2.run(RELEASE);}
bs4 = digitalRead(b4);
if (bs4 == HIGH)
{motor2.run(BACKWARD);Serial.println("button4");}
else {motor2.run(RELEASE);}
}
Thanks a lot!
P.S. I am new to arduino so please reply with simple code, Thanks again!