Beruflich Dokumente
Kultur Dokumente
Submitted by
PRANESH S (161EC222)
APRIL 2019
ARDUINO BASED PIANO PIEZO BUZZER
MINI PROJECT REPORT
Submitted by
PRANESH S (161EC222)
APRIL 2019
BONAFIDE CERTIFICATE
SIGNATURE SIGNATURE
Dr.C.POONGODI, Dr.C.POONGODI,
HEAD OF THE DEPARTMENT, PROFESSOR AND HEAD,
DEPARTMENT OF ECE, DEPARTMENT OF ECE,
BANNARI AMMAN INSTITUTE BANNARI AMMAN INSTITUTE
OF TECHNOLOGY, OF TECHNOLOGY,
SATHYAMANGALAM-638401. SATHYAMANGALAM-638401.
ABSTRACT I
LIST OF FIGURES II
LIST OF SYMBOLS III
1 INTRODUCTION 1
NEED OF THE SYSTEM 2
2 LITERATURE REVIEW 3
3 HARDWARE COMPONENTS 4
3.1 CIRCUIT DIAGRAM 4
3.2 PUSH BUTTONS 5
3.3 ARDUINO (UNO) 7
3.4 BUZZER 9
3.5 TECHNIQUES USED IN ARDUINO 11
6 CONCLUSION 19
6.1 FUTURE SCOPE 20
7 REFERENCE 21
ABSTRACT
In the recent days, piano is an musical instruments and that is used to play sounds
according to our tune and it is played by using an keyboard. This is an new-
technology where we can record and play sounds according to our interest. Also,
it also leads to emerging to new discoveries and technologies like we can play
any musical instruments with the help of Arduino platform. A special feature of
this piano project is that Arduino will record the last played set of tones and it
will repeat those tones like a one time record and repeat feature. This project
doesn’t include or have any Real-Time Applications but can be used to
understand certain features of Arduino like its sound producing capabilities using
the tone() function. Arduino has been an boon to many people who are not from
electronics department or the background. But, this piano is just pretty with the 8
push buttons and an single buzzer. It is not going to be a conventional professional
piano but it is very close to the one that it is love to play using the push buttons
and the Piezo-buzzer. The main advantage is that in this project, we don’t need
an professional musician but here we only need an maker. We can make our tune
according to our desire and interest. This generates only Pulse Width
Modulation(PWM) signals for their operation and the recording purpose. It is also
similar to the projects like Heart Rate Monitor, Robotic Arm as well as Home
Automation Applications and so on. This project is an automation for the
professional musicians and it is an simple project to display an Piano demo
according to our tune functions and it is helpful for the beginner-level musicians.
LIST OF FIGURES:
1.1 BUZZER 1
SYMBOL NAME
PUSH BUTTON
ARDUINO UNO
BUZZER
CHAPTER 1
INTRODUCTION
LITRATURE REVIEW
Arduino has been a boon for people who are not from the electronics
background to build stuff easily. It has been a great prototyping tool or to try
something cool, in this project we are going to build a small yet fun Piano using
the Arduino .This piano is pretty much plain with just 8 push buttons and buzzer.
It uses the tone() function of Arduino to create various types of piano notes on
the speaker. To spice it up a bit we have added the recording feature in the project,
this enables us to play a tune record it and play it again repeatedly when required.
The Arduino has a handy tone() function which can be used to generate varying
frequency signals that can be used to produce different sounds using a buzzer. So
let’s understand how the function works and how it can be used with Arduino.
Before that we should know how a Piezo buzzer works. Here we apply a variable
current (frequency) for which the crystal vibrates thus producing sound. Hence in
order to make the Piezo buzzer to make some noise we have to make the Piezo
electric crystal to vibrate, the pitch and tone of noise depends on how fast the
crystal vibrates. Hence the tone and pitch can be controlled by varying the
frequency of the current. The values of pin can be any of your digital pin. I have
used pin number 8 here. The frequency that can be generated depends on the size
of the timer in your Arduino board. For UNO and most other common boards the
minimum frequency that can be produced is 31Hz and the maximum frequency
that can be produced is 65535Hz. However we humans can hear only frequencies
between 2000Hz and 5000 Hz. It will going on progress for the compatibility
considerations and to reduce the size to transport it to any locations when required
in manual mode. Using tone () function, you can generate square waves of
different frequencies but with fixed duty cycle (50%). Internally, the tone ()
function relies on the Timers of Arduino UNO (ATmega328P Microcontroller).
CHAPTER 3
HARDWARE COMPONENTS
They are mostly found on the biased switches, many unbiased buttons will
requires an spring to return to their un-pushed state depending upon their
operation. The Push buttons are also used or seen in the calculators, telephones,
and Kitchen Appliances . The Red push buttons have large heads for their
operation and to control the stopping of the machine.
The push buttons are also used to avoid the controller by pushing the incorrect
switch , also these are often colored code to access them for their operation.
Mostly used colors are red for stopping the machine and green for starting the
machine. The mostly used colors are red for the stopping of the process and
green for starting the process.
FIGURE 1.3 OCTAGON BUTTON
These red buttons also has larger heads for their simple operation and to control
the stop of a machine. These red buttons are also called as an Immediate button
and are mandated by the electrical code.
3.3 ARDUINO(UNO):
It was started around 2003 as an program for students at the Interaction Design
Institute Ivrea in Ivrea, Italy, aiming to provide an low-cost and easy way for
professionals to create the devices that interact with their environment by
using sensors and actuators. The common examples of such devices used for the
beginner hobbyists include simple robots, thermostats, and motion detectors etc.
Buzzers and Sounders are also known as audio alarms, audio indicators, audio
transducers, piezo buzzers, beepers and/or audible alarms. Typical uses of
buzzers and beepers include Alarm Devices, Timers, and Confirmation of user
input such as a Mouse or a Keystroke. Light weight, simple construction and low
price make it usable in various applications like car/truck reversing indicator,
computers, call bells etc.
APPLICATIONS:
WORKING:
1. Make the connections as per the circuit diagram and upload the code to
Arduino. Once the power to the circuit is turned on, Arduino is ready to accept
the input from the buttons.
2. Each button is associated with a PWM signal in the code. When a button is
pushed, that particular PWM signal is generated through the Piezo Electric
Buzzer.
3. Now for the record and repeat mode, play a few tones using different
buttons.
4. With each button pressed, Arduino starts recording i.e. makes note of the
sequence of the buttons, it’s on time and off time. Once you are done with the
tone, you can push the Interrupt Button.
5. As soon as the Arduino enters Interrupt Mode, all the previously pressed
tones are played back through the Piezo Buzzer.
6. During normal tone playback i.e. when the buttons are being pressed, the
LED on pin 13 stays ON. During repeat mode, it stays OFF.
CONCEPT:
1. The main concept of the Arduino based Piano is very simple. Here, we had
used Push Buttons for Recording Purpose.
2. Actually, I have made Interrupt Button as the Stop stage to play the recorded
tone.
3. The main aim of this project is to Play the tone according to the user’s
decision at anywhere, and anytime.
PROGRAM:
int val=0;
int buzzer = 10;
unsigned long on_time=0;
unsigned long off_time=0;
unsigned long button_ontime[20];
unsigned long button_offtime[20];
int button_seq[20];
int button1=3;
int button2=4;
int button3=5;
int button4=6;
int button5=7;
int button6=8;
int button7=9;
int button8=10;
int frequency[] = {262, 294, 330, 349, 392, 440, 494};
int buttonPin = 2;
int previousState = HIGH;
unsigned int previousPress;
volatile int buttonFlag;
int buttonDebounce = 20;
int path=1;
int i=0;
int led=13;
void playback (void);
void setup()
{
Serial.begin(9600);
pinMode(buzzer,OUTPUT);
pinMode(led,OUTPUT);
///////////////
pinMode(button1,INPUT_PULLUP);
pinMode(button2,INPUT_PULLUP);
pinMode(button3,INPUT_PULLUP);
pinMode(button4,INPUT_PULLUP);
pinMode(button5,INPUT_PULLUP);
pinMode(button6,INPUT_PULLUP);
pinMode(button7,INPUT_PULLUP);
pinMode(button8,INPUT_PULLUP);
pinMode(buttonPin,INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), button_ISR, CHANGE);
analogWrite(buzzer,0);
digitalWrite(led,HIGH);
}
void loop()
{
if(path==0)
{
Serial.println("playback");
playback();
}
if((millis() - previousPress) > buttonDebounce && buttonFlag)
{
previousPress = millis();
if(digitalRead(buttonPin) == LOW && previousState == HIGH)
{
path =! path;
previousState = LOW;
}
else if(digitalRead(buttonPin) == HIGH && previousState == LOW)
{
previousState = HIGH;
}
buttonFlag = 0;
}
if(digitalRead(button1)==LOW)
{
analogWrite(buzzer,frequency[0]);
on_time=millis();
if(i>0)
{
button_offtime[i-1]=on_time-off_time;
}
while(digitalRead(button1)==LOW);
if(path==1)
{
off_time=millis();
button_ontime[i]=(off_time-on_time);
button_seq[i]=0;
i++;
Serial.println("button 1 stored");
}
}
else if(digitalRead(button2)==LOW)
{
analogWrite(buzzer,frequency[1]);
on_time=millis();
if(i!=0)
button_offtime[i-1]=on_time-off_time;
while(digitalRead(button2)==LOW);
if(path==1)
{
off_time=millis();
button_ontime[i]=(off_time-on_time);
button_seq[i]=1;
i++;
Serial.println("button 2 stored");
}
}
else if(digitalRead(button3)==LOW)
{
analogWrite(buzzer,frequency[2]);
on_time=millis();
if(i!=0)
button_offtime[i-1]=on_time-off_time;
while(digitalRead(button3)==LOW);
if(path==1)
{
off_time=millis();
button_ontime[i]=(off_time-on_time);
button_seq[i]=2;
i++;
Serial.println("button 3 stored");
}
}
else if(digitalRead(button4)==LOW)
{
analogWrite(buzzer,frequency[3]);
on_time=millis();
if(i!=0)
button_offtime[i-1]=on_time-off_time;
while(digitalRead(button4)==LOW);
if(path==1)
{
off_time=millis();
button_ontime[i]=(off_time-on_time);
button_seq[i]=3;
i++;
Serial.println("button 4 stored");
}
}
else if(digitalRead(button5)==LOW)
{
analogWrite(buzzer,frequency[4]);
on_time=millis();
if(i!=0)
button_offtime[i-1]=on_time-off_time;
while(digitalRead(button5)==LOW);
if(path==1)
{
off_time=millis();
button_ontime[i]=(off_time-on_time);
button_seq[i]=4;
i++;
Serial.println("button 5 stored");
}
}
else if(digitalRead(button6)==LOW)
{
analogWrite(buzzer,frequency[5]);
on_time=millis();
if(i!=0)
button_offtime[i-1]=on_time-off_time;
while(digitalRead(button6)==LOW);
if(path==1)
{
off_time=millis();
button_ontime[i]=(off_time-on_time);
button_seq[i]=5;
i++;
Serial.println("button 6 stored");
}
}
else if(digitalRead(button7)==LOW)
{
analogWrite(buzzer,frequency[6]);
on_time=millis();
if(i!=0)
button_offtime[i-1]=on_time-off_time;
while(digitalRead(button7)==LOW);
if(path==1)
{
off_time=millis();
button_ontime[i]=(off_time-on_time);
button_seq[i]=6;
i++;
Serial.println("button 7 stored");
}
}
analogWrite(buzzer,0);
}
void playback (void)
{
digitalWrite(led,LOW);
for(int j=0;j<i;j++)
{
analogWrite(buzzer,frequency[button_seq[j]]);
delay(button_ontime[j]);
analogWrite(buzzer,0);
delay(button_offtime[j]);
}
i=0;
off_time=0;
on_time=0;
path=1;
digitalWrite(led,HIGH);
}
void button_ISR()
{
buttonFlag = 1;
}
CHAPTER 5
REFERNCES:
4. http://www.puiaudio.com/resources-white-papers-helmholtz.aspx
6. "Arduino Blog – A new era for Arduino begins today". Arduino Blog.
Retrieved 19 Jan 2018.