Project 8 – Piezo buzzer: Melody – Birthday Song

Piezo buzzer, generally use as a sensor and actuator which are use to measure force, pressure , tools for positioning object and etc. As for this project, we are going to use it to generate a melody by applying PWM frequency to it.

PROJECT 8

PIEZO BUZZER: MELODY – BIRTHDAY SONG

Back to Project 7                                                                                                        Go to Project 9

Piezo buzzer, generally use as a sensor and actuator which are use to measure force, pressure , tools for positioning object and etc. As for this project, we are going to use it to generate a melody by applying PWM frequency to it.

———————————————————————————————————————————————————-

COMPONENT NEEDED

———————————————————————————————————————————————————-

  PIEZO BUZZER

———————————————————————————————————————————————————-

CONNECTION

———————————————————————————————————————————————————-
For piezo buzzer, connect any of the wire to ground(GND) and the other wire to RC1.

———————————————————————————————————————————————————-

ADDITIONAL INFORMATION

———————————————————————————————————————————————————-
INSIDE OF PIEZO BUZZER

HOW PIEZO BUZZER WORKS

RECOMMENDED OPERATING CIRCUIT

———————————————————————————————————————————————————-

CODE OVERVIEW

———————————————————————————————————————————————————-
system.h

#define A4 78
In system.h, we firstly declare each delay period value according to the musical tone chart.

MAIN PROGRAM

unsigned int birthday[]
Assign an array for birthday[] so that it can increase 1 at the time by just simply give bithday[] a number.
E.g: birthday [4], the delay period are N which is 132.

unsigned int delay_pariod[]
Assign the delay period for each tone. The delay_period much be within 0 to 65535.

PR2 = (birthday[wait]/2);
Assign timer 2 value (PR2) with the delay period over 2 to generate the PWM period.

tone_out(birthday[wait],delay_period[wait]*20000);
Call tone_out subroutine and also assign the birthday[wait] value and delay_period times with 20000.
E.g: delay_period for C4_1 = (1) * 20000 = 20000

while(delay– > 0)
Loop forever if the 30000 is decrease by 1 at the time is still greater then 0.

pwm_set_duty_cycle(tone);
Set the duty cycle of the PWM with birthday[] value.

Back to Project 7                                                                                                              Go to Project 9

————————————————————————————————————————————————————————-

ATTACHMENT

1. P8 User Manual.pdf
2. Project_8_code.zip

BUY

3 thoughts on “Project 8 – Piezo buzzer: Melody – Birthday Song”

  1. May i know how to stop the piezo buzzer from infinity looping in the project 8 Piezo buzzer: Melody – Birthday Song?

  2. Wow!! really very nice idea of generating a melody from Piezo buzzer. And have also maintained the coding. Thanks for sharing.

Leave a Comment

Your email address will not be published.

Share this Tutorial

Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest
Share on facebook
Share on whatsapp
Share on email
Share on print
Share on twitter
Share on pinterest

Latest Tutorial

Getting Started With ProjekIoT.com Using Raspberry Pi
Control Servo With Gesture Using ESP32 and Arduino
Send Sensor’s Data to ThingSpeak Using ESP32
Basic Usage of iMAX B6AC LiPo Charger
Colourful Bed Lamp Using Tilt Sensor on Maker UNO
Scroll to Top