# 8 channel quiz buzzer circuit using 8051 microcontroller

Project: 8 channel quiz buzzer circuit using 8051 microcontroller from this site.

For the first candidate who presses their button, their number will show on the 7-segment display and the buzzer will make a sound.I am using peizo-buzzer in the circuit.

After making all the connections, the display is working but the buzzer is not making any sound. Buzzer delay time in code in 1ms. When we give direct 5V supply to the buzzer it works, but not in the circuit.

Please give me some solution for this.

#include<reg51.h>

#define SEGMENT P2 // PORT2 to Segments of 7-Segment Display
#define SWITCH P1  // Input Switches (buttons) to PORT1

sbit buzz=P3^0; // Buzzer
sbit rst=P3^3; // Reset Switch (Reset the display) - not the microcontroller
sbit digit=P3^7; // 7-Segment Display Common Pin (to enable)

void delay (int); // Delay function

int x=0,y,z;
unsigned char ch[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x98}; // Hexadecimal values from 0 to 9.

void delay (int d)
{
unsigned char i;
for(;d>0;d--)
{
for(i=250;i>0;i--);
for(i=248;i>0;i--);
}
}

void main()
{
SWITCH=0xff;
SEGMENT=0xff;
digit=1;
buzz=0;
rst=1;

while(1)
{
while(SWITCH==0xff); // wait until any button is pressed.

while (SWITCH==0xfe) // Button 1 is pressed.
{
SEGMENT=ch[1];
buzz=1;
delay(1000); // Activate buzzer for 1 second.
buzz=0;
while(rst!=0); // display the digit until the reset is pressed.
}

while (SWITCH==0xfd) // Button 2 is pressed.
{
SEGMENT=ch[2];
buzz=1;
delay(1000);
buzz=0;
while(rst!=0);
}

while (SWITCH==0xfb) // Button 3 is pressed.
{
SEGMENT=ch[3];
buzz=1;
delay(1000);
buzz=0;
while(rst!=0);
}

while (SWITCH==0xf7) // Button 4 is pressed.
{
SEGMENT=ch[4];
buzz=1;
delay(1000);
buzz=0;
while(rst!=0);
}

while (SWITCH==0xef) // Button 5 is pressed.
{
SEGMENT=ch[5];
buzz=1;
delay(1000);
buzz=0;
while(rst!=0);
}

while (SWITCH==0xdf) // Button 6 is pressed.
{
SEGMENT=ch[6];
buzz=1;
delay(1000);
buzz=0;
while(rst!=0);
}

while (SWITCH==0xbf) // Button 7 is pressed.
{
SEGMENT=ch[7];
buzz=1;
delay(1000);
buzz=0;
while(rst!=0);
}

while (SWITCH==0x7f) // Button 8 is pressed.
{
SEGMENT=ch[8];
buzz=1;
delay(1000);
buzz=0;
while(rst!=0);
}

SEGMENT=0xff;
rst=1;

}
}

• it sounds like the microcontroller output is too weak to drive the buzzer, measure the voltage on the buzzer – Jasen Mar 27 '19 at 8:19
• Can you remove disconnect the resistor from pin 10 of the AT89C51 and drive it manually with 5V? (P.S. do use reference names as well for components, it is easier to refer to them that way) – Huisman Mar 27 '19 at 8:58
• P3^3 What language is this? It is nonsense in C, ^ being the bitwise XOR operator. – Lundin Mar 27 '19 at 9:07
• @Lundin It is no nonsense. Please read keil.com/support/man/docs/c51/c51_le_sbit.htm – Huisman Mar 27 '19 at 9:23
• @Huisman Of course it is nonsense in C, since the ^ operator is already taken and perfectly valid to use inside an initializer. This is clearly not valid C but non-standard extensions. There are of course many other reasons why Keil has such a bad reputation, this is just one of them. – Lundin Mar 27 '19 at 9:39

The 8051 and clones typically use an I/O configuration that is described as "pseudo-bidirectional". They have active pull-down but quasi-passive pull-up (there's a transistor that is turned on briefly to improve the rise time). This means that they can only source a tiny amount of continuous current to an external device. The datasheet (DC Characteristics, page 10) shows that VOH drops to 2.4V at just 60 µA of current.

This is not enough current to drive your NPN transistor. Instead, try putting a logic-level N-channel MOSFET there.

Note also that your other NPN (the one attached to pin 17 — you really do need to use reference designators in your schematics!) should actually be a PNP. This requires inverting the logic in your code that drives pin 17.

• There's only one digit of display so the transistor attached to pin 17 is not even needed at all. The SEGMENT=0xFF line at the end of the loop blanks the display. – Finbarr Mar 27 '19 at 13:04
• @Dave Tweed any reference for MOSFET ...I want MOSFET number. – Shrutika Jagtap Apr 2 '19 at 10:26
• You could try the 2N7000 or the BSS138. – Dave Tweed Apr 2 '19 at 11:04
• @Dave Tweed I tried with 2N7000 (drain terminal connected to the ground, gate terminal to 13 pin of controller, source terminal negative terminal of buzzer), but now when I switch on the circuit buzzer continuously beeps. – Shrutika Jagtap Apr 9 '19 at 11:56
• You swapped drain and source, and the body diode is conducting regardless of the state of the gate. The source should be connected to ground. – Dave Tweed Apr 9 '19 at 12:07

You don't say what type of device the buzzer is (electromechanical, piezo, etc.) or how much current it requires to operate, but I don't think either of those is the problem.

One millisecond is too short a time for the buzzer to wake up and make enough noise to be heard. Increase the on-time to 1 second to verify that the code is working, then adjust to taste.

BTW, what type of buzzer is it? Datasheet or link?

• Hi, "One millisecond is too short a time for the buzzer to wake up" FYI the OP isn't claiming to drive the buzzer for 1ms. The code (I added a link to the original source page) is supposed to switch on the buzzer, delay for 1000 x 1ms = 1s (hence the delay(1000);), then switch the buzzer off. There are comments in the original code which I linked (not included by the OP) which make this clearer. That doesn't answer all of your questions, but I hope their intent is now clearer. – SamGibson Mar 27 '19 at 12:18