Push buttons
Component | Push buttons |
Type | Input |
Function | Handle input from a user |
Introduction
A push button is a simple input device that is used to control an electronic system. It is a type of switch that is activated by pressing it. When the button is pressed, it makes an electrical connection and sends a signal to the system. Push buttons are commonly used in applications such as keyboards, remote controls, and other devices that require user input.
Pin Description
A push button has two pins. When the button is pressed, it makes an electrical connection between the two pins, which sends a signal to the system. You can connect the push button to a digital pin on a microcontroller to read the state of the button. You can use a pull-up or pull-down resistor to ensure that the pin has a defined state when the button is not pressed.
Most push buttons have 4 pins, these are internally connected.
Code Example
The following code example demonstrates how to read the state of a push button using an Arduino board.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
(This example uses the Serial library to print the button state to the serial port. You can view the output using the Serial Monitor in the Arduino IDE.)