Sunday, December 22, 2013

Interfacing Of a Buzzer Using Microcontroller 89C52/89S52

Interfacing Of a Buzzer Using Microcontroller 89C52/89S52 

Welcome back embedded system geeks! In this article we are going to learn about the interfacing of a Buzzer with the microcontroller. But if this is your first mini-project you should probably check-out my previous article on Blinking LED'S for more understanding of the programming I will be dealing with this project. Once you get to know what Buzzer is and the programming logic behind connecting a Buzzer and a microcontroller you will able to apply the same logic to any microcontroller (i.e. your microcontroller may be a PIC or an AVR microcontroller). At the end of the explanation of the code there are some questions for you to answer which can help you to improve your programming skills.

why do we need a Buzzer? 

Buzzer is used many times in embedded systems. For an instance-Digital clock with an alarm-here buzzer can be used an alarm or a fire alarm or an intruder alarm. There are so many uses.

Components required

  • 1 microcontroller 89C52(89S52 will also do)
  • 1 potentiometer-10k
  • 2 ceramic capacitors-22pF
  • 1 switch(button for reset purpose)
  • 1 electrolytic capacitor-10uF,25V
  • 1 crystal oscillator-11.0592MHz
  • 1 resistor-10k
  • 5 LED's
  • 1 resistor-1k
  • 5 330 ohm resistor
  • 1 Buzzer
  • 1 transistor-BC548

Schematic Diagram 


This project has been made using Proteus software.If you want to learn more about the software you can watch the tutorials provided below

The connection of the circuit is explained below

  • Port 2 of the microcontroller is defined as the output port
  • Port 3 of the microntroller is defined as the output port
  • 4 LED's are connected to the four pins of the output port 2 from P2.0 TO P2.3 respectively
  • An LED is connected to the pin 3 of the output port 3 of the microcontroller
  • A Buzzer is connected to the pin 8 of the output port 3
  • Other components connected to the microcontroller are for the working of the microcontroller.


The working of the circuit is shown with an application of a decade counter. As soon as the microcontroller receives a power supply, the counter will start counting. An image of the counter is shown below



The Decade counter will count from 0 to 9 and when the counter counts 9, the buzzer will be switched ON.The transistor connected to the buzzer acts as a switch.The programming of the microcontroller is explained below:

#include "REGX52.H"
#include "delay.h" /*delay header file is included*/
void main()
P2=0X00;/*port 2 is defined as output port*/
P3=0XFF;/*port 3 is defined as output as port*/
{ P3_2=0; /*set pin 3 of port 2 to logic 0 */
P3_7=0; /*set pin 8 of port 2 to logic 0 */
P2=0X00; /*code for the decade counter begins here*/
delay_sec(1); /* code for decade counter ends here*/
{ P3_2=1; /*LED is switched ON*/
P3_7=1; /*buzzer is switched ON*/
delay_sec(3); /*buzzer is switched ON for 3 seconds*/
P3_2=0; /*LED is switched OFF*/
P3_7=0; /*buzzer is switched OFF*/

Try this for Fun      

No comments:

Post a Comment