Musical DoorBell with PIC16F84A

Microcontroller Topics

What do you think about this example?

Poll ended at Fri Apr 23, 2010 5:00 pm

Very good
10
83%
Good
2
17%
Bad
0
No votes
Very bad
0
No votes
 
Total votes: 12
User avatar
Shane
Captain
Captain
Posts: 226
Joined: Sun Jul 19, 2009 9:59 pm
Location: Jönköping, Sweden

Re: Musical DoorBell with PIC16F84A

Post by Shane » Mon Nov 14, 2011 5:40 pm

LM386 circuit submitted by RKSK is a common one. You would add a 10K resistor in series with the 10uf cap in pin 1,8 to increase the gain from 20x to 200x (Without that you would only get a 20x amplification). However this amplifier is only good for driving a low power speaker from a sound effects module or a noise generator. I have posted a better quality amplifier at Simple 7W Audio Amplifier Circuit Diagram.

You may also look at 120 Watt Audio Power Amplifier Circuit Diagram for more power. There are many other TDA series amplifiers which are easy to make. STK series also have many good power amplifiers.
User avatar
SemiconductorCat
Major
Major
Posts: 455
Joined: Mon Aug 22, 2011 8:42 pm
Location: currently in hyperspace

Re: Musical DoorBell with PIC16F84A

Post by SemiconductorCat » Thu Nov 17, 2011 3:12 pm

Shane wrote:LM386 circuit submitted by RKSK is a common one. You would add a 10K resistor in series with the 10uf cap in pin 1,8 to increase the gain from 20x to 200x (Without that you would only get a 20x amplification). However this amplifier is only good for driving a low power speaker from a sound effects module or a noise generator. I have posted a better quality amplifier at Simple 7W Audio Amplifier Circuit Diagram.

You may also look at 120 Watt Audio Power Amplifier Circuit Diagram for more power. There are many other TDA series amplifiers which are easy to make. STK series also have many good power amplifiers.
Hmm , sounds like not enough experience in Analog and Power Electronics Right?
User avatar
Shane
Captain
Captain
Posts: 226
Joined: Sun Jul 19, 2009 9:59 pm
Location: Jönköping, Sweden

Re: Musical DoorBell with PIC16F84A

Post by Shane » Fri Nov 18, 2011 11:08 am

Hmm , sounds like not enough experience in Analog and Power Electronics Right?
No. I think for the circuit mentioned in the main topic, it is enough to have that LM amplifier. Besides we welcome all opinions here rather than only from experts. So it is really important to share ideas within the community. No good to discriminate others.
DeepakPatil23
Sergeant
Sergeant
Posts: 20
Joined: Mon May 23, 2011 7:16 pm

Re: Musical DoorBell with PIC16F84A

Post by DeepakPatil23 » Wed Nov 23, 2011 12:27 pm

Shane wrote:Hi guys

I'm adding the C code for playSound function.

Code: Select all

// frequency table: periods in thousands of ms
#define NFREQ  7
const unsigned char t_period[NFREQ] = {132, 148, 165, 176, 198, 220, 247};

// s - Index of the sound in frequency table
// d - Duration of the sound in numbers of periods
// t - Duration of silence after the sound (to be multiplied by 10 ms)

void playSound (unsigned char s, unsigned char d, unsigned char t){

	unsigned char i, t1;

	t1 = t_period[s];

	for (i = 0; i < d; i++){
		RB0 ^= 1; // Toggle 1 and 0
		Delay_us(t1);
	}
	
	// Turn loudspeaker off
	RB0 = 0;
	
	// Do the silence (if needed)
	for (i = 0; i < t; i++){
		delay10ms();
	}
}
Note that, since 's' is the index of frequency table, you can pass 0 to 6 for different frequencies.

The above C code will work on HiTECH C compiler. However with little modifications to port writing codes, you can get this working for any platform.


I Used this procedure to produce sound but i m not able to generate a music with this. the sounds are coming but with any songs not able to produce like that. the frequency not matches or some time no sound at all. what to do. :?: :cry:
User avatar
Shane
Captain
Captain
Posts: 226
Joined: Sun Jul 19, 2009 9:59 pm
Location: Jönköping, Sweden

Re: Musical DoorBell with PIC16F84A

Post by Shane » Thu Nov 24, 2011 12:27 pm

This whole discussion was aiming at making a simple Musical door bell. It is definitely not good for any songs type playback. To playback such music, you will have to use a DAC (Digital-to-Analogue converter) chip such as CS4334. I have added a schematic at Making an MP3 player using STA013 & CS4334 chips.
DeepakPatil23
Sergeant
Sergeant
Posts: 20
Joined: Mon May 23, 2011 7:16 pm

Re: Musical DoorBell with PIC16F84A

Post by DeepakPatil23 » Thu Nov 24, 2011 3:53 pm

Shane wrote:This whole discussion was aiming at making a simple Musical door bell. It is definitely not good for any songs type playback. To playback such music, you will have to use a DAC (Digital-to-Analogue converter) chip such as CS4334. I have added a schematic at Making an MP3 player using STA013 & CS4334 chips.
yesss, for Musical door bell only. i am not saying for playback music.
i am not able to play musical bell. its just making sound or like beeper.
User avatar
Shane
Captain
Captain
Posts: 226
Joined: Sun Jul 19, 2009 9:59 pm
Location: Jönköping, Sweden

Re: Musical DoorBell with PIC16F84A

Post by Shane » Sat Nov 26, 2011 4:58 am

Hey Deepak,
This is nothing more than beeping. If you need more quality, you better use PWM to control the frequency. Have a look at the following circuit diagram.
ex.PNG
ex.PNG (24.88 KiB) Viewed 8618 times
Instead of a piezo speaker, you can use a 8 Ohm speaker here. However with a simple arrangement as below, you can drive a piezo with PWM well.
piezo.JPG
piezo.JPG (7.53 KiB) Viewed 8618 times
Here is a sample PWM code

Code: Select all

/*
Code written by Bobby By, Agatha Lee, Dan Niecestro 02-2009
This code uses a PWM signal from PIC 18F4520 to define the frequencies 
that produce the basic notes in one octave of the musical scale, 
and plays a simple song on a piezo speaker.
The volume of the speaker can be set by changing the duty cycle value (1~125)
*/

#include <18f4520.h>
#fuses HS,NOLVP,NOWDT,NOPROTECT
#use delay(clock=40000000)

//define timer scaling value for each note
#define C 255 
#define D 227
#define E 204
#define F 191
#define G 170
#define A 153
#define B 136
#define C2 127
//

#define x 14 //total number of notes in song to be played - modify for specific song

//the song to be played in this demonstration is "Twinkle Twinkle Little Star" 
int song[x]={C, C, G, G, A, A, G, F, F, E, E, D, D, C}; //insert notes of song in array
int length[x]={1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2}; //relative length of each note
int i;

void main() {

	setup_ccp1(CCP_PWM); // PWM output on pin 17, RC2/CCP1 
	set_pwm1_duty(30); // the number changes the volume of the piezo speaker

	for (i=0; i<x; i++) { // play x notes inside song array

		setup_timer_2(T2_DIV_BY_16, song[i], 16); 
		//set PWM frequency according to entries in song array
		delay_ms(400 * length[i]); //each note is played for 400ms*relative length
		setup_timer_2(T2_DIV_BY_16, 1, 16); //the PWM frequency set beyond audible range
		//in order to create a short silence between notes
		delay_ms(50); //the silence is played for 50 ms
	}
}
Bonus songs:
Mary Had a Little Lamb

Code: Select all

#define x 26
int song[x] = {B, A, G, A, B, B, B, A, A, A, B, B, B, B, A, G, A, B, B, B, A, A, B, A, G, G};
int length[x] = {1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 2, 2};
Jingle Bells

Code: Select all

#define x 25
int song[x] = {E, E, E, E, E, E, E, G, C, D, E, F, F, F, F, F, E, E, E, E, D, D, E, D, G};
int length[x] = {1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2};
User avatar
Rksk
Major
Major
Posts: 730
Joined: Thu Jan 07, 2010 4:19 pm
Location: Rathnapura, Sri Lanka

Re: Musical DoorBell with PIC16F84A

Post by Rksk » Sat Nov 26, 2011 11:09 am

DeepakPatil23 wrote:for Musical door bell only. i am not saying for playback music.
i am not able to play musical bell. its just making sound or like beeper.
You can use UM66 for music generation insted of uCs.
Image

* I posted this topic just to give u a idea about uCs.

[ Post made via Mobile Device ] Image
nukleng
Corporal
Corporal
Posts: 3
Joined: Thu Jan 31, 2013 11:34 am

Re: Musical DoorBell with PIC16F84A

Post by nukleng » Thu Jan 31, 2013 12:02 pm

thanks
Post Reply

Return to “Microcontrollers”