2.4k
In this example we will connect a buzzer to our pic and then play a basic tune, we will use mikroC and the Sound library that is available.
Here is the schematic
Schematic
Code
The code was written in mikroC, you can find out the frequencies of the notes used at http://en.wikipedia.org/wiki/Piano_key_frequencies
[codesyntax lang=”c”]
void main() { TRISB = 0; Sound_Init(&PORTB, 0); // Initialize sound o/p pin PORT B 0 do { //Happy birthday to you Sound_Play(262, 400); Delay_ms(100); Sound_Play(262, 400); Delay_ms(100); Sound_Play(294, 800); Delay_ms(100); Sound_Play(262, 800); Delay_ms(100); Sound_Play(349, 800); Delay_ms(100); Sound_Play(330, 1000); Delay_ms(1000); // Wait for 1 sec and replay }while(1); }
[/codesyntax]
Links
10pcs 5V Mini Magnetic Active Buzzer