Monday, 19 January 2015

Blink code in Arduino ( Blink LED ON and OFF using Arduino)


/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.
 
  This example code is in the public domain.
 */
 
// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

// the setup routine runs once when you press reset:
void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

// the loop routine runs over and over again forever:
void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
}




The following code is available by default in Arduino in File---->Examples---->basics----->blink

Working of the code

The pin 13 avail in the Arduino UNO has a On-board LED with a internal resistance with it .
so in order to activate the internal resistance the code " pinMode(led,OUTPUT) "(in void setup) is used.
The variable led is initialized with 13 and the pin 13 is said to be a output.
So the resistance of the on board LED is activated.


Now in void loop()  the code

digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
 
supplies 5v(ie Vcc) to the LED and hence it glows up..!! :D
now it has a delay(1000) which waits for one second and again it switches off the LED and waits for 1 sec.

This process repeats for ever in void loop()..!!


No comments:

Post a Comment