4 digit binary counter skipping

Hello Everyone! I am new to Arduino and I have a question. Why is 0001 is not displaying correctly? It does not follow the 1-second delay I coded. Thank you for the help!

This will light up 4 LEDs depending on the value.2021-09-16 15-32-38_Trim (1)

SOURCE CODE:

void setup()
{
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
}

void loop()
{
  digitalWrite(2,0);//0000
  digitalWrite(3,0);
  digitalWrite(4,0);
  digitalWrite(5,0);
  delay(1000);
  digitalWrite(2,1);//0001
  digitalWrite(3,0);
  digitalWrite(4,0);
  digitalWrite(5,0);
  delay(1000);
  digitalWrite(2,0);//0010
  digitalWrite(3,1);
  digitalWrite(4,0);
  digitalWrite(5,0);
  delay(1000);
  digitalWrite(2,1);//0011 
  digitalWrite(3,1);
  digitalWrite(4,0);
  digitalWrite(5,0);
  delay(1000);
  digitalWrite(2,0);//0100 
  digitalWrite(3,0);
  digitalWrite(4,1);
  digitalWrite(5,0);
  delay(1000);
  digitalWrite(2,1);//0101 
  digitalWrite(3,0);
  digitalWrite(4,1);
  digitalWrite(5,0);
  delay(1000);
  digitalWrite(2,0);//0110 
  digitalWrite(3,1);
  digitalWrite(4,1);
  digitalWrite(5,0);
  delay(1000);
  digitalWrite(2,1);//0111 
  digitalWrite(3,1);
  digitalWrite(4,1);
  digitalWrite(5,0);
  delay(1000);
  digitalWrite(2,0);//1000 
  digitalWrite(3,0);
  digitalWrite(4,0);
  digitalWrite(5,1);
  delay(1000);
  digitalWrite(2,1);//1001 
  digitalWrite(3,0);
  digitalWrite(4,0);
  digitalWrite(5,1);
  delay(1000);
  digitalWrite(2,0);//1010 
  digitalWrite(3,1);
  digitalWrite(4,0);
  digitalWrite(5,1);
  delay(1000);
  digitalWrite(2,1);//1011 
  digitalWrite(3,1);
  digitalWrite(4,0);
  digitalWrite(5,1);
  delay(1000);
  digitalWrite(2,0);//1100 
  digitalWrite(3,0);
  digitalWrite(4,1);
  digitalWrite(5,1);
  delay(1000);
  digitalWrite(2,1);//1101 
  digitalWrite(3,0);
  digitalWrite(4,1);
  digitalWrite(5,1);
  delay(1000);
  digitalWrite(2,0);//1110 
  digitalWrite(3,1);
  digitalWrite(4,1);
  digitalWrite(5,1);
  delay(1000);
  digitalWrite(2,1);//1111
  digitalWrite(3,1);
  digitalWrite(4,1);
  digitalWrite(5,1);
  delay(1000);
}``'

Please follow the advice given in the link below when posting code. Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

1 Like

done editing

Hello
You may check the hardware.
Did you connect the LED correct?

1 Like

I think so. See the GIF above. When 0001 is the next to be output. It just lights up a little bit. It doesn't follow 1-second delay.

Use the Blink sketch to drive the LED with the problem. Does it work ?

It does not resolve the problem.

Now I think he would only be in the simulator world. :roll_eyes:
No actual component is used.

If you are saying that Blink does not work with the LED then you have a hardware problem. Check the wiring. Swap LEDs between positions. Does the problem follow the LED or is it with one pin ? Are all of the resistors the same value ? What is the value of the resistors ?

btw, I am using tinkercad only.

I am using tinkercad only

The operation result of the simulator is not guaranteed.
Especially from TinkerCad.
Please actually build the circuit with real components.
It should work.

So do you think this is a bug in Tinkercad? I think the code is fine that is why I am confused about why is it happening.

I think it's a problem of lack of your PC specs, but it's safe to say bugs.
Probably the first process when simulation begin to be executed is taking a time.
Try inserting delay (3000); at the beginning of the loop to delay the start.

Well, get the actual Arduino. :wink:

1 Like

If the real circuit, with a real Arduino and real LEDs, works, and the simulator does not, then it must be a bug in the simulator.

1 Like

Well, I already bought one but It doesn't arrive yet so I'm stuck with the simulator for now.

Thank you for the insight. The simulator must be the problem.

Your Arduino has not arrived yet, so you cannot know yet.

Does the Blink example sketch work in Tinkercad using the built in LED ?

yes it works fine. I noticed that the problem only happens in the first iteration. When it loops for the 2nd iteration it works fine.