Useful for detecting passage of a moving part or for implementing an electronic limit stop. Setup so that your mechanism wipes the lever and closes the switch as it moves by.

Some pictures of microswitches


Most microswitches have three terminals labelled C, NO, and NC, standing for Common, Normally Open, and Normally Closed, as shown below.

For regular switch action, connect to the C and NO terminals. The switch will be open when not pressed and closed when pressed.

Interface to the Stamp in the usual manner as shown here.

Demo code

In ME2011 lecture, Durfee has a demo showing a motor driven wheel that stops precisely at a pre-determined position because of a microswitch. The code for the demo is in the files below.

badpizza.bs2 -- Attempts to stop the wheel by timing. No good because the wheel velocity slows down as the battery runs down.

goodpizza.bs2 -- Wheel stops by looking for the microswitch to be pressed.

4turnpizza.bs2 -- Same as above, but wheel turns four times then stops.

Additional thoughts

  1. If you have a turntable that you want to stop at several positions, use a single microswitch and place several bumps on the edge of the turntable where each bump closes the switch as it passes by.
  2. If you want to stop the motion at the beginning and end of travel, use two microswitches wired in parallel. These will connect to one Stamp pin. Although the Stamp can't tell which switch is being depressed, the program will know because it will know which direction the motor is turning in.

Where to get a microswitch

Robot store, or Ax-man, or Radio Shack 275-017 (SPDT, 5A contacts, lever arm with roller, $1.99), or many other sources.