Arduino - Keypad - Beep

When a key on the keypad is pressed, the piezo buzzer beeps. Without delay() function for beeping, there is no keypad's press missed.

Hardware Required

1×Arduino UNO or Genuino UNO
1×USB 2.0 cable type A/B
1×Keypad 3x4 and 4x4 Kit
1×(Alternative) Keypad 3x4
1×(Alternative) Keypad 4x4
1×Piezo Buzzer
1×Jumper Wires
1×(Optional) 9V Power Adapter for Arduino
1×(Optional) Screw Terminal Block Shield for Arduino

One of the following breadboard:

1×Full-sized 830-Point Breadboard
1×Half-sized 400-point Breadboard
1×Mini-sized 170-point Breadboard
1×All-sized Breadboard Kit
Please note: These are affiliate links. If you buy the components through these links, We may get a commission at no extra cost to you. We appreciate it.

About Keypad and Piezo Buzzer

If you do not know about keypad and Piezo Buzzer (pinout, how it works, how to program ...), learn about them in the following tutorials:

The ezBuzzer library is designed for buzzer to beep or play memody without blocking other code.

Wiring Diagram

Arduino keypad piezo buzzer wiring diagram

This image is created using Fritzing. Click to enlarge image

Arduino Code

/* * Created by ArduinoGetStarted.com * * This example code is in the public domain * * Tutorial page: https://arduinogetstarted.com/tutorials/arduino-keypad-beep */ #include <Keypad.h> #include <ezBuzzer.h> const int BUZZER_PIN = 11; const int ROW_NUM = 4; // four rows const int COLUMN_NUM = 4; // four columns char keys[ROW_NUM][COLUMN_NUM] = { {'1', '2', '3', 'A'}, {'4', '5', '6', 'B'}, {'7', '8', '9', 'C'}, {'*', '0', '#', 'D'} }; byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; // connect to the row pinouts of the keypad byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; // connect to the column pinouts of the keypad Keypad keypad = Keypad(makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM ); ezBuzzer buzzer(BUZZER_PIN); // create ezBuzzer object that attach to a pin; void setup() { Serial.begin(9600); } void loop() { buzzer.loop(); // MUST call the buzzer.loop() function in loop() char key = keypad.getKey(); if (key) { Serial.print(key); // prints key to serial monitor buzzer.beep(100); // generates a 100ms beep } }

Quick Steps

  • Connect Arduino to PC via USB cable
  • Open Arduino IDE, select the right board and port
  • On Arduino IDE, Go to Tools Manage Libraries
Arduino add library
  • Search “keypad”, then find the keypad library by Mark Stanley, Alexander Brevig
  • Click Install button to install keypad library.
Arduino keypad library
  • Search “ezBuzzer”, then find the buzzer library by ArduinoGetStarted
  • Click Install button to install ezBuzzer library.
Arduino buzzer library
  • Copy the above code and open with Arduino IDE
  • Click Upload button on Arduino IDE to upload code to Arduino
Arduino IDE Upload Code
  • Press some keys on keypad
  • Listen the beep and see the result in Serial Monitor

Code Explanation

Read the line-by-line explanation in comment lines of source code!

Video Tutorial

We are considering to make the video tutorials. If you think the video tutorials are essential, please subscribe to our YouTube channel to give us motivation for making the videos.

The Best Arduino Starter Kit

※ OUR MESSAGES