Switch, LED and Buzzer

Read the status of the momentary switch connected to any port pin and display it on the LED & make the buzzer beep connected to another port pin.

Required components

  • 8051 MCU
  • 1 LED
  • Registers 330 ohm
  • Push to on switch
  • Jumpers

Circuit diagram

SwitchLEDBuzzer

RED LED is connected to the 0th pin of port 2. The cathode of each LED is connected to Ground. Anode of LED is connected to port pin P2.1.  The resistor is needed to limit the flow of current.

As the cathode of LED is connected to the Ground terminal, we just need to provide a positive voltage to LED`s Anode terminal. So in order to turn on the LED we just need to give HIGH logic (1) to port pin P2.1.

Push Button switch is connected to P1.1 and Buzzer is connected to P2.5.

Code

Code Description

To turn on LED and Buzzer when the switch is pressed, we just need to read the switch status, and based on switch status just have to turn on LED and Buzzer. So Cathode terminal of LED is connected to ground we need to give high logic to LED anode terminal to turn it on(when the switch is pressed) the same as Buzzer as well.

Initially, Port1 is initialized with 0xff. so when the switch is pressed and as another terminal of the switch is connected to the ground Port1.1 will receive logic 0.

Once the switch is pressed, it will give high logic to LED and Buzzer which in turn will glow the led and make the buzzer active.

Download Proteus Circuit and Hex File

Video

Thank you for reading…

Leave a Comment

Your email address will not be published. Required fields are marked *