“LED Blinking” Program on Arduino

So, We will learn today the very first program on Arduino which we can say normally like “Hello World” of Arduino. Something like which we learn for the very first time in any of the programming language be it C or C++ or python etc. But hold on, We are not going to print “Hello World” on our Arduino Board , right ?? because we do not have any interface like LED or TFT screens where we can see this… then what ??

What we are going to do today is that we are actually going to Blink an LED on one of the pins of Arduino Board. This will help us with two things

  1. It will give us an idea about the Pins on the Arduino Boards
  2. It will give us some knowledge about the programming steps too.

So, Are you guys excited now ?

Normally on most of the Arduino Boards, there is a LED connected on Pin number 13.

For Ex: Arduino UNO board has a LED connected  at Pin 13.

I hope that before trying out this program, you must be ready with Arduino Software Installation and Arduino Board Connection (Visit this Arduino Basics page)

Step 1: Connect Your Arduino Board via USB cable to your PC

Step 2: Open Arduino Software, Click on Tools -> Board

select your particular Arduino Board (In my case, it is Arduino UNO). Also, make sure that PORT number is also selected right (in my case, it is PORT 5) (As shown in below figure)

ardinput

Step 3: Click on File -> New

It will open a new Sketch, It will have two functions already defined in it.

Void setup() and Void loop().

setup() is a function which will be called only once when your Arduino Starts or  whenever you click a reset button on your Arduino Board. loop() is a function which will always be running in a loop throughout the time Arduino Board is powered on.

Step 4: Let us write the program as shown below

// Program Starts Here

#define LED_PIN 13
void setup() {
// put your setup code here, to run once:
pinMode( LED_PIN, OUTPUT);
}

void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_PIN, HIGH); // Turn on the LED.
delay(1000); // Wait 1 second (1000 milliseconds).
digitalWrite(LED_PIN, LOW); // Turn off the LED.
delay(1000);

}

//Program Ends here

Explanation of the Above program:

Above program is self explanatory.

first we define Pin 13 as LED_PIN (since we know pin 13 is having an LED connected to it)

In setup() function, we define that pin 13 as OUTPUT

In loop() function, we switch on the LED for 1 sec and then switch off the LED for 1 sec in a continuous loop. So, LED Blinking will keep on happening till the Arduino Board is powered on.

Step 5: Click on Sketch -> Verify/Compile

It will take some time to compile the program. Alternatively, you can press CTRL+ R.

Step 6: Click on Sketch -> Upload

It will upload the program on Arduino Board. Alternatively, you can press CTRL+ U. While uploading you can see Tx/Rx LEDs blinking as shown which means that upload is happening properly. Forget about other Red wires in the below figure.

img_20161219_185343
Tx Rx LED Blink

Once Upload finishes, you must observe the LED at Pin 13 starts blinking On/Off every 1 sec.

Congratulations!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Today you have completed your first LED blinking program on Arduino.

-Signing Off, Arduino Novice

Please do follow my Blog and subscribe to my Youtube Channel for more demos and videos related to Arduino.

Advertisements

One thought on ““LED Blinking” Program on Arduino

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s