help with arduino motor shield R3 program

I am new in using arduino and especially arduino motor shield and I cannot deal with this shield I tried this program but it doesnot work I know it have mistakes but I am searching in the web but I cannot find a solution

the program that I need to read two switches every switch will forward or reverse some motors
I used if statement and I do not know what is the wrong with the program

not that only motors on pins 12 and 13 are using motor shield the other two motors are using ld293 ic board made by mine
the code

int sensor1 = 4;
int sensor2 = 2;
int m2direction = 12;
int m3direction = 13;
int m2speed = 3;
int m3speed = 11;
int m1input1 = 5;
int m1input2 = 6;
int m4input1 = 7;
int m4input2 = 10;
void setup()
{
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);

  pinMode(m2direction, OUTPUT);
  pinMode(m3direction, OUTPUT);
  pinMode(m2speed, OUTPUT);
  pinMode(m3speed, OUTPUT);
  pinMode(m1input1, OUTPUT);
  pinMode(m1input2, OUTPUT);
  pinMode(m4input1, OUTPUT);
  pinMode(m4input2, OUTPUT);
}
void loop()
{
  digitalWrite(m4input1, HIGH);
  digitalWrite(m4input2, LOW);


  if (sensor2 == HIGH)
  {
    digitalWrite(m1input1, LOW);
    digitalWrite(m1input2, LOW);
    digitalWrite(m2direction, LOW);
    digitalWrite(m3direction, HIGH);

    delay(3000);
    digitalWrite(m2direction, HIGH);
    digitalWrite(m3direction, LOW);

    delay(3000);
    digitalWrite(m2direction, HIGH);
    digitalWrite(m3direction, HIGH);

    digitalWrite(m4input1, HIGH);
    digitalWrite(m4input2, LOW);
  }
  if (sensor1 == HIGH)
  {
    digitalWrite(m1input1, HIGH);
    digitalWrite(m1input2, HIGH);
    digitalWrite(m2direction, HIGH);
    digitalWrite(m3direction, LOW);

    delay(3000);
    digitalWrite(m2direction, LOW);
    digitalWrite(m3direction, HIGH);

    delay(3000);
    digitalWrite(m2direction, LOW);
    digitalWrite(m3direction, LOW);

    digitalWrite(m4input1, LOW);
    digitalWrite(m4input2, HIGH);
  }

}

Moderator edit: [code][/code] tags added. (Nick Gammon)

int sensor2 = 2;
...
  if (sensor2 == HIGH)

...

#define HIGH 0x1

Since HIGH is 1, sensor2 (which is 2) will never be equal to 1.

Perhaps you mean:

  if (digitalRead (sensor2) == HIGH)

Ditto for elsewhere in your code.

thank you for reply but isnot there any other mistakes in the code related to using arduino shield because the mistake you mentioned I know but I changed it hopping to solve my problem but it did not solve it

Right, well post your new code then.

This is a simple code of what I want is this code right????

int sensor1 = 2; int dirA = 12; int speedA = 3; int val1 = 0;

void setup() { pinMode(sensor1, INPUT); pinMode(dirA, OUTPUT); pinMode(speedA, OUTPUT); } void loop() { val1 = digitalRead(sensor1);

if (val1 == HIGH) { digitalWrite(dirA, HIGH); analogWrite(speedA, 128); } else { digitalWrite(dirA, LOW); analogWrite(speedA, 0 ); } }

What is connected to pin 2? How is that device wired? The pin may, or may not, show HIGH when the device is active.

If the device is a switch, you must have a pulldown resistor in order to read HIGH when the switch is pressed.