LED blinking with delay

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(13, LOW);
  delay(1000);
  digitalWrite(13, HIGH); 
}

I have doubt after delay i tshould have to turn ON for long right, but it's turn OFF, if any one knows explain

Put another delay after the

Otherwise the LED turns on and loop() starts over right away and turns the LED off.

i know for blinking we have to put delay, i have to know why it's in LOW state because it should be in high state right

1 Like

A LED can be turned on by either a LOW or HIGH, see the two circuits D1 and D2 in the schematic.

I didn't understand what are you trying to say

Hello sureshkumar_123

Try and checked this simplified sketch.

void setup() {
  // put your setup code here, to run once:
  pinMode(13, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(13,!digitalRead(13));
  delay(1000);
}

As mentioned, add a second delay( ).

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(13, LOW);
  delay(1000);
  digitalWrite(13, HIGH); 
  delay(1000);
}

In the schematic, look at the symbols of the LEDs.

In D1 circuit, the cathode goes to the Arduino pin.

In D2 circuit, the anode goes to the pin.

Don’t be too worried, this is the first mistake that almost every user encounters when they write their own first blink program !

What is the meaning of "Blinking a LED"?

1. Turn ON the LED.
2. Wait for a while so that the brightness of the LED is visible.
3. Turn OFF the LED.
4. Wait for a while so that the brightness of the LED is visible.
5. repeat from Step-1.

If you omit Step-4, you will not see that the LED is OFF though there is a code in Step-3 to turn OFF the LED. The control instantly goes to Step-1 and the LED is ON again.

1 Like

why it's instantly going to step 1

That’s the way it works.

If not instatntly, then it will take 1 or 2 cycle time (0.0625 us or 0.1250 us with 16 MHz UNO) to reach at Step-1.

Okay Thanks, now i understood its turning OFF the LED but we can't see that right.

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