0% found this document useful (0 votes)
13 views4 pages

MEng 125n Laboratory Exercise 6

This document outlines an exercise for generating sounds and tones using a piezo speaker with an Arduino. It includes a step-by-step procedure for setting up the circuit, writing the code, and expected learning outcomes. Additionally, it provides post-lab questions and instructions for submitting the laboratory report.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views4 pages

MEng 125n Laboratory Exercise 6

This document outlines an exercise for generating sounds and tones using a piezo speaker with an Arduino. It includes a step-by-step procedure for setting up the circuit, writing the code, and expected learning outcomes. Additionally, it provides post-lab questions and instructions for submitting the laboratory report.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Exercise No.

6:
Creating Sounds and
Tones with Piezo
Speaker
Introduction
In this exercise, we will generate different tones in piezo speaker. The code
sequence are as follows:
a. Assign variable names to use and create a tone[] array (10 different
tone frequencies)
b. Start using for:loop to create tone - Integer i is set to zero.
c. First tone plays for 0.5 seconds.
d. Integer i is incremented by one
e. Next tone is played for 0.5 seconds until the tenth tone.
f. After playing the last tone, stop by calling noTone() command.

Learning Outcomes
After this laboratory exercise, student should be able to:
1. discuss the concepts of Interfacing a Piezo Speaker with Arduino;
2. create a desired tone; and
3. use the programming data type “Array” and programming structure “for
loop”.

Materials
• 1 – Arduino UNO R3
• 1 – USB Cable (USB-A to USB-B)
• 1 – Piezo Speaker (Buzzer)
• 1 – Breadboard
• Connecting Wires
• Computer with Arduino software
22 MEng 125n: Basic Electronics

Procedure

Part 1: The Circuit


1. Connect the positive pin of the buzzer into digital pin 8 of the Arduino
Uno. To know the positive pin of the buzzer, look for the plus sign found
on the head of the buzzer.
2. Connect the negative pin of the buzzer to the GND pin of Arduino. See
Figure 6 for your reference.

Figure 6. Pictorial Diagram of Creating Sounds and Tones with Piezo Speaker

Part 2: The Code


1. Open the Arduino Software IDE. Go to top-left corner of the Arduino IDE
window and click File>New. This action opens up a new coding editor
window for a new project.
2. Type the Arduino Code below to your Arduino IDE.
/*
Creating Sounds and Tones with Piezo Speaker
*/

//assign variables to use in our program


int buzzerPin = 8; //Arduino pin to connect the positive pin of buzzer
int listTones = 10; //number of tones we will play
//list of tones we will play which corresponds to
// C, C#, D, D#, E, F, F#, G, G#, A
int tones[] = {261, 277, 294, 311, 330, 349, 370, 392, 415, 440};

void setup() {
//we do not need to put any code initialization here.
}

Page 22 of 56
Vision: A globally competitive university for science, technology, and environmental conservation.
TP-IMD-04
Mission: Development of a highly competitive human resource, cutting-edge scientific knowledge V0 07-15-2020
and innovative technologies for sustainable communities and environment. No. CET.ME
LM21-01
For instructional purposes only • 1st Semester SY 2020-2021 23

void loop() {
// A "for" loop function is used to make a count from 0 to 9 using a
// variable "i". This "i" corresponds to the tone sequences listed like
// for i = 0 is for 261 and for i = 9 is for 440.

for (int i = 0; i < listTones; i++)


{
// The "tone" command from the Arduino library need only 2
parameters
// first parameter is the pin for the buzzer (buzzerPin) and second
// the tones we wish to play (tones)

tone(buzzerPin, tones[i]);
delay(500);
}
noTone(buzzerPin); // call the "noTone" command to stop playing any
tones
delay(1000); // delay 1 second before playing again
}

3. Click Verify button to review code for errors. If the code has no
errors and missing commands a message on the window below will
display “Done Compiling” this means your code is
ready to be uploaded into the Arduino microcontroller board.
4. Click Upload button to upload the Arduino Code to the Arduino
microcontroller board.
The program starts to play the tones that we put in the tones[] array. 10 tones
will be played simultaneously with a 1 second delay after the last tone. The
program plays back the first tone after the last tone.

Post Lab Questions


1. Try adding other tone values to play different musical tones. What
change to do in the array parameter? You may also connect the LDR
from the previous exercise and program the Arduino that equivalent
values read by the LDR to play the tone value on the speaker.
2. This time try creating a buzzer alarm using one or multiple tones. What
frequencies to use?
3. What are your learning experiences in this laboratory exercise?

Instructions on how to submit the laboratory


1. Make a video of yourself while performing the laboratory. The video
must not be below 3 minutes but will not exceed for 5 minutes.
2. Upload your video on your Google Drive or YouTube account. Share the
link of this video to meng125n.vsu@gmail.com.
3. Make the laboratory report by following the format/template given in
the virtual classroom. Save it in a pdf file with a file name format of
Surname.Firstname_LE# (e.g. Rizal.Procorpio_LE1).
4. Upload your laboratory report in the virtual classroom.

Page 23 of 56
Vision: A globally competitive university for science, technology, and environmental conservation.
TP-IMD-04
Mission: Development of a highly competitive human resource, cutting-edge scientific knowledge V0 07-15-2020
and innovative technologies for sustainable communities and environment. No. CET.ME
LM21-01
24 MEng 125n: Basic Electronics

References

1. Purdum, Jack. 2015. Beginning C for Arduino, Second Edition: Learn C


Programming for the Arduino. doi:10.1007/978-1-4842-0940-0
2. Craft, Brock. 2013. Arduino Projects for Dummies. John Wiley & Sons,
Ltd, Chichester, West Sussex, England
3. Riley, Mike. 2012. Programming Your Home: Automate with Arduino,
Android, and Your Computer. The Pragmatic Programmers, LLC. United
States of America.
4. McRoberts, Michael. 2010. Beginning Arduino. Apress901 Grayson
Street Suite 204 Berkely, CA, United States

Page 24 of 56
Vision: A globally competitive university for science, technology, and environmental conservation.
TP-IMD-04
Mission: Development of a highly competitive human resource, cutting-edge scientific knowledge V0 07-15-2020
and innovative technologies for sustainable communities and environment. No. CET.ME
LM21-01

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy