Build it step by step
0 of 8 doneInstall the library
Add Keypad by Mark Stanley.
Find the pins
Use continuity to find rows and columns.
Wire the keypad
Rows to D2 to D5, columns to D6 to D8.
Wire the buzzer
Plus to D9, minus to GND.
Upload the sketch
Press keys and watch the serial monitor.
Play notes
Keys 1 to 0 play a scale.
Record a tune
Press star, play up to sixteen keys, press star.
Play it back
Press hash.
How do you build a keypad tone dialer?
A phone-style keypad plays a different tone for each key, like a toy telephone. You need Arduino Nano, Keypad 4x3 (membrane), Passive buzzer and Breadboard 830 Tie Points. It takes 8 steps and about 60 minutes.
- Level
- Beginner
- Time
- About 60 min
- Parts
- 4
Parts list
- Development BoardsBuyArduino Nano × 1
- SwitchesBuy
- Motors & ActuatorsBuyPassive buzzer × 1
- PrototypingBuy
Tick what you already own. It saves to My Garage, so “Build with what I have” knows.
Wiring
| From | To | Why |
|---|---|---|
| Keypad row pins 1 to 4 | Nano D2, D3, D4, D5 | Find rows and columns with a multimeter on continuity first |
| Keypad column pins 1 to 3 | Nano D6, D7, D8 | Same check |
| Buzzer plus | Nano D9 | Passive buzzer |
| Buzzer minus | Nano GND | Common ground |
Code
A 4 by 3 membrane keypad is just twelve switches arranged in a grid of three columns and four rows. The sketch uses the Keypad library, which sets the rows and columns one at a time, finds which key connects them and returns the key as a character. Each of the keys from 1 to 0 is given a note from a musical scale, so the keypad plays a short tune like a toy telephone. A passive buzzer is used because it plays whatever tone the board sends it, which an active buzzer cannot do. The star key starts and stops recording up to sixteen notes, with a high beep when recording starts and a lower one when it stops, and the hash key plays the recording back. Keypad connectors are not standardised, so find the row and column pins first: with a multimeter in continuity mode, press key 1 and see which two pins beep together, then key 2 and so on, and you will see the pattern of three columns and four rows. If the keys come out in the wrong order, swap the pin lists in the sketch.
Runs on a virtual Arduino Nano in your browser, with sliders for the sensors. Happy with it? Verify and upload to your real board from the same page (Chrome or Edge on a computer).
#include <Keypad.h>
const byte ROWS = 4, COLS = 3;
char keys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};
Keypad pad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
const int BUZ = 9;
const int NOTES[10] = {262, 294, 330, 349, 392, 440, 494, 523, 587, 659}; // C4 up to E5
byte rec[16];
int recLen = 0;
bool recording = false;
int noteIndex(char k) { return (k == '0') ? 9 : (k - '1'); }
void playKey(char k) {
tone(BUZ, NOTES[noteIndex(k)], 250);
delay(300);
}
void setup() {
pinMode(BUZ, OUTPUT);
Serial.begin(9600);
}
void loop() {
char k = pad.getKey();
if (!k) return;
Serial.println(k);
if (k == '*') { // start or stop recording a short tune
recording = !recording;
if (recording) recLen = 0;
tone(BUZ, recording ? 1000 : 500, 150);
delay(200);
} else if (k == '#') { // play the recorded tune
for (int i = 0; i < recLen; i++) playKey(rec[i]);
} else {
playKey(k);
if (recording && recLen < 16) rec[recLen++] = k;
}
}Test checklist
What you should see at each check. If a reading is far off, stop and use the troubleshooting list.
| Check | Expected |
|---|---|
| Press 1 | Low note and a 1 in the monitor |
| Press 0 | The highest note |
| Star then a few keys then star | High beep, then low beep |
| Press hash | The tune plays back |
| More than sixteen keys | Extra keys are not recorded |
If it does not work
Wrong keys appear
Swap rows and columns or reverse the pin lists.
Nothing happens
Check every wire and that the keypad is not shifted by one pin.
No sound
Check the buzzer polarity and that it is a passive type.
Two keys at once
Keypads can only report one key at a time, press one.
Reads random keys
A loose wire, press it firmly into the header.
Still stuck? Find the fault step by step with your multimeter →
Common questions
What parts do I need for the keypad tone dialer?
Arduino Nano, Keypad 4x3 (membrane), Passive buzzer and Breadboard 830 Tie Points.
How long does the keypad tone dialer take to build?
About 60 minutes for a beginner maker, in 8 steps.
How do I know the keypad tone dialer works?
Press 1: Low note and a 1 in the monitor. Press 0: The highest note. Star then a few keys then star: High beep, then low beep.
Wrong keys appear: what should I check?
Swap rows and columns or reverse the pin lists.
Nothing happens: what should I check?
Check every wire and that the keypad is not shifted by one pin.
No sound: what should I check?
Check the buzzer polarity and that it is a passive type.
Two keys at once: what should I check?
Keypads can only report one key at a time, press one.
