Principle and design of microcontroller driven buzzer

Publisher:温柔花香Latest update time:2013-03-21 Source: dzsc Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
  A buzzer is an electronic sounder with an integrated structure. This article introduces how to drive a buzzer with a single-chip microcomputer. It is widely used as a sound-generating device in electronic products such as computers, printers, copiers, alarms, and telephones.

  Buzzers are mainly divided into two types: piezoelectric buzzers and electromagnetic buzzers.

  The electromagnetic buzzer consists of an oscillator, an electromagnetic coil, a magnet, a vibrating diaphragm and a shell. After the power is turned on, the audio signal current generated by the oscillator passes through the electromagnetic coil, causing the electromagnetic coil to generate a magnetic field. Under the interaction of the electromagnetic coil and the magnet, the vibrating diaphragm vibrates periodically and makes a sound.

  The piezoelectric buzzer is mainly composed of a multivibrator, a piezoelectric buzzer, an impedance matcher, a resonance box, a shell, etc. The multivibrator is composed of a transistor or an integrated circuit. When the power is turned on (1.5~15V DC working voltage), the multivibrator starts to vibrate and outputs an audio signal of 1.5~2.5kHZ. The impedance matcher drives the piezoelectric buzzer to sound.

  Below is the appearance picture and structure diagram of the electromagnetic buzzer

Click here to view the image in a new window

  Electromagnetic buzzer physical picture: Electromagnetic buzzer structure diagram: \'

Click here to view the image in a new window

  Internal structure of electromagnetic buzzer:
  1. Waterproof sticker
  2. Spool
  3. Coil
  4. Magnet

  5. Base
  6. Pin
  7. Shell
  8. Core

  9. Sealing glue
  10. Small iron sheet
  11. Vibrating membrane
  12. Circuit board [page]

   1. Driving principle of electromagnetic buzzer

  The principle of buzzer sound is that the current passes through the electromagnetic coil, which makes the electromagnetic coil generate a magnetic field to drive the vibration membrane to make sound. Therefore, a certain current is required to drive it. The current output by the IO pin of the microcontroller is small, and the TTL level output by the microcontroller basically cannot drive the buzzer. Therefore, a current amplification circuit is needed. The S51 enhanced microcontroller experiment board uses a transistor C8550 to amplify and drive the buzzer. The schematic diagram is shown in Figure 3 below:

Click here to view the image in a new window

 

       S51 enhanced single chip microcomputer experiment board buzzer driver schematic diagram:

  The positive pole of the buzzer is connected to the VCC (+5V) power supply, and the negative pole of the buzzer is connected to the emitter E of the transistor. The base B of the transistor is controlled by the P3.7 pin of the microcontroller after passing through the current limiting resistor R1. When P3.7 outputs a high level, the transistor T1 is cut off, no current flows through the coil, and the buzzer does not sound; when P3.7 outputs a low level, the transistor is turned on, so that the current of the buzzer forms a loop and sounds. Therefore, we can control the level of the P3.7 pin through the program to make the buzzer sound and turn it off.

  By changing the frequency of the waveform output by the P3.7 pin of the microcontroller in the program, the tone of the buzzer can be adjusted to produce sounds of various timbres and tones. In addition, by changing the duty cycle of the high and low levels of the P3.7 output level, the volume of the buzzer can be controlled. We can verify these through programming experiments.

       2. Buzzer Example

  Below we give a few simple examples of programming and circuit design of microcontroller-driven buzzers.

  1. Simple buzzer experiment program: This program drives the buzzer on the experimental board to emit a buzzing sound by outputting a square wave in the audio range at P3.7. The function of the DELAY delay subroutine is to make the output square wave frequency below 20KHZ within the hearing capacity of the human ear. Without this delay program, the output frequency will greatly exceed the hearing capacity of the human ear, and we will not be able to hear the sound. Changing the delay constant can change the output frequency, and thus adjust the tone of the buzzer. You can change #228 to other values ​​in the experiment and listen to the change in the tone of the buzzer.

  ORG 0000H
  AJMP MAIN ; Jump to the main program

  ORG 0030H
  MAIN: CPL P3.7 ;Buzzer drive level inversion
  LCALL DELAY ;Delay
  AJMP MAIN ;Repeated loop

  DELAY:MOV R7,#228 ; Delay subroutine, changing the delay constant can change the tone of the buzzer
  DE1: DJNZ R7,DE1
  RET
  END

  2. Reversing warning sound experiment procedure: We know that various trucks and container trucks will emit a reversing warning buzzer sound when reversing, and the warning yellow light will also flash synchronously to remind the people or vehicles behind to pay attention. This experimental routine realizes the reversing warning function, and the warning sound is emitted by the buzzer on the experimental board, and the yellow warning light is emitted by the two yellow LEDs on P1.2 and P1.5 on the experimental board. [page]

  ORG 0000H
  AJMP START ; Jump to initialization program

  ORG 0033H
  START:
  MOV SP,#60H ;SP initialization
  MOV P3,#0FFH ;Port initialization

  MAIN: ACALL SOUND; buzzer sound
  ACALL YS500M; delay
  AJMP MAIN

  SOUND:
  MOV P1,#11011011B ;Light up 2 yellow warning LEDs
  MOV R2,#200 ;Sound for 200 cycles
  SND1: CLR P3.7 ;Output low level T1 conducts, buzzer sounds
  ACALL YS1ms ;Delay
  SETB P3.7 ;Output high level T1 cuts off, buzzer does not sound
  ACALL YS1ms ;Delay
  DJNZ R2,SND1
  MOV P1,#0FFH ;Turn off the yellow warning light
  RET

  YS1ms: ;1ms delay subroutine
  MOV R0,#2
  YL1: MOV R1,#250 ;Changing the value of R0 can change the sound frequency
  DJNZ R1,$
  DJNZ R0,YL1
  RET

  YS500M: ;500ms delay subroutine
  MOV R0,#6
  YL2: MOV R1,#200
  YL3: MOV R2,#250
  DJNZ R2,$
  DJNZ R1,YL3
  DJNZ R0,YL2
  RET

  END

  3. "Ding Dong" electronic doorbell experimental program: When a guest visits, if you press the doorbell button of a common household electronic doorbell, a "ding dong" sound will be emitted indoors. This experimental program simulates the pronunciation of the electronic doorbell. When we press the K1 button on the experimental board, the buzzer emits a "ding dong" music sound. It is a more practical program.

  "Ding Dong" electronic doorbell experiment ASM source program: "Ding Dong" electronic doorbell C language source program:
  ORG 0000H
  LJMP START; jump to the initialization program

  ORG 000BH
  LJMP PGT0 ; Jump to T0 interrupt service routine
  START:
  OBUF1 EQU 30H ; Initialize program
  OBUF2 EQU 31H
  OBUF3 EQU 32H
  OBUF4 EQU 33H
  FLAGB BIT 00H
  STOPB BIT 01H
  K1 BIT P3.2 ; Define button K1 as doorbell button

  MOV TMOD,#02H ; Initialize timer
  MOV TH0,#06H
  MOV TL0,#06H
  SETB ET0 ; Start timer T0
  SETB EA ; Start general interrupt

  MAIN: ;Main program
  JB K1,MAIN ;Test K1 button
  LCALL YS10M ;Delay de-jitter
  JB K1,MAIN
  SETB TR0 ;Button is valid
  MOV P1,#00H ;Light up the button indicator
  MOV OBUF1,#00H
  MOV OBUF2,#00H
  MOV OBUF3,#00H
  MOV OBUF4,#00H
  CLR FLAGB
  CLR STOPB
  JNB STOPB,$
  MOV P1,#0FFH
  LJMP MAIN ;After sending out the "ding dong" sound, return to re-test the button

  YS10M: ;10ms delay subroutine
  MOV R6,#20
  D1: MOV R7,#248
  DJNZ R7,$
  DJNZ R6,D1
  RET

  PGT0: ;Timer T0 interrupt service program
  INC OBUF3 ;A "ding-dong" sound is emitted in the interrupt service program
  MOV A,OBUF3
  CJNE A,#100,NEXT
  MOV OBUF3,#00H
  INC OBUF4
  MOV A,OBUF4
  CJNE A,#20,NEXT
  MOV OBUF4,#00H
  JB FLAGB,PGSTP
  CPL FLAGB
  AJMP NEXT
  PGSTP:
  SETB STOPB
  CLR TR0
  LJMP INT0RET
  NEXT: JB FLAGB,SOU2
  INC OBUF2
  MOV A,OBUF2
  CJNE A,#03H,INT0RET
  MOV OBUF2,#00H
  CPL P3.7
  LJMP INT0RET
  SOU2: INC OBUF1
  MOV A,OBUF1
  CJNE A,#04H,INT0RET
  MOV OBUF1,#00H
  CPL P3.7
  LJMP INT0RET
  INT0RET:
  RETI [page]

  END
  #include
  unsigned char obuf1;
  unsigned char obuf2;
  unsigned int obuf3;

  bit stopb;
  bit flagb;

  void main(void)
  {
  unsigned char i,j;

  TMOD=0x02; //Timer T0 initialization
  TH0=0x06;
  TL0=0x06;
  ET0=1;
  EA=1; //Enable general interrupt

  while(1)
  {
  if(P3_2==0) //Detect K1 button
  {
  P1=0x00;
  for(i=10;i>0;i--)
  for(j=248;j>0;j--);
  if(P3_2==0)
  {
  obuf1=0;
  obuf2=0;
  obuf3=0;
  flagb=0;
  stopb=0;
  TR0=1; //Start timer T0 and make a "ding-dong" soundwhile
  (stopb==0);
  P1=0xff;
  }
  }
  }
  }

  void t0(void) interrupt 1 using 0
  {
  obuf3++;
  if(obuf3==2000)
  {
  obuf3=0;
  if(flagb==0)
  {
  flagb=~flagb;
  }
  else
  {
  stopb=1;
  TR0=0;
  }
  }
  if(flagb==0)
  {
  obuf2++;
  if(obuf2==3)
  {
  obuf2=0;
  P3_7=~P3_7;
  }
  }
  else
  {
  obuf1++;
  if(obuf1==4)
  {
  obuf1=0;
  P3_7=~P3_7;
  }
  }
  }

Reference address:Principle and design of microcontroller driven buzzer

Previous article:Design a digital voltmeter using AT89S51 microcontroller and ADC0809
Next article:51 single chip microcomputer 8*8 dot matrix LED display principle and program

Recommended ReadingLatest update time:2024-11-16 15:54

11. GPIO principle and configuration (marquee, buzzer, button)
1. STM32 GPIO firmware library function configuration method 1. Delete some unused firmware library files in the project as needed and keep the useful firmware library files 2. Comment out these unused header files in stm32f10x_conf.h 3. The IO port of STM32 can be configured by software into the following 8 mod
[Microcontroller]
11. GPIO principle and configuration (marquee, buzzer, button)
arm7 Litian Electronics lpc2148 GPIO one buzzer test program
The experiment uses the output function of P0.22 to control the buzzer. The program sets PINSEL0 to connect P0.22 to GPIO, and sets it to output state through IO0DIR; then sets and clears P0.22 port through IO0DET and IO0CLR to control the buzzer. #include NXP/iolpc2148.h void Delay(unsigned long n); main() {   PI
[Microcontroller]
arm7 Litian Electronics lpc2148 GPIO one buzzer test program
51 microcontroller program - let the buzzer sound
#include   #define uint unsigned int //Macro definition sbit SPK=P3^5;             //Define speaker port   void delay(uint z) { uint x,y; for(x=z;x 0;x--) for(y=110;y 0;y--); }   void main() {     while(1)     {          delay(100);      SPK=0; delay(100);         SPK=1;     }
[Microcontroller]
Improvement of microcontroller driven piezoelectric buzzer
This article focuses on how to drive a piezo buzzer with a large AC voltage using a microcontroller. It uses a four-MOSFET circuit connected to two I/O pins of the microcontroller (Reference 1). The following is a modification and expansion of this circuit in this article that saves an I/O pin of the microcontroller.
[Microcontroller]
Improvement of microcontroller driven piezoelectric buzzer
"Beginner's C51 Self-study Notes" Buzzer and Relay
Relay, DIP switch and buzzer; connect them in sequence (same for relay) #include reg52.h sbit beep=P0^1; void main() { beep=1; } A small current flows in from the lead wire, and the core generates magnetic force to pull the armature downward, so that the end point will also go down; // Repeatedly pull in a
[Microcontroller]
51 single chip microcomputer program - use buttons to control the start and stop of the buzzer
#include   #define uint unsigned int //macro definition sbit SPK=P3^5;             //define speaker port sbit key=P3^1;             //The corresponding key on the development board is s18   void delay(uint z) { uint x,y; for(x=z;x 0;x--) for(y=110;y 0;y--); }   void main() {     while(1)
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号