So guys the time has came when you will make your first project in this Series on IoT. In this project we will be blinking the LED with the help of Arduino UNO board. If you have covered my article Introduction to Arduino IDE | The Complete guide to Internet of Things then you are good to go if not then please go and have a look at it so that there will be no difficulty in your first project of Blinking a LED using Arduino. Blinking the LED is the first step towards the programming of IoT devices and also in learning of Arduino.
And after you have connected your Arduino Uno, the Port option will be active select the required COM port showing the Arduino board.
Now hit that upload button to compile the code and the upload to your board.
I will guide throughout this project if you find any difficulty fee free to ask in the comments below. So if you are ready then lets head into our first project.
Step 1: Things That You Will Need ??
- 1 Arduino UNO Board (if you are planning to buy it, purchase the Arduino along with its USB cable)
- 1 Arduino USB Cable ( USB a/b Cable)
- 1 Resistor 1K Ohm
- 1 Led
- 2 Jumper Wires(optional)
- 1 Bread Board(optional)
Step 2: The Circuit Diagram
Step 3: The Code
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin LED_BUILTIN(pin 13) as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Copy the above code and paste it in your Arduino IDE new sketch
or you can find the same code in Arduino Builtin Examples jut follow this File > Examples > Basics > Blink
After opening the example remove the top comments to get the same code as given above. Do you remember what comments in code do ?
Now after removing the top comment lines if you have got the same code can we continue?
Step 4: The Explanation
Do not get scared with these code they are very simple let me explain you line by line each and every function.
So you already know that every Arduino code have setup and loop part which we already have discussed let e explain once more
Code Snippet:
void setup() {
//this is setup part of the code, this part runs only once when the Arduino boot up when you connect your power source or press the reset button the board
}
Explanation : The above block is for setup part we put the part of our code which has to be run only once. Like setting which pin will be output which will be input and some other task.
Code Snippet:
void loop() {
//this is loop part of the code, this part runs over and over again infinitely until you turn off the power of Arduino board
}
Explanation : The above block is for loop part we put the part of our code which has to be run forever until there is power. This part contains functions and codes that will take input and give output to different devices like LED, Motors, Display etc.
Code Snippet:
void setup() {
// initialize digital pin LED_BUILTIN(pin 13) as an output.
pinMode(LED_BUILTIN, OUTPUT);
}
Explanation : The above block is for setup part we put the part of our code which has to be run only once. So here we are putting a function which will make the LED_BUILTIN pin (or pin 13 of Arduino) as output. See the function to make this pin as output i.e pinMode(LED_BUILTIN,OUTPUT); with this function we can make any digital pin as output like pinMode(10,OUTPUT); since the Arduino code is case sensitive so you must write the exact way it is shown here the capitals and the smalls you have to take care. Similarly you can make any pin as output, here we have used LED_BUILTIN in place of 13 because Arduino compiler know the meaning of this constant, yes this keyword LED_BUILTIN is a constant you can make yourself too. We will learn the same in upcoming article.
Code Snippet:
void loop() {
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(LED_BUILTIN, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Explanation : The above block is for loop part we put the part of our code which has to be run forever until there is power. So here we are putting a piece of code that will make a { LED turn ON then wait 1 second in ON position and turn OFF then wait in OFF position} this process in curl bracket will continue to run forever until we remove the power source or change the code in the board. This piece of code inside loop part when run forever will give the feeling of blinking the LED. If the code have not been put in loop part it would have turn On the LED then turn Off it that’s it. but we don’t want this we want to blink forever so we have to put the code in loop block.
Here in this block we have three new function for you let me describe each one for you.
Code Snippet:
digitalWrite(LED_BUILTIN, HIGH);
Explanation : The above function will make the LED_BUILTIN pin (pin 13) HIGH or you can say it will send 5v to that pin. Now when LED’s positive terminal is connected to this point then this will turn ON the LED. This function can also be Re Written as digitalWrite(13, HIGH); or digitalWrite(13, 1); yes we can write 1 in place of HIGH and 0 in place of LOW
Code Snippet:
digitalWrite(LED_BUILTIN, LOW);
Explanation : The above function will make the LED_BUILTIN pin (pin 13) LOW or you can say it will send 0v to that pin. Now when LED’s positive terminal is connected to this point then this will turn OFF the LED. This function can also be Re Written as digitalWrite(13, LOW); or digitalWrite(13, 0); yes we can write 0 in place of LOW.
Code Snippet:
delay(1000);
Explanation : The above function will make Arduino board to delay for 1000 milliseconds or 1 Second. By delay we means that the current state of Arduino will stay same for 1 second or if the LED is in ON position then with delay(1000); it will keep the led in ON position for 1 second and if it in OFF position the with delay(1000); it will keep led in OFF position for 1 second. We are using delay here because Arduino runs at 8MHz Hence the loop part will be repeated very fast so we must use delay to visualize the blinking. If you don’t put delay you will see the LED at its half brightness.(sometimes less)
Step 4: Upload the Code to Arduino
Connect your Arduino Uno to your Laptop, Now in the Arduino IDE go to Tools > Board > Select Arduino Uno
And after you have connected your Arduino Uno, the Port option will be active select the required COM port showing the Arduino board.
Now hit that upload button to compile the code and the upload to your board.
If the code is correct you will get no error and your code will upload to the board and you will see a message of successful upload in the message area.
1.
2.
3.
On Successful Uploading of code your Arduino RX TX led will blink like this (only 2 time). It means you have successfully uploaded the code.
Now you will see something like this. Congratulation you DID It!
Now let’s extend it with our own LED. Insert positive terminal of the LED into pin 13 hole and negative terminal into Ground hole side to the pin 13.
REMEMBER to use register in series with the LED like this
After doing this you will see something like this
Now if you want to test this blinking of led with other pin then I will recommend to use breadboard or you can directly insert into the pin.
Remember to change the code and re-upload in a similar manner as done above.
Example code to blink led connected to pin 10 of Arduino
// the setup function runs once when you press reset or power the board
void setup() {
// initialize digital pin 10 as an output.
pinMode(10, OUTPUT);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(10, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(10, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
Also you can decrease the number inside delay(); function to blink the LED faster. This will we your task, try it yourself and comment down the code to blink faster. Do not put zero in delay, you will not be able to see when it is turning off and when turning on because human eye can’t see so fast frame rate like camera can see. Because Arduino runs at 8MHz Hence the loop part will repeat very fast so we must use delay to visualize the blinking.
This is Task to Blink LED FAST like this experiment and learn yourself.
So today in this article we coded our first Arduino project, uploaded it and tested also. In our upcoming articles you will be blinking rows of LED’s so stay tuned, keep visiting
How did you like this post. Was it informative, Did you understood all the points, What problem you faced during reading this article. Do you have any doubts or any query…
Comment Down each and everything I am eager to hear from you.
In the next article you will be blinking rows of LED’s. Till then KEEP LEARNING












0 Comments
We are friendly, helpful and available. Reach out to us anytime and we will happily answer your quires. SEND US A MESSAGE OR FEEDBACK
Emoji