byte msg; 
int button = 8;
int led = 2;

void setup()
{
  pinMode(button, INPUT);  
  pinMode(led, OUTPUT); 
  Serial.begin(9600);    

}
void loop()
{
  if (Serial.available()>=1) 
  // character received
  {
    msg = (char)Serial.read();
    if (msg == 's')  
    {
      // command s: get switch position
      digitalWrite(led,HIGH);
      if (digitalRead(button) == HIGH) {     
        // send 1 for closed and 0 for open
        Serial.print("1"); 
      } 
      else {
        Serial.print("2");
      } 
      delay(200);
      digitalWrite(led, LOW);
    }
  }
}


