Project 8 – Piezo buzzer: Melody – Birthday Song

Project 8 – Piezo buzzer: Melody – Birthday Song

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