View Tutorial Metadata Edit Content Revision History Add to Watchlist Add New Tutorial Blinking a LED with Arduino

Blinking a LED with Arduino

The "Hello World!" code for Arduino : blinking a LED. You can see the electronic part in the link above.

//the pin on which you connect the anode (+) of the LED
byte ledPin =  13;
//our on/off switch
byte state = LOW;
 
//this function runs only once (after reset)
void setup(){                
  //set the pin we use to OUTPUT so we can power-up the LED
  pinMode(ledPin, OUTPUT);     
}
 
//this function runs continuosly (after setup)
void loop(){
  //toggle our switch (if off make it on and vice-versa)
  if (state == LOW){
    state = HIGH;
  } else {
    state = LOW;
  }
  //toggle the LED based on our switch above
  digitalWrite(ledPin, state);
  //sleep for 1000 ms = 1 second
  delay(1000);
}

A picture of the electronic part :

http://stuff.nekhbet.ro/wp-content/uploads/2009/08/DSCF4594.jpg

Only plain text supported.

Optional

Required - will be kept private

Optional

 
 

Rating: (1+, 0-) In: Arduino