This project creates a simple digital keypad that uses push buttons to play musical notes via a piezo buzzer with Arduino. This is also an educational project demonstrating reading analog inputs and generating sounds with Arduino.
Devices and components
Arduino Starter Kit [English]
USB 2.0 Type A/B Cable
Arduino Uno Rev3
10k ohm resistance
Breadboard Jumper Wire Pack (200mm & 100mm)
Push button
Resistance 1 Mohm
Mini bread board - White
Resistance 330 ohms
Piezoelectric buzzer
Materials and tools
Laptop
Software and tools
Fritzing
Arduino IDE
Project description
Digital keyboard with sound output using Arduino
Code for digital keypad with sound output
Use this code in the Arduino IDE.
1int notes[] = {262, 294, 330, 349};
2
3void setup() {
4 Serial.begin(9600);
5}
6
7void loop() {
8 int keyVal = analogRead(A0);
9 Serial.println(keyVal);
10
11 if (keyVal == 1023) {
12 tone(8, notes[0]);
13 } else if (keyVal >= 990 && keyVal <= 1010) {
14 tone(8, notes[1]);
15 } else if (keyVal >= 505 && keyVal <= 515) {
16 tone(8, notes[2]);
17 } else if (keyVal >= 5 && keyVal <= 10) {
18 tone(8, notes[3]);
19 } else {
20 noTone(8);
21 }
22}
Downloadable files
Digital keyboard with sound output using Arduino
Arduino Project - Rexhep Mustafovski .pdf
Documentation
Fritzing Circuit Diagram – Numeric Keypad with Arduino
Rexhep Mustafovski.png
Note: Content and images are from: https://projecthub.arduino.cc/, with some modifications.
If you want it removed due to copyright reasons, please leave a comment. Thank you.
I want to share this article more widely so that everyone knows about Arduino and your project.