Arduino UNO R4 - Keypad 3x4
This tutorial instructs you how to use Arduino UNO R4 with keypad 3x4. In detail, we will learn:
- How to connect a 3x4 keypad to Arduino UNO R4.
- How to program Arduino UNO R4 to read the pressed key from a keypad 3x4
- How to check the password entered on a keypad.
Hardware Preparation
Or you can buy the following sensor kits:
1 | × | DIYables Sensor Kit (30 sensors/displays) | |
1 | × | DIYables Sensor Kit (18 sensors/displays) |
Additionally, some of these links are for products from our own brand, DIYables .
Overview of 3x4 Keypad
The keypad has 12 membrane buttons arranged in rows and columns, known as a matrix. Each button is called a key.
Pinout
A 3x4 keypad has 7 pins, divided into two categories: rows and columns.
- 4 pins are for the rows (R1, R2, R3, R4).
- 3 pins are for the columns (C1, C2, C3).
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Uno R4 and other components.
Arduino UNO R4 Code
Detailed Instructions
Follow these instructions step by step:
- If this is your first time using the Arduino Uno R4 WiFi/Minima, refer to the tutorial on setting up the environment for Arduino Uno R4 WiFi/Minima in the Arduino IDE.
- Connect the Arduino Uno R4 to the 3x4 keypad according to the provided diagram.
- Connect the Arduino Uno R4 to your computer using a USB cable.
- Launch the Arduino IDE on your computer.
- Select the appropriate Arduino Uno R4 board (e.g., Arduino Uno R4 WiFi) and COM port.
- Go to the Libraries icon on the left side of the Arduino IDE.
- Type DIYables_Keypad in the search box, and look for the keypad library by DIYables.io.
- Press the Install button to install the keypad library.
- Copy the code above and open it with the Arduino IDE.
- Click the Upload button in the Arduino IDE to upload the code to the Arduino UNO R4.
- Open the Serial Monitor.
- Press some keys on the keypad.
- Check the results in the Serial Monitor.
Keypad and Password
A common use of a keypad is entering a password. In this use, we highlight two special keys:
- A key to begin or begin again entering the password. For example, key "*"
- A key to end entering the password. For like, key "#"
The password will be made up of the remaining keys, excluding two chosen special keys.
When a key is pressed.
- If the key is not "*" or "#", add the key to the password the user is entering.
- If the key is "#", check if the password entered by the user matches the set password, then erase the entered password.
- If the key is "*", erase the entered password.
Keypad - Password Code
- Run the code provided above.
- Open the Serial Monitor.
- Enter the keys "123456" and then press "#".
- Enter the keys "1234" and then press "#".
- Check the results on the Serial Monitor.