How to Interface Buzzer with Microcontroller Electronics Project

Function

This project shows how to interface a buzzer to the microcontroller. When a push button has pressed a buzzer will on and off 30 times and then stops.

Components

  • AT89C2051 microcontroller
  • Push button switch
  • Buzzer
  • Capacitors: 33pF,33pF,10uF
  • Resistor 8.2KO

Circuit diagram

A circuit diagram for interfacing buzzer to the microcontroller is shown in the figure below. Bit 7 of port 1 is directly connected to a small buzzer. This type of connection is possible only when the current required for the buzzer is less than 20mA. The port output is in current source mode so that the buzzer will turn on when the output is at logic LOW. Bit 0 of port 3 is connected to the push button switch which is held at a logic high by the pull-up resistor.

simple buzzer interface circuit diagram
simple buzzer interface circuit diagram

simple buzzer interface
simple buzzer interface

Program description

The buzzer is initially OFF. When the push button is pressed, the buzzer is turned ON and OFF 30 times, with a one second delay between each output.

Download

Click here to download .C and .HEX file

You may also like

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!

LED Dice using Microcontroller (8051): Electronics Project

In this project, we are going to build a LED Dice using microcontroller. We have already seen many microcontroller project, you can check all the previous project here. This project is used to simulate dice, which displays a random number from 1 to 6 by using 6 LEDs connected to port 1 of the microcontroller. Pin no 2 (or bit 0 of port 3 (P3.0)) is used as the input and a push-button switch is connected to this pin. Every time, when we press this switch, a new number is displayed.

Circuit Diagram: LED Dice using Microcontroller

The circuit diagram for LED Dice using microcontroller project is shown in the figure below.

LED dice using AT89C2051 microcontroller Electronics mini project
LED dice using microcontroller

LED dice using AT89C2051 microcontroller
LED dice using AT89C2051 microcontroller

LED dice using AT89C2051 microcontroller
LED dice using AT89C2051 microcontroller

Bit 0 of port 3 is generally held at logic HIGH with pull-up resistor R3=100K. when switch S1 is pressed, bit 0 of port 3 moves to logic LOW and is detected by the microcontroller. As shown in circuit diagram all the seven LEDs are so mounted that they will show dots for different numbers as in real dice.

The different patterns for different numbers are shown below:

LED dice using microcontroller
LED dice using microcontroller

Program Description

A random dice number is obtained during scanning of the push-button switch as follows. The program scans the push-button switch continuously. If the switch is not pressed (i.e. at logic HIGH), a number is incremented between 1 and 6. Whether the push-button is pressed, the current value of the number is read and this value is used as the new dice number. Since the switch is pressed by the user in random, the numbers generated are also random numbers from 1 to 6. The new random number is displayed on the seven LEDs appropriately. After about 2 seconds delay, all LEDs are turned off and the above process is repeated forever.

Download

Click here to download .C and .HEX file for this project.

If you like this article, please share it with your friends and like or facebook page for future updates. Subscribe to our newsletter to get notifications about our updates via email. If you have any queries, feel free to ask in the comments section below. Have a nice day!