Sunday, November 17, 2013

Blinking an LED with Arduino

This is tutorial number 1 from our series of Arduino tutorials and in this part I will talk about blinking an LED using the one already available on the Arduino Uno board or using an external LED to blink. The board has an LED connected at digital pin 13 that turns ON when the pin is set HIGH and turns OFF when is LOW.

You can see more arduino led projects here.

CODE :

void setup() {
   pinMode(13, OUTPUT); //set pin 13 as output
}
void loop() {
   digitalWrite(13, HIGH); //set pin 13 high (+5V)
   delay(1000); //wait 1000 ms = 1 second
   digitalWrite(13, LOW); //set pin 13 low (0V)
   delay(1000); // wait 1 second
}
 
 
 
 
 
Code Explanation
If you upload this sketch you’ll notice that the LED is blinking once every second. Now let’s analyze the code. In the setup function is only one instruction that sets the pin 13 as OUTPUT. This instruction is executed only one time. Next is the loop function that sets the pin 13 HIGH (+5V on pin 13), waits a second (1000 ms), then turns OFF the LED (0V on pin 13) and waits another second.
The loop function runs as long as the Arduino board is powered and will blink the LED ON and OFF withe 1 second pause between states.
You can use another pin, for example pin 12 and then change the code, and in this case the onboard LED won’t light anymore. You can change the delay time too, by simply editing the code, but remember that the time is in milliseconds.








 

No comments:

Post a Comment