A 2-pin push switch, also known as a momentary switch, is a basic electronic component that creates a temporary electrical connection when pressed and breaks the connection when released. This type of switch is widely used in various applications such as consumer electronics, industrial controls, and hobbyist projects, including interfacing with microcontroller platforms like the Arduino UNO.
Pin Number | Description |
---|---|
1 | Common terminal (C) |
2 | Normally open (NO) |
When the button is pressed, an electrical connection is made between pins 1 and 2.
// Define the pin connected to the push switch
const int pushSwitchPin = 2;
void setup() {
// Set the push switch pin as an input
pinMode(pushSwitchPin, INPUT_PULLUP);
// Initialize serial communication at 9600 bits per second
Serial.begin(9600);
}
void loop() {
// Read the state of the push switch value
int switchState = digitalRead(pushSwitchPin);
// Check if the push switch is pressed (the pin will read low)
if (switchState == LOW) {
// If the switch is pressed, print a message
Serial.println("Switch Pressed");
// Delay a little to avoid bouncing issues
delay(50);
}
}
Note: The INPUT_PULLUP
mode is used to enable the internal pull-up resistor, which ensures the pin is at a high state when the switch is not pressed.
Q: Can I use the switch with an AC voltage? A: This switch is typically rated for DC voltage. Using it with AC voltage may require a different type of switch.
Q: How do I know if my switch is damaged? A: A damaged switch may not make a connection when pressed or may have a charred or melted appearance.
Q: Is it necessary to debounce the switch in every application? A: Debouncing is recommended for digital circuits, especially when precise input is required. In some simple or slow applications, it may not be necessary.
Manufacturer: Electronics
Part ID: Electronics
Description: A 2-pin push switch is a simple momentary switch that is typically used to send a signal when pressed and released.