motor runing one lap

im trying to make my motor to run only one lap wait and to run another lap but have some issue

int motor=2;
int button=3;
void setup(){
  pinMode(motor, OUTPUT);
  pinMode(button, INPUT);
  Serial.begin(115200);
  Serial.print("REDY");
}
void loop(){
  while(Serial.available()>0)
  {
    char aChar=Serial.read();
    if (aChar=='g')
    {
      Serial.println("RUN");
      digitalWrite(motor,HIGH);
      digitalRead(button)==LOW;
    }
  }
  if (digitalRead(button)==HIGH)
  {
    Serial.println("STOP");
    digitalWrite(motor, LOW);
  }
}

i try different setups wit this code but my motor run one lap or he stops and stays stop or hes not runing

The following line:

digitalRead(button)==LOW;

does nothing useful (it reads the pin, compares the value with LOW, and throws the result away).

How do you have the button connected to the Arduino?

like i write i try difrent setups im using PIN 3 to button and PIN 2 for motor
hers some photos
http://imageshack.us/a/img11/5/20121028195540.jpg
http://imageshack.us/a/img713/1323/20121028195220.jpg

  1. Unless you have an external pullup resistor connected, you need to change pinMode(button, INPUT) to pinMode(button, INPUT_PULLUP).

  2. Is the switch closed at the "home" position, or open?

  3. After you start the motor, you will need to wait for the motor to move away from the home position before you start looking to see whether the switch indicates that the home position has been reached again.

the home position is open
if the motor run the switch is closed
have modified the code

int motor=2;
int sw=3;
void setup(){
  pinMode(motor, OUTPUT);
  pinMode(sw, INPUT_PULLUP);
  Serial.begin(115200);
  Serial.print("REDY");
}
void loop(){
  while(Serial.available()>0)
  {
    char aChar=Serial.read();
    if (aChar=='g')
    {
      Serial.println("RUN");
      digitalWrite(motor,HIGH);
    }
  }
  if (digitalRead(sw)==HIGH)
  {
    Serial.println("STOP");
    digitalWrite(motor, LOW);
  }
}

but now my serial print STOP all the time and i cant restart the motor

After the line

digitalWrite(motor,HIGH);

to start the motor, you need to keep the motor on until the switch closes, before you proceed to wait for the switch to open again. Try inserting this after that line:

while (digitalRead(sw) == HIGH) { }
delay(10);

The first line waits for the switch to close and the second one allows for contact bounce. Alternatively, just use delay(1000) so that the motor runs for at least one second, which is hopefully long enough for the switch to close.

heh its working +/-