Buzzer/Speakers(Tone Application-Jingle Bell Tone)

What is a buzzer?
A buzzer or a beeper is an audio signalling device, which may be mechanical, electromechanical, or piezoelectric. Typical uses of buzzers and beepers include alarm devices,timers and confirmation of user input such as a mouse click or keystroke. Google Definition Credits
I'm using buzzer in this project because i'm testing and experimenting how buzzer is able to create tone and how it could create different variations of sound.
Buzzers are really helpful for our daily uses such as for our securities for alarming devices and entertainment for it create music also.
Pin Configurations

What Will I Learn?
Things that we could learn from it:
- How to program an example tone for the buzzer from our Arduino Nano
- How to simply connect the pin configurations from buzzer to Arduino Nano
- How to simulate this buzzers by programming any tone
Requirements/Materials needed
Simple materials to follow this tutorial
- Buzzers/Speakers
- Arduino Nano
- Braedboard
- Connecting wires(if necessary)
- Laptop/Desktop PC w/ Arduino IDE installed
Difficulty
- Basic
Tutorial Contents
Let's Start
Step 1: Physical connection of the buzzer to the Arduino Nano

Connect the following:
- Buzzer(Gnd) to Arduino Nano Gnd
- Buzzer(DataIn) to Arduino Nano Digital Pin(3)
- Arduino Nano to your laptop using usb cable
Step 2: Software Connection from Arduino Nano to Buzzers
- Open your Arduino IDE. Go to Tools and change your Board to Arduino Nano. Next, change your port where Arduino Nano is connected on your computer. Go to Port and select port for your Arduino Nano.

- Paste the given code below on your Arduino IDE.
#define C 2100
#define D 1870
#define E 1670
#define f 1580
#define G 1400
#define R 0
int spkOut = 3;
int DEBUG = 1;
void setup() {
pinMode(spkOut, OUTPUT);
if (DEBUG) {
Serial.begin(9600);
}
}
int melody[] = {E, E, E,R,
E, E, E,R,
E, G, C, D, E, R,
f, f, f,f, f, E, E,E, E, D ,D,E, D, R, G ,R,
E, E, E,R,
E, E, E,R,
E, G, C, D, E, R,
f, f, f,f, f, E, E, E, G,G, f, D, C,R };
int MAX_COUNT = sizeof(melody) / 2;
long tempo = 10000;
int pause = 1000;
int rest_count = 100;
int tone_ = 0;
int beat = 0;
long duration = 0;
void playTone() {
long elapsed_time = 0;
if (tone_ > 0) {
while (elapsed_time < duration) {
digitalWrite(spkOut,HIGH);
delayMicroseconds(tone_ / 2);
digitalWrite(spkOut, LOW);
delayMicroseconds(tone_ / 2);
elapsed_time += (tone_);
}
}
else {
for (int j = 0; j < rest_count; j++) {
delayMicroseconds(duration);
}
}
}
void loop() {
for (int i=0; i<MAX_COUNT; i++) {
tone_ = melody[i];
beat = 50;
duration = beat * tempo;
playTone();
delayMicroseconds(pause);
}
}
- When your done programming the Arduino Nano, just click on the Upload button to upload the code from Arduino IDE to your Arduino Nano.

Step 3: Testing the buzzer if it really works.
This is my sample output video on this tutorial. it really works for me.
Curriculum
Other Arduino projects/contribution:
That's All! Hope you learn something with this tutorial.
Thank You!
Posted on Utopian.io - Rewarding Open Source Contributors
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Thank you @rufans
Hey @jbeguna04 I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x