Arduino buzzer and 7 segment display not working

Hello friends, I made a small circuit on tinkercad, everything works perfectly, but when I plug the arduino into the computer, the 7 segment display and buzzer do not work at all, the leds and buttons are working perfectly, I will share the codes and the picture of the circuit below, can you help me?

#define button1 7 //the number of the button 1
#define button2 8 //button2 attach to
#define button3 9 //button3 attach to
#define button4 10 //button4 attach to
#define button5 12 //button4 attach to
#define buzzerPin 11 //the buzzer attach to
#define LED1 2 //LED1 attach to
#define LED2 3 //LED2 attach to
#define LED3 4 //LED3 attach to
#define LED4 5 //LED4 attach to
#define LED5 13 //LED4 attach to
#define uint8 unsigned char
uint8 flag = 0; //used to indicate the state of button4 key
uint8 b1State,b2State,b3State,b4State,b5State = 0;

void setup()
{

pinMode(6, OUTPUT);
pinMode(1, OUTPUT);
pinMode(0, OUTPUT);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
pinMode(A4, OUTPUT);

//initialize buzzer,LED1, LED2, LED3 and LED4 as output
pinMode(buzzerPin, OUTPUT);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
pinMode(LED3, OUTPUT);
pinMode(LED4, OUTPUT);
pinMode(LED5, OUTPUT);
//initialize button1,button2,button3 andbutton4 as input,combined with pullup
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
pinMode(button5, INPUT_PULLUP);
//turn all the led off

digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);

}
void loop()
{
//turn all the led off
digitalWrite(LED1, LOW);
digitalWrite(LED2, LOW);
digitalWrite(LED3, LOW);
digitalWrite(LED4, LOW);
digitalWrite(LED5, LOW);
digitalWrite(6,LOW);
digitalWrite(1,LOW);
digitalWrite(0,LOW);
digitalWrite(A0,LOW);
digitalWrite(A1,LOW);
digitalWrite(A2,LOW);
digitalWrite(A3,LOW);
digitalWrite(A4,LOW);
//read the state of the button5
b5State = digitalRead(button5);
//when button5 pressed
if(b5State == 0)
{
if(b5State == 0) //confirm that the button4 is pressed
{
flag = 1; //if so,flag is 1
digitalWrite(LED5, HIGH);//turn the host LED on
delay(200);
}
}
if(1 == flag)
{
//read the state of the button of buttons
b1State = digitalRead(button1);
b2State = digitalRead(button2);
b3State = digitalRead(button3);
b4State = digitalRead(button4);
//If the button1 press the first
if(b1State == 0)
{
flag = 0;
digitalWrite(LED5, LOW);
Alarm(); //buzzer sound
digitalWrite(LED1,HIGH); //turn the LED1 on only
digitalWrite(LED2,LOW);
digitalWrite(LED3,LOW);
digitalWrite(LED4,LOW);
digitalWrite(6,LOW);
digitalWrite(1,LOW);
digitalWrite(0,HIGH);
digitalWrite(A0,HIGH);
digitalWrite(A1,HIGH);
digitalWrite(A2,LOW);
digitalWrite(A3,LOW);
digitalWrite(A4,LOW);

  while(digitalRead(button5));
  
  //detect the button4,if pressed,out of the while loop
}
//If the button2 press the first
if(b2State == 0)
{
  flag = 0;
  digitalWrite(LED5, LOW);
  Alarm();
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,HIGH); 
  digitalWrite(LED3,LOW);
  digitalWrite(LED4,LOW); 
  digitalWrite(6,HIGH);
  digitalWrite(1,HIGH);
  digitalWrite(0,LOW);
  digitalWrite(A0,HIGH);
  digitalWrite(A1,HIGH);
  digitalWrite(A2,HIGH);
  digitalWrite(A3,LOW);
  digitalWrite(A4,HIGH);
  while(digitalRead(button5));
}
//If the button3 press the first
if(b3State == 0)
{
  flag = 0;
  digitalWrite(LED5, LOW);
  Alarm();
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,HIGH); 
  digitalWrite(LED4,LOW); 
  
  digitalWrite(6,LOW);
  digitalWrite(1,HIGH);
  digitalWrite(0,HIGH);
  digitalWrite(A0,HIGH);
  digitalWrite(A1,HIGH);
  digitalWrite(A2,HIGH);
  digitalWrite(A3,LOW);
  digitalWrite(A4,HIGH);
  while(digitalRead(button5));
}
 if(b4State == 0)
{
  flag = 0;
  digitalWrite(LED5, LOW);
  Alarm();
  digitalWrite(LED1,LOW);
  digitalWrite(LED2,LOW);
  digitalWrite(LED3,LOW); 
  digitalWrite(LED4,HIGH); 
   
   digitalWrite(6,LOW);
  digitalWrite(1,LOW);
  digitalWrite(0,HIGH);
  digitalWrite(A0,HIGH);
  digitalWrite(A1,HIGH);
  digitalWrite(A2,LOW);
  digitalWrite(A3,HIGH);
  digitalWrite(A4,HIGH);
  while(digitalRead(button5));
}

}

}
//buzzer sound
void Alarm()
{
for(int i=0;i<100;i++)

{
digitalWrite(buzzerPin,HIGH); //the buzzer sound
delay(2);
digitalWrite(buzzerPin,LOW); //without sound
delay(2); //when delay time changed,the frequency changed
}
}

Is your 7-segment display common anode or common cathode?

how can ı find anode or cathode?

Please do read and follow the instructions for posting code.

Edit your first post using the "pencil" icon. :+1:

1 Like

Most of us use the device data sheet to find the function of each one of the pins. That will show which pins are the anodes and cathodes of the display.

Wire it for one of those. If it doesn't light up, it might be the other. Change the wiring to the other. If it still doesn't light up, you made a mistake somewhere.

Chekin common anode or common cathode is easy with multimeter with diode check if all else attempts to identify component pinout fails.

Not always. Many modern meters do not respond to diode drops very much greater than 0.7V, in the diode check mode. The reason is that it is better for in-circuit testing (so it won't respond to alternate, multi component electrical paths). Usually, a LED voltage drop is too much for those meters and it won't work.

Also, meters don't respond very well to Tinkercad circuits. :slight_smile: One should look up the Tinkertoy component used, the attributes should be listed right there.

Please pay attention to post #4.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.