This tutorial is for the beginners who have just bought a arduino and want to start using it. Just like while learning programming we start with a simple program of Hello World!, in embedded systems we start by blinking an led. Before we start i want to give a brief introduction of how a arduino program or sketch looks like? For writing and uploading sketch to arduino you will need arduino IDE which can be downloaded from here
Arduino Sketch:
Every arduino program also called as sketch has 2 parts:
- Initialization Part : Where we define things and initialize any arduino peripheral like Serial or USB Connection and Input / Output Port.
- Infinite Loop : After initialization is complete there is a infinite loop in which arduino runs till it is not reset or switched off.
Code for Blinking Led:
Some Explanation of Code:
The two parts discussed above are implemented in code as setup() function and loop() function. In arduino led is connected to pin number 13 so we name a variable ledPin for our convenience.
The setup() block runs only once and initializes all the peripherals and assignments. Then the pinMode(pinNumber, direction) function assigns the mode of pin, (in our case pin number 13 or ledPin) as OUTPUT, because we want to output high or low voltage level so that our led lights up. If you are reading the voltage level of the pin then you have to choose the direction as INPUT.
Now, the loop() function block, this block runs continuously till the reset or power off of the board. In this block there are two functions digitalWrite(pinNumber, Value) and delay(milliseconds). digitalWrite(pinNumber, Value) writes value (either LOW or HIGH) to the pinNumber and delay(milliseconds) is used to give accurate time delays between any two sequence of instruction.
Now upload this code using Arduino IDE to Arduino Board and you will see the led light blinking at an interval of 1sec.