I NEED HELP! arduino uno R3 with motor shield 1.2

I have an arduino uno R3 with a motor shield. I wanna run a DC motor back and forth. There are two proximity sensor at both ends which are used to reverse the direction of the motor. When the sensor is triggered, it can provide 4V output. So I think I can connect it to the digital input to control the motor. After I put all the stuff together and power it on, the motor just ran back and forth in the middle without reaching any ends.

Here is my code:

#include <AFMotor.h>

AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

void setup() {
Serial.begin(9600); // set up Serial library at 9600 bps
Serial.println("Motor test!");

motor.setSpeed(255); // set the speed to 255/255
pinMode(0,INPUT); // use Pin 0 as digital input
pinMode(1,INPUT); // use Pin 1 as digital input

}

void loop()
{

int VOL1=digitalRead(0); //read voltage from pin 0 which is connected to sensor 0
int VOL2=digitalRead(1); //read voltage from pin 1 which is coneected to sensor 1
static int number=0; //add a static value to determine the direction of motor between two ends

if (VOL1==HIGH) //if sensor 0 is triggered, the motor move forward
{
motor.run(RELEASE);
delay(500);
motor.run(FORWARD); // turn it on going forward
delay(1000);
number++; //number++ will make number be odd
}
if (VOL2==HIGH) //if sensor 1 is triggerd, the motor move backward
{
motor.run(RELEASE);
delay(500);
motor.run(BACKWARD);
delay(1000);
number++; //number++ will make number be even
}

if(number%2==1) //if number is odd, which means it just left sensor 0, it should keep going forward until it reaches sensor 1
{
motor.run(FORWARD);
delay(5);

}
else //if the number is even, which means it just left sensor 1, it should keep going backward until it reaches sensor 0
{
motor.run(BACKWARD);
delay(5);
}

}

I really need some help. So thanks so much if you have some advice or solution.

You are more likely to get help if you follow the forum guidelines.

http://forum.arduino.cc/index.php/topic,148850.0.html

I suggest you don't use pins 0 and 1 for the sensor inputs. Use any other available digital pins. Then use the Serial port to print out the values you're reading from the sensors and see whether they're working correctly.