Thanks for all. Now I made it like this and I got what I want from it:
int Switch = 2; //Pin for sensor switch
int buttonState; // current state of the button
int lastButtonState = 0; // previous state of the button
void setup()
{
Serial.begin(9600);
pinMode(Switch, INPUT);
Serial.begin(9600);
}
void loop()
{
buttonState = digitalRead(Switch);
if (digitalRead(Switch) == HIGH && buttonState != lastButtonState) {
Serial.println("open");
delay(180);
}
lastButtonState = buttonState;
if (digitalRead(Switch) == LOW && buttonState == 1){
Serial.println("Close");
delay(200);
}
}