Design of 51 single chip wireless music doorbell

Publisher:phi31Latest update time:2022-01-11 Source: elecfans Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Wireless doorbells are also called wireless remote control doorbells or remote control doorbells. Wireless doorbells use super-regenerative wireless modules to achieve wireless remote control. Wireless doorbells do not require wiring and are simple and flexible to install. However, the transmission distance is greatly affected by the transmission distance and the on-site environment. Wired doorbells are just the opposite.

Including, program physical drawings program simulation


Expected results of the course:

1. There are 5 songs to switch between, each press will play a different song.

2. The wireless transmission distance is more than 10m and can pass through walls and doors.

3. Compact design, easy to install and use

4. High stability, no false alarm.


Physical map:

insert image description here

Schematic diagram:

insert image description here

Simulation diagram

insert image description here

Code screenshot

insert image description here

Wireless Music Doorbell Components List

1.79 Multipurpose Board

2.8Ω 0.25w small speaker

3. DC power socket

4. Self-locking switch

5.12m crystal oscillator

6. 10k resistor 8

7. 2.2k resistor

8. 30pf capacitor 2

9. 10uf capacitor

10. 40-pin IC socket

11. Button 2

12. stc89c51

13.315M transmitter module

14. Receiving module

15. 2272-M4 chip

16.2262 Chip

17. 12v battery

18.820k chip resistor

19. 4.7M chip resistor

20.9012

21.9013

22. Several wires

23. Some solder

24.23cm long antenna*2

25. USB power cord (battery box + DC plug)


C language reference source code


//

//51 MCU wireless remote control doorbell program

//

#include

#define sound_amount 5 //Number of songs

sbit pause=P2^5; //playback pause

sbit speaker=P2^7; //passive buzzer

//

unsigned char timer0h, timer0l, time; //timer0h, timer0l are the initial values ​​of the high and low bits of timer T0, time is the corresponding beat time

unsigned char music_num,num; //music_num is the song number, music_num=0 means the state when the machine is just turned on, num is the address to search the song data table

signed char fre; //The address of the corresponding frequency data table

bit play_enable; //Song playback enable flag, used for playback pause

void delay(unsigned char t); //delay subfunction, control the length of pronunciation

void delayms(unsigned int t); //Ordinary delay subroutine, can be used to eliminate key jitter

void song(void); //play a note

void music_play(void); //play songs

//

//Every three numbers represent a note

//The first number is one of the values ​​of the note 1234567 (the note number), representing Do-Re-Mi-Fa...

//The second number is one of 0123, representing bass, mid-range, treble, and super-treble (octave)

//The third number is the duration, in half beats. The end of the music data table is three 0s.

//

//"Happy birthday to you"

unsigned char code song1[]={

5,1,1, 5,1,1, 6,1,2, 5,1,2, 1,2,2, 7,1,4,

5,1,1, 5,1,1, 6,1,2, 5,1,2, 2,2,2, 1,2,4,

5,1,1, 5,1,1, 5,2,2, 3,2,2, 1,2,2, 7,1,2, 6,1,2,

4,2,1, 4,2,1, 3,2,2, 1,2,2, 2,2,2, 1,2,4, 0,0,0};


//《There is only one good mother in the world》

unsigned char code song2[]={

6,2,3, 5,2,1, 3,2,2, 5,2,2, 1,3,2, 6,2,1,

//6,2,3 represents 6, middle note, 3 and a half beats;

//5,2,1 represents 5, middle note, 1 and a half beats;

//3,2,2 represents 3, middle note, 2 and a half beats;

//5,2,2 represents 5, middle note, 2 and a half beats;

//1,3,2 represents 1, high note, 2 half beats;

//…

5,2,1,6,2,4, 3,2,2, 5,2,1, 6,2,1, 5,2,2, 3,2,2, 1,2,1,6,1,1, 5,2,1,

3,2,1, 2,2,4, 2,2,3, 3,2,1, 5,2,2, 5,2,1, 6,2,1, 3,2,2, 2,2,2,

1,2,4, 5,2,3, 3,2,1,2,2,1, 1,2,1, 6,1,1, 1,2,1, 5,1,6, 0,0,0};


//《Who do you think of when you are lonely》

unsigned char code song3[]={

3,2,2, 3,2,1, 4,2,1, 3,2,2, 2,2,1, 1,2,1, 2,2,2, 5,2,2, 2,2,2, 2,2,3,

1,2,2, 1,2,1, 2,2,1, 1,2,2, 7,1,1, 6,1,1, 7,1,2, 3,2,2, 7,1,2, 7,1,3,

6,1,2, 2,2,1, 3,2,1, 2,2,1, 1,2,1, 6,1,2, 5,1,2, 2,2,1, 3,2,1, 2,2,1,

1,2,1, 6,1,2, 6,1,2, 2,2,1, 3,2,1, 2,2,1, 1,2,1, 6,1,1, 7,1,1, 1,2,6, 0,0,0 };


//"Country road"

unsigned char code song4[]={

3,1,2, 3,1,1, 3,1,1, 6,0,1, 6,0,1, 1,1,2,

6,0,1, 5,0,1, 6,0,4, 6,0,2, 6,0,1 ,6,0,1, 6,0,2, 6,0,1, 1,1,1,

2,1,2, 2,1,1, 3,1,1, 2,1,4, 3,1,1, 3,1,1, 3,1,1, 2,1,1, 4,1,2,

4,1,2, 3,1,2, 2,1,1, 1,1,1, 2,1,4, 7,0,1, 7,0,1, 7,0,1, 6,0,1,

5,0,1, 5,0,1, 6,0,1, 7,0,1, 7,0,1, 6,0,1, 5,0,1, 6,0,4, 6,1,2,

3,1,1, 6,1,1, 7,1,1, 6,1,1, 5,1,1, 5,1,2, 5,1,1, 2,1,1, 5,1,1,

6,1,1, 5,1,1, 4,1,1, 4,1,2, 4,1,1, 3,1,1, 2,1,2, 1,1,1, 2,1,1,

3,1,1, 2,1,1, 1,1,1, 2,1,1, 3,1,4, 6,1,2, 3,1,1, 6,1,1, 7,1,1,

6,1,1, 5,1,1, 5,1,2, 2,1,1, 5,1,1, 6,1,1, 5,1,1, 4,1,1, 0,0,0};


//"farewell"

unsigned char code song5[]={

5,1,2, 3,1,3, 5,1,1, 1,2,3, 6,1,2, 1,2,2,

5,1,4, 5,1,2, 1,1,1, 2,1,1, 3,1,2, 2,1,1, 1,1,1, 2,1,4, 5,1,2,

3,1,1, 5,1,1, 1,2,2, 7,1,1, 6,1,2, 1,2,2, 5,1,4, 5,1,2, 2,1,1,

3,1,1, 4,1,2, 7,0,1, 1,1,4, 6,1,2, 1,2,2, 1,2,4, 7,1,2, 6,1,1,

7,1,1, 1,2,4, 6,1,1, 7,1,1, 1,2,1, 6,1,1, 6,1,1, 5,1,1, 3,1,1,

1,1,1, 2,1,8, 5,1,2, 3,1,1, 5,1,1, 1,2,2, 7,1,1, 6,1,2, 1,2,2,

5,1,4, 5,1,2, 2,1,1, 3,1,1, 4,1,2, 7,0,2, 1,1,4, 0,0,0};


// The high eight bits of the frequency-half-period data table store 28 frequency data of four octaves

unsigned char code FREQH[]={

0xF2, 0xF3, 0xF5, 0xF6, 0xF7, 0xF8, //Bass 1234567

0xF9, 0xF9, 0xFA, 0xFA, 0xFB, 0xFB, 0xFC, 0xFC, //1,2,3,4,5,6,7,i

0xFC, 0xFD, 0xFD, 0xFD, 0xFD, 0xFE, // high pitch 234567

0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF}; //Super high pitch 1234567


// Frequency-half-cycle data table lower eight bits

unsigned char code FREQL[]={

0x42, 0xC1, 0x17, 0xB6, 0xD0, 0xD1, 0xB6, //Bass 1234567

0x21, 0xE1, 0x8C, 0xD8, 0x68, 0xE9, 0x5B, 0x8F, //1,2,3,4,5,6,7,i

0xEE, 0x44, 0x6B, 0xB4, 0xF4, 0x2D, ​​// high pitch 234567

0x47, 0x77, 0xA2, 0xB6, 0xDA, 0xFA, 0x16}; //Super high pitch 1234567


void main(void)

{

TMOD=0x11; //T0 T1 are both in working mode 1

ET0=1; //T0 opens interrupt

EA=1; //CPU interrupt

while(1)

{

music_play(); //Play a note of the corresponding song according to the current state


if(!pause) //Pause key processing

{

delayms(5);

if(!pause)

{

if(music_num0) //music_num=0 only exists when the device is just powered on and the pause button is not pressed, indicating the state when the device is just powered on. Press the button to start playing from the first song.

{

music_num=1; //Set the song number to 1

num=0; //play from the beginning

play_enable=1; //Allow playback

}

else

{

play_enable=~play_enable;

speaker=1;

}

while(!pause) //What to do if you hold down the pause button

{

if(play_enable0){} //If it is paused, the display time remains unchanged //(play_enable==0 when paused)

}


}//Pause key processing ends

}//while ends

}

}


void delayms(unsigned int t) //MS delay subroutine

{

unsigned int i,j;

for(i=0;i{

for(j=0;j<123;j++)

;

}

}


void delay(unsigned char t) //delay subfunction, control the length of pronunciation, 0.4S per beat

{

unsigned char t1;

unsigned long t2;

for(t1=0;t1{

for(t2=0;t2<8000;t2++) //During the delay period, you can enter T0 interrupt to pronounce

{

;

}

}

TR0=0; //Turn off T0, stop pronunciation

}


void timer0(void) interrupt 1 //T0 interrupt program, control the tone of pronunciation

{

speaker=!speaker; // output square wave, pronunciation

TH0=timer0h; //The next interrupt time, this time controls the pitch

TL0=timer0l;

}


void song(void) //play a note

{

TH0=timer0h; //control tone

TL0=timer0l;

TR0=1; //Start T0, and T0 will output square wave sound

delay(time); //Playing time of each note

}


void music_play(void) //Play a note of the corresponding song

{

if((music_num1)&&(play_enable1))

{

fre=song1[num]+7song1[num+1]-1; //The i-th is a note, the i+1th is the octave

timer0h=FREQH[fre]; //Read the frequency value from the data table, which is actually the timing time length

timer0l=FREQL[fre];

time=song1[num+2]; //Read the time length value

num+=3;

if(fre==-1) //Judge the end of the song and go to the next one after it ends

{

num=0; //Play the next song from the beginning

music_num=2;

play_enable=0;

}

song(); //send a note

}


if((music_num2)&&(play_enable1))

{

fre=song2[num]+7song2[num+1]-1;

timer0h=FREQH[fre];

timer0l=FREQL[fre];

time=song2[num+2];

num+=3;

if(fre==-1)

{

num=0;

music_num=3;

play_enable=0;

}

song();

}


if((music_num3)&&(play_enable1))

{

fre=song3[num]+7song3[num+1]-1;

timer0h=FREQH[fre];

timer0l=FREQL[fre];

time=song3[num+2];

num+=3;

if(fre==-1)

{

num=0;

music_num=4;

play_enable=0;

}

song();

}


if((music_num4)&&(play_enable1))

{

fre=song4[num]+7song4[num+1]-1;

timer0h=FREQH[fre];

timer0l=FREQL[fre];

time=song4[num+2];

num+=3;

if(fre==-1)

{

num=0;

music_num=5;

play_enable=0;

}

song();

}


if((music_num5)&&(play_enable1))

{

fre=song5[num]+7*song5[num+1]-1;

timer0h=FREQH[fre];

timer0l=FREQL[fre];

time=song5[num+2];

num+=3;

if(fre==-1)

{

num=0;

music_num=1;

play_enable=0;

}

song();

}


}

//End of program

Reference address:Design of 51 single chip wireless music doorbell

Previous article:Mobile phone Bluetooth control Guangzhou Tower LED light array wireless control music playback
Next article:Literacy: What is MCU timing and how to understand the timing diagram

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号