Arduino Nano - Keypad - Beep
This tutorial instructs you how to use Arduino Nano to generate a beep when the keypad is pressed. In detail, Arduino Nano controls the piezo buzzer to emit a short sound for each key press.
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 Keypad and Piezo Buzzer
If you are unfamiliar with keypad and Piezo Buzzer (pinout, how it works, how to program ...), the following tutorials can provide guidance:
The ezBuzzer library is created to enable buzzers to beep or play a tune without interfering with other code.
Wiring Diagram
This image is created using Fritzing. Click to enlarge image
See The best way to supply power to the Arduino Nano and other components.
Arduino Nano Code
Detailed Instructions
- Connect a USB cable between the Arduino Nano and the PC.
- Open the Arduino IDE, choose the correct board and port.
- Click to the Libraries icon on the left bar of the Arduino IDE.
- Search for “keypad” and locate the keypad library created by Mark Stanley and Alexander Brevig.
- Click the Install button to complete the installation of the keypad library.
- Search for “ezBuzzer” and locate the buzzer library by ArduinoGetStarted.
- Then, press the Install button to install the ezBuzzer library.
- Copy the code and open it in the Arduino IDE.
- Click the Upload button in the Arduino IDE to send the code to the Arduino Nano.
- Press certain keys on the keypad.
- Listen for the beep and observe the output in the Serial Monitor.
Code Explanation
Check out the line-by-line explanation contained in the comments of the source code!