Site icon Circuit Ideas for You

Arduino Piano Music Keyboard with Memory Circuit

This project is for Arduino Piano Music Keyboard with Memory Circuit and its main parts are Arduino Uno, push buttons, buzzer, LCD and resistors.

When button is press then buzzer make piano sound, LCD show note name on screen and then we can record notes and play again later.

Furthermore, it is small and fun project and is good for learning Arduino, electronics and music.

Arduino Code:

#include <LiquidCrystal.h>
#include <Tone.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int buzzer = 10;
int keys[8] = {A0, A1, A2, A3, A4, A5, 6, 7};
int notes[8] = {262, 294, 330, 349, 392, 440, 494, 523};
int recordData[100];
int recordTime[100];
int index = 0;
bool recording = false;
unsigned long lastTime;

void setup() {
lcd.begin(16,2);
lcd.print("Arduino Piano");
for(int i=0;i<8;i++){
pinMode(keys[i],INPUT);
}
pinMode(buzzer,OUTPUT);
delay(1000);
lcd.clear();
}

void loop() {
for(int i=0;i<8;i++){
if(digitalRead(keys[i])==HIGH){
tone(buzzer,notes[i],300);
lcd.setCursor(0,0);
lcd.print("Note: ");
lcd.print(notes[i]);
if(recording){
recordData[index] = notes[i];
recordTime[index] = millis()-lastTime;
lastTime = millis();
index++;
}
delay(300);
}
}
if(digitalRead(8)==HIGH){
recording = true;
index = 0;
lastTime = millis();
lcd.clear();
lcd.print("Recording...");
delay(500);
}
if(digitalRead(9)==HIGH){
lcd.clear();
lcd.print("Playing...");
for(int j=0;j<index;j++){
delay(recordTime[j]);
tone(buzzer,recordData[j],300);
}
recording = false;
delay(500);
}
}

Code Explanation:

Circuit Working:

Arduino Piano Music Keyboard with Memory Circuit Diagram

Parts List:

ComponentsValuesQuantity
Resistors (All resistors are 1/4 watt unless specified)10k 3
560Ω1
1.5k1
2.6k1
3.9k1
5.6k1
6.8k 1
8.2k 1
Preset 10k1
SemiconductorsArduino UNO Board1
LCD Display 16×21
Piezo Buzzer 1
Tactile Switches S1 to S8 piano keys8
Record Tactile Switch 1
Replay Tactile Switch 1

Arduino Uno is brain of this project.

The circuit uses a total of 10 tactile switches, eight switches function as piano keys, while two additional switches are located near the buzzer and LCD.

One for Record and one for replay; when button is press then Arduino check which one and each button send signal to Arduino.

Arduino play tone on buzzer for that button and then LCD also show note name and then VR1 preset use for LCD contrast adjust.

After that, power come from Arduino 5V and GND to breadboard rails and resistors used as pull down for buttons.

When record mode is ON, the Arduino saves the notes along with their time intervals and when the user presses the replay button, the Arduino reads the saved notes and plays them again with the same timing.

Formulas:

Frequency of tone given by formula:

f = 1/T

where,

Arduino tone function use square wave.

How to Build:

To build a Arduino Piano Music Keyboard with Memory Circuit follow the below steps for connections:

Push button connections:

Buzzer connections:

LCD connections:

Preset connections:

Conclusion:

To conclude, this Arduino Piano Music Keyboard with Memory Circuit is simple project, it is small and fun to make.

Also, project show how to use buttons, buzzer, LCD and memory in Arduino; furthermore, we can add more notes in future and we can use better buzzer or speaker.

Moreover, we can use SD card for saving songs, it is a good project for learning embedded system and this circuit is also nice DIY music toy for beginners.

Exit mobile version