What is Blink code:

Blink code is one of the basic arduino codes which are done in Arduino IDE. In this code, we will write a code for a led light to blink for a time of ‘a’ milli seconds out of after a time period of ‘t’ seconds.

Code for blink:

int a = 500;

int b = 2000;

void setup() {

  pinMode(LED_BUILTIN, OUTPUT);

}

void loop() {

  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)

  delay(a);                       // wait for ‘a’ milli seconds

  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW

  delay(b);                       // wait for ‘b’ milli seconds

}

Code explaination:

Here,we need to initialize variables on top of void setup,as shown. In void setup, we initialize digital pin LED_BUILTIN as an output, where LED_BUILTIN is the 13th pin of arduino board which has a built in LED in it. After completing void setup, we come to void loop, where we do actual coding. We have written digitalWrite(LED_BUILTIN, HIGH); which means to turn the LED on (HIGH is the voltage level) till ‘a’ miliseconds (written as delay(a)) . Then we have written digitalWrite(LED_BUILTIN, LOW); which means to turn the LED off by making the voltage LOW till ‘b’ milliseconds(written as delay(a)) . So this code makes the built in LED to blink for 500 milli seconds for every 2 seconds.

This is how LED glows when we dump high

This is how LED doesn’t glow when we dump LOW.

Categories: ArduinoTutorials

0 Comments

Leave a Reply