Arduino Tutorials:Blink code in Arduino IDE

Published by sandesh on

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.

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.

Next Post:Turning on and off an LED from Serial Monitor

Previous Post:Uploading code to and introduction to com port to Arduino board


1 Comment

Arduino Tutorials:Uploading code to and introduction to com port to Arduino board - projectsflix · January 3, 2021 at 6:04 pm

[…] Next Post:Blink code in Arduino IDE […]

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.