DIY Arduino Keyboard – The best Piezo Buzzer tutorial

From our STAR Maker: Sandheep Gopinath

Arduino Keyboard - Piezo buzzer tutorial

Arduino Keyboard – Piezo buzzer tutorial

Making cool things out of an Arduino is something, but making musical instruments out of an Arduino is quite something else. So behold, here comes the Musical-duino, an arduino keyboard. To see what this does, check out the demo video at the bottom of this page.

They say that “You could become anyone”, so why not become Beethoven or Mozart. If you have an Arduino you could in fact become anyone. The only limit being your imagination. All you need for this project are a few things like an Arduino, jumper wires and a Piezo buzzer.

The DIY arduino keyboard or the Musical-duino has a few buttons. Pressing them makes different melodies according to the pulse sent to it by the Arduino. Your Arduino can be used to make different instruments. It can even be used to make a proximity sensing device to help blind people. A device to detect obstacles and make different voices. You can also make a Theremin out of an Arduino by attaching LDR’s. In case you don’t know what a Theremin is, check here.

And maybe after making one you could play the “legend of Zelda”. And upload a video on YouTube so that we can share your work of art here on our website :)

What are the stuff required to do this?

  1. Arduino Uno, Mega, Freeduino or any of its clones
  2. 2 Pushbuttons
  3. A Piezo Buzzer
  4. A 9 volt battery with the terminal caps
  5. A DC  Jack
  6. Jumper Wires

How stuff works:

Arduino-Keyboard-Circuit-

Arduino-Keyboard-Circuit

One end of each push button is connected to the VCC and the other end to three analog pins. The data from the push buttons are read by the analog pins. This is further compared with a threshold voltage.

Don’t know what’s a threshold voltage? Don’t you worry, we’re here to explain it to you ^_^

Even when the switch is open, the analog pin connected to the button shows a value. When the button is pressed, the analog value reading changes. The value that we get when the switch is open is usually referred as the threshold voltage. To know more about this one you would like to click here.

In later steps, each button is identified on comparison. Corresponding frequencies are produced on the Piezo buzzer using the Arduino.

Step 1 : Connecting the Push Buttons as keys for the Arduino Keyboard

Arduino Keyboard - Piezo buzzer tutorial

Push button connection

Connect all the 3 pins of the push buttons to the 5 volt output on the arduino. If you aren’t aware of how to do that you might follow the image and imitate it. You can further move to understanding the structure of an Arduino over here. After connecting the buttons to the 5 volt output, the other end of them goes to the analog 1, 2 and 3. After doing the above connections, please upload the following code to arduino:

void setup()
{
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
Serial.begin(9600);
}
int a,b,c;

void loop()
{
a=analogRead(A0);
b=analogRead(A1);
c=analogRead(A2);

Serial.print(a);
Serial.print(‘ ‘);
Serial.print(b);
Serial.print(‘ ‘);
Serial.print(c);
}

Now do the following:

  1. Upload the code.
  2. Open the Serial Monitor.
  3. Note the analog values on serial monitor without pressing the buttons as the threshold.
  4. Press the buttons and find the change in analog readings.

Step 2 : Connecting the Piezo Buzzer

Arduino Keyboard - Piezo buzzer tutorial

Piezo Buzzer for Arduino keyboard

Connect the Piezo buzzer as shown positive(red) goes to the 3rd digital pin. And negative (black) goes to the GND pin. After connecting the piezo buzzer, upload the following code to your arduino:

void setup()
{
pinMode(3,OUTPUT);
}

void loop()
{
tone(3,296,10);
delay(1000);
noTone();
}

tone(pinNumber,frequency,duration) //plays a tone of frequency defined on the piezo buzzer connected to pinNumber 3.

noTone() //sets the piezo buzzer into ideal mode with no tone .

Note: The piezo positive can only be connected to the PWM pins or the required output cannot be obtained.

Step 3: Putting together your Arduino Keyboard

Arduino Keyboard - Piezo buzzer tutorial

Final Assembly for Arduino keyboard

Now upload this sketch to your arduino after completing the connections above:

void setup()
{
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(A2,INPUT);
Serial.begin(9600);
}
int a,b,c;
int threshold=400;
void loop()
{
a=analogRead(A0);
b=analogRead(A1);
c=analogRead(A2);
if(a>threshold)
tone(3,200,10);

else if(b>threshold)
tone(3,296,10);

else if(c>threshold)
tone(3,360,10);

else
noTone();
}

Arduino Keyboard - Piezo buzzer tutorial

And Voila!!!! There you go.By now you shall be able to see the big picture. If not, then you might want to read the whole thing again. The image in the 3rd step might turn out to be very helpful to understand about the assembly of this project. Now, check out the demo video of this project:

This project can be enhanced by using LDR’s to replace buttons. And then you can play tones without even touching the board. And feel like a Musician.

A lot to come up with!! DiY Hacking  ^_^

Edited by- Jyoti Patil


Sandheep Gopinath – STAR Maker at DIY Hacking

 

– Project submitted by Sandheep Gopinath and edited by Jyoti Patil

 

 

 

 

 

Recommended Posts
Showing 2 comments
  • Nidhiya
    Reply

    Good tutorial (y)

  • Shreya Haridas
    Reply

    Wow Sandheep! Loved it! The best tutorial I have ever come across! :D

Leave a Comment

84 + = 86

Start typing and press Enter to search