A round push button is a simple yet essential electronic component used to control the flow of electric current in a circuit. It acts as a mechanical switch that can be pressed to either make (close) or break (open) an electrical connection. This type of button is commonly used in various applications such as consumer electronics, industrial machinery, and hobbyist projects, including interfacing with microcontrollers like the Arduino UNO.
Pin Number | Description |
---|---|
1 | Common (COM) |
2 | Normally Open (NO) |
3 | Normally Closed (NC) |
Note: Some round push buttons may only have two pins (COM and NO) if they do not offer a normally closed configuration.
// Define the pin connected to the push button
const int buttonPin = 2;
// Define the pin connected to an LED (or other device)
const int ledPin = 13;
// Variable to store the state of the button
int buttonState = 0;
void setup() {
// Initialize the LED pin as an output
pinMode(ledPin, OUTPUT);
// Initialize the push button pin as an input
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
// Read the state of the push button value
buttonState = digitalRead(buttonPin);
// Check if the push button is pressed
// If it is, the buttonState is LOW
if (buttonState == LOW) {
// Turn on the LED
digitalWrite(ledPin, HIGH);
} else {
// Turn off the LED
digitalWrite(ledPin, LOW);
}
}
Note: The INPUT_PULLUP
mode enables the internal pull-up resistor, which is a best practice for push button circuits.
Q: Can I use a round push button with a higher voltage rating in a low-voltage circuit?
A: Yes, using a button with a higher voltage rating than your circuit's voltage is generally safe.
Q: How do I know if my button requires debouncing?
A: If you notice erratic behavior or multiple activations with a single press, debouncing is likely necessary.
Q: What is the difference between normally open and normally closed buttons?
A: Normally open buttons make the circuit when pressed, while normally closed buttons break the circuit when pressed.