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.
- 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
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:
Try this for Fun
Try to program your microcontroller in which the Buzzer is used as a musical device meaning your buzzer will output a musical tune .