A limit switch is an electromechanical device that operates based on the movement or presence of an object. It is designed to detect the presence or absence, passing, positioning, and end of travel of an object. When an object comes into contact with the actuator of the limit switch, it operates the contacts to make or break an electrical connection. Limit switches are commonly used in industrial control systems to control machinery and in various applications such as conveyor systems, elevators, and machine tools to provide precise control and positioning.
Pin Number | Description | Notes |
---|---|---|
1 | Common (COM) | Connects to the power supply or ground |
2 | Normally Closed (NC) | Closed when the switch is not actuated |
3 | Normally Open (NO) | Closed when the switch is actuated |
Q: Can I use a limit switch with an Arduino? A: Yes, limit switches can be connected to an Arduino's digital input pins.
Q: What is the difference between NO and NC contacts? A: NO contacts close when the switch is actuated, while NC contacts open when actuated.
Q: How do I know if my limit switch is working? A: You can test it with a multimeter or by observing the operation of the connected load.
Below is an example of how to use a limit switch with an Arduino UNO to control an LED:
// Define the connection pins
const int limitSwitchPin = 2; // Limit switch connected to pin 2
const int ledPin = 13; // LED connected to pin 13
void setup() {
pinMode(limitSwitchPin, INPUT_PULLUP); // Set the limit switch pin as input
pinMode(ledPin, OUTPUT); // Set the LED pin as output
}
void loop() {
// Read the state of the limit switch
bool isPressed = digitalRead(limitSwitchPin) == LOW;
// If the switch is pressed, turn on the LED
if (isPressed) {
digitalWrite(ledPin, HIGH);
} else {
digitalWrite(ledPin, LOW);
}
}
Note: The INPUT_PULLUP
mode is used to enable the internal pull-up resistor, which is useful when using a NO limit switch. When the switch is open, the pin is pulled to a high state. When the switch is closed (actuated), it connects the pin to ground, resulting in a low state.