The using of a push button will help you to understand how the input works in Arduino Uno.
Be aware, even if the push button has 4 pins, it’s a dipole. In fact, the pins are linked two by two.
To connect the push button, we link the supply (5V) and the ground (GND). To pick up the state of the push button, we link to the pins 2. You can’t link directly the supply to the Arduino card, we need a resistor.
To simplify the circuits, it is possible to modify the program for that the pull-up is inside the Arduino Card.
When we push the button, the led turn on. When we release it, the led turn off.
The supply of the Arduino is 5V, therefore it’s required to put a resistor to not burnt the led. One advice is using a resistor of 220 ohms.
We initialize the led on the pin 2 of the Arduino card. We choose output because the signal go out of the Arduino card to control the LED.
With this circuit you have to push the button to see the LED turn on. This is not really practical, therefore you have to use a switch. In fact, the switch will keep the state unlike the push button. That’s mean you don’t to stay with your finger pressed on the push button to see the light turn on with a switch.
A push button has unexpected functionalities. This is an example of it : We will use the push buttons as keypad.
To know if the password taped by the user is good you have to check the serial monitor.
To simplify the circuit, you can buy a matrix module at 16 buttons
If you liked the keypad and you want to improve the system you can buy a matrix keyboard.
If you prefer a keypad with a professional look, you can buy this one.