A micro switch, also known as a miniature snap-action switch, is a small, high-precision switch that operates using a tipping-point mechanism with very little physical force. It is widely used in various applications, including home appliances, industrial equipment, and consumer electronics, to detect the presence or absence of objects, changes in position, or to provide a user with tactile feedback.
Pin Number | Description | Notes |
---|---|---|
1 | Common (COM) | Connects to the moving contact |
2 | Normally Open (NO) | Closed when the actuator is engaged |
3 | Normally Closed (NC) | Closed when the actuator is at rest |
Q: Can I use a micro switch with an Arduino? A: Yes, micro switches can be used with an Arduino for input detection. Ensure that the switch's voltage and current ratings are compatible with the Arduino's I/O pins.
Q: How do I know if my micro switch is working? A: You can test it with a multimeter set to the continuity function. When the actuator is pressed, you should hear a beep if the switch is functioning correctly.
Q: What is the difference between NO and NC contacts? A: NO contacts are open when the switch is at rest and close when actuated. NC contacts are closed at rest and open when actuated.
// Define the pin connected to the micro switch
const int microSwitchPin = 2;
void setup() {
// Set the micro switch pin as an input
pinMode(microSwitchPin, INPUT_PULLUP);
Serial.begin(9600);
}
void loop() {
// Read the state of the micro switch
int switchState = digitalRead(microSwitchPin);
// Check if the switch is pressed (assuming NO configuration)
if (switchState == LOW) {
// The switch is pressed
Serial.println("Switch is pressed");
} else {
// The switch is not pressed
Serial.println("Switch is not pressed");
}
// Add a small delay to prevent bouncing issues
delay(50);
}
Note: The INPUT_PULLUP
mode is used to enable the internal pull-up resistor, which ensures a stable state when the switch is open. The switch is connected between the pin and ground. When pressed, the pin reads LOW
; when released, it reads HIGH
due to the pull-up resistor.