
Switches are also known as mechanical end stops. They are commonly used to help a robot sense the world around it. For example, in a CNC machine, the moving parts will back up until they contact the switch and then stop. This is called their "home" position.
void setup() {
Serial.begin(9600);
pinMode(YOURPIN,INPUT);
}
void loop() {
Serial.println(digitalRead(YOURPIN));
delay(100);
}