Glow an LED

To glow an led we just need a DC power source and ground terminal here we connect led anode terminal (+) to pin number (digital IO) 13 so that if we program our code as pin number 13 as HIGH, it behaves as power source and Cathode terminal (–) of led to the ground terminal of Arduino so that the circuit will get complete. After doing this if we give power to Arduino then it will glows led (after programming MCU).

Required Hardware

S.No. Item Quantity
1. Arduino 1
2. Breadboard 1
3. LED 1
4. Resistor 220 ohm 1

Circuit Diagram

Programming Code

void setup( ) {
pinMode(13,OUTPUT);
}
void loop( ) {
digitalWrite(13,HIGH);
}

Code Explanation

In setup function we decide the mode of digital pins either as INPUT or OUTPUT. Let concentrates on output for now.
Function "pinMode( )" is used to define the pin working mode as an input/output.
In this function we have to pass two argument -
first one is pin number and
second is its mode, pinmode(pinNumber,mode).
In this we set pin number 13 as output: pinmode(13,OUTPUT).

Void setup( ) {
pinMode(13,OUTPUT);
}

In loop function we are using one inbuilt functions that is digitalWrite( ).
Function "digitalWrite( )" is used to instruct the controller/Arduino to set the state of particular digital pin as either LOW or HIGH.
In digitalWrite( ) function we also pass two argument -
first one is pin number and
second is its state, digitalWrite(pinNumber,state).
In this we set pin number 13 output as HIGH: digitalWrite(13,HIGH).

void loop( ) {
digitalWrite(13,HIGH);
}