user11493: i want the led to light at the beginning and stays like this for a while then turns off, so i wrote:
int led=13;
void setup() {
  pinMode(led,OUTPUT);    
}
void loop() {
    digitalWrite(led,HIGH);
    delay (5000);
    digitalWrite (led,LOW);
}

as i understand it should start with high means on digitalWrite(led,HIGH)...and stays like this for 5000us  delay (5000)  then it should turn off with  digitalWrite (led,LOW).
but why its not working, it starts with off for afew seconds then stays on..what i understand wrong with these simple steps ????

user21074: It immediately loops, from the digital write low to digital write high. Add a second delay after the low, so that it waits before it loops to the top again.

user39059: The "loop()" will keep repeating itself, turning the led on and off forever.
If you want turn the led on just once, put the commands for turn the led on in "setup()" section:

void setup() {
    pinMode(led,OUTPUT);
    digitalWrite(led,HIGH);
    delay (5000);
    digitalWrite (led,LOW);
} 
void loop() {
}
Other method would be add a variable to count how much times the led should light. I copied the following sketch from here

int ledPin =  13;    // LED connected to digital pin 13
int alreadyBlinked = 0;

// The setup() method runs once, when the sketch starts
void setup()   {
pinMode(ledPin, OUTPUT);    // initialize the digital pin as an output:
}

// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()                    
{
     if(alreadyBlinked == 0)
     {
            digitalWrite(ledPin, HIGH);   // set the LED on
            delay(5000);                  // wait for five seconds
            digitalWrite(ledPin, LOW);    // set the LED off
            alreadyBlinked = 1;
      }
}

When the variable "alreadyBlinked" is set to 1, the led will not turn on again.

11493: <p>i want the led to light at the beginning and stays like this for a while then turns off, so i wrote:</p>

<pre><code>int led=13;
void setup() {
  pinMode(led,OUTPUT);    
}
void loop() {
    digitalWrite(led,HIGH);
    delay (5000);
    digitalWrite (led,LOW);
}
</code></pre>

<p>as i understand it should start with high means on digitalWrite(led,HIGH)...and stays like this for 5000us  delay (5000)  then it should turn off with  digitalWrite (led,LOW).
but why its not working, it starts with off for afew seconds then stays on..what i understand wrong with these simple steps ????</p>
 21074: <p>It immediately loops, from the digital write low to digital write high. Add a second delay after the low, so that it waits before it loops to the top again.</p>
 39059: <p>The "loop()" will keep repeating itself, turning the led on and off forever.
If you want turn the led on just once, put the commands for turn the led on in "setup()" section:</p>

<pre><code>
void setup() {
    pinMode(led,OUTPUT);
    digitalWrite(led,HIGH);
    delay (5000);
    digitalWrite (led,LOW);
} 
void loop() {
}</code></pre>

<p>Other method would be add a variable to count how much times the led should light. I copied the following sketch from <a href="http://forum.arduino.cc/index.php?topic=47983.0" rel="nofollow noreferrer">here</a></p>

<pre><code>
int ledPin =  13;    // LED connected to digital pin 13
int alreadyBlinked = 0;

// The setup() method runs once, when the sketch starts
void setup()   {
pinMode(ledPin, OUTPUT);    // initialize the digital pin as an output:
}

// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()                    
{
     if(alreadyBlinked == 0)
     {
            digitalWrite(ledPin, HIGH);   // set the LED on
            delay(5000);                  // wait for five seconds
            digitalWrite(ledPin, LOW);    // set the LED off
            alreadyBlinked = 1;
      }
}
</code></pre>

<p>When the variable "alreadyBlinked" is set to 1, the led will not turn on again.</p>
