A Microswitch is a very small and sensitive switch which can be activated by a lever arm. This design often suits its use as a contact or collision sensor in robotic and mobile "buggy" applications.
By placing a microswitch in an appropriate circuit and connecting to a PICAXE input pin the PICAXE can determine if the switch is activated or not.
Microswitch contact detection
The following program looks for microswitch activations on input pin C.0 and counts those activations. When five activations have been counted a LED on output pin B.1 will be set. The 'pause 100' acts as a contact de-bounce; if it is removed contact bouncing may cause the LED to be lit prematurely.
- Code Example:
init: let b0 = 0
main: if pinC.0 = 1 then add
add: pause 100 ; short delay
let b0 = b0 + 1
if b0 < 5 then main
Submit an Example
A microswitch (and 10k pull down resistor) may be connected to the generic terminal block create module.
Bill of Materials
|Miniature SPDT microswitch ||SEN050 ||1 ||Buy Now |
|10k resistor (pack 100) ||RES10K ||1 ||Buy Now |
Submit Your Own Code!
You must be logged in to submit code examples. Login now.