While loop

hii there
Sir/ma'am i am doing a project of smart conveyar with arduino board and the problem is
i have to make my DC geared motor to change direction when its recieve the signal from the metal sensor, But i am failing miserably
here is the program
and metal sensor is providing digital output

please help me..i have submisiion in 4 days :cry:

int a = 8;
int b = 9;
int sensorPin = 4;
int val = 0;

void setup ()
{

Serial.begin(9600);
pinMode (a, OUTPUT);
pinMode (b, OUTPUT);
pinMode (sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
}
void loop()
{
int val = digitalRead(sensorPin);
Serial.println(val);
while(val>=1);
{
digitalWrite (a,HIGH);
digitalWrite (b,LOW);
delay(2000);

digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
delay(1000);

digitalWrite(a,LOW);
digitalWrite(b,HIGH);
delay(2000);

digitalWrite(a,HIGH);
digitalWrite(b,HIGH);
delay(1000);
}
}

Thanks

  pinMode (sensorPin, INPUT);

We're supposed to guess what kind of sensor is connected to that pin?

  digitalWrite(sensorPin, HIGH);

You need a comment that explains WHY you are doing this.

  while(val>=1);

Can you find another example of a while statement that ends in a ;?

The body of your while statement is that ;, which means do nothing. If val is ever greater than 0, you have an infinite loop that can never end.

The value returned by digitalRead() is HIGH or LOW. Use those names in the code when you care what the value is.

When you get rid of the incorrect ; on the while line, you'll see that once the while loop starts, you never assign a new value to val, so the while loop will never end.

I really can't see that a while loop is appropriate. Maybe that's simply because it isn't clear what the code in the while body is doing.

i have submisiion in 4 days

If you were submitting the code to me, you'd get a failing grade for the complete lack of comments.