Code for using micro switch on Arduino

knut_ny:
connect one one of microsw. to GND.. the other to pin 2 or 3 (UNO)
attach interrupt 0 (pin2) or 1 (pin3).
Now u can stop motor instantly when interupt is triggered.

If wired like above be sure to enable the internal pull-up resistor for the pin(s) you use