How To Make A Mini Musical Keyboard Using Arduino

by | Dec 29, 2022 | Arduino, Basic Coding, Coding

Home » Coding » How To Make A Mini Musical Keyboard Using Arduino

Introduction

In this Arduino tutorial, we will learn how to make a mini musical keyboard using Arduino to produce different sounds using a piezo buzzer. It will take different inputs based on the resistors we connected, which will divide the voltage. It can be further modified to some musical instruments as well!

A mini musical keyboard is a small electronic instrument that allows you to play music by pressing keys or pressing buttons. It is typically smaller and more portable than a traditional keyboard, making it an ideal choice for musicians on the go or for those with limited space. Mini musical keyboards typically have a range of built-in sounds, including pianos, organs, and synthesizers. They may also have features such as built-in drum patterns and the ability to connect to a computer or other devices. They are often used by beginners learning to play an instrument and experienced musicians looking for a portable and versatile performance tool.

 

Supplies

To make Mini Musical Keyboard using Arduino, we will require the following components:

Components

Circuit Diagram

How To Make A Mini Musical Keyboard Using Arduino

Steps To Make A Mini Musical Keyboard Using Arduino

Step 1: Gather all the components on the Digital Board or Physical Table.

Step 2: Plug the Piezo & Push Buttons on the BreadBoard.

Piezo:

Step 3: Connect the Positive Terminal of the Piezo to the Ground(GND) pin of the Arduino using a black-colored wire.

Step 4: Connect the Negative terminal of it to the 8-number pin of the Arduino on the Digital side.

PushButtons:

Step 5: Connect any one terminal of all the PushButtons to resistors and then to the 5V pin of the Arduino at its Analog Side, as shown in the figure.

Step 6: Connect the Second Terminal of all the Push Buttons to the GND pin of the Arduino, as shown in the figure.

Step 7: Connect the Third Terminal of all 1st buttons to the third terminal of the second and so on till the last. In the end, connect the third terminal of the last button to analog pin A0 of the Arduino.

Source Code

int keys[] = {262,294,330,349};
void setup()
{
Serial.begin(9600);
}
void loop()
{
int keyVal = analogRead(A0);
Serial.println(keyVal);


if(keyVal == 1023)
{
tone(8, keys[0]);
}
else if(keyVal >= 900 && keyVal <= 1010)
{
tone(8, keys[1]);
}
else if(keyVal <= 500 && keyVal <= 800)
{
tone(8, keys[2]);
}
else if(keyVal >= 50 && keyVal <=400)
{
tone(8, keys[3]);
}
else
{
noTone(8);
}
}

Explanation Of The Code

1. In the beginning, we initialized an integer array “keys” with the notes of the sounds that will be produced by the buzzer.

2. After that, we used the setup function to establish a serial connection with a speed of 9600 bits per second.

3. After this, we used a loop function, which will keep on looping once the Arduino starts.

4. In this function, we have initialized one variable, “keyVal” that will store the Analog input from the buttons. We are printing the analog value to the serial montoir using serial print.

5. After this, we use an if-else ladder to produce a particular note from the buzzer based on the key pressed.

Output

Once you have compiled the source code without errors, you will get the following output of this Arduino project.

How To Make A Mini Musical Keyboard Using Arduino

On pressing different switches as keys of the keyboard, we will get different sounds as voltage will be divided respectively.

 

 

You May Also Like To Create…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *