Problem using L293D Motor Shield, with Buttons

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!

How are the switches (buttons) wired? Are you using pull down resistors?

The more accepted way to wire switches is one side to ground and the other to a digital input with the internal pullup resistors enabled with pinMode(pin, INPUT_PULLUP). The switch will read LOW when closed (pressed) so you need to adjust the logic accordingly.

Hi!
Thank you for responding!
I tried to use PULLUP function, with no success. the weird thing is:

  1. the buttons work fine, as I know from the serial monitor, but they do not turn on the engines.
  2. If I use only 1 button, see code:
#include <AFMotor.h>
AF_DCMotor motor1(1);
AF_DCMotor motor2(2);
int b1 = 9; 
int b2 = 11;
int b3 = 8;
int b4 = 7;
// variables will change:
int bs1 = 0;
int bs2 = 0;
int bs3 = 0;
int bs4 = 0;

void setup() {
pinMode(b1, INPUT_PULLUP);
Serial.begin(9600);
}

void loop() {
motor1.setSpeed(255);
motor2.setSpeed(255);

bs1 = digitalRead(b1);
if (bs1 == LOW) 
{motor1.run(FORWARD); Serial.println("button1");}
else {motor1.run(RELEASE);}


}

Everything works fine. the problem is only when I add the 3 other buttons.

Which, exact, motor shield are you using? What pins does the shield use?