Led Interfacing with Arduino 

What is an LED?

The full form of LED is light-emitting diode. It is a small and Powerful light used in various applications.

Image And Symbol of LED:-


What is the current Sourcing?



When a device supplies current to a connected load, it is known as current sourcing. For example, when an LED and a resistor are connected between the microcontroller and ground, setting the pin logic (1) to turn on the LED and (0) to turn off the LED.

Circuit of Current Sourcing:-



What is the current Sinking?

Current sinking is when the power passes to the load and then to the object. Eg. When an LED and a resistor are connected between the power supply setting pin, logic that (0) turns on the LED and (1) turns off the LED.

Circuit of Current Sinking:-


Functions of LED Interfacing:-

1. pinMode( ):- Configures the specified pin to behave either as an Input or Output

Syntax:- pinMode(pin,mode);

Parameters:-

pin:- To which the object is connected on the Arduino Board.

Mode:- The device is used to take the input or output

2. digitalWrite( ):- It is used to turn on/off a component connected to Arduino. When set HIGH, it turns on, and when set to LOW, it turns off.

Syntax:- digitalWrite(pin,value);

Parameters:-

pin:- To which the object is connected on the Arduino Board.

value:- HIGH or LOW

3. delay( ):- It pauses the program for the amount of time in milliseconds.

Syntax:- delay(ms);

Parameters:-

ms:- To delay the program for milliseconds.

Task 1: Turn on the in-built LED of Arduino connected to pin no.13.

 Code:-

int led=13;
void setup()
{
  pinMode(led, OUTPUT);
}

void loop()
{
  digitalWrite(led, HIGH);

Output:-


Task 2: Blink LED using Arduino.

Code:-

int led=13;
void setup()
{
  pinMode(led, OUTPUT);
}

void loop()
{
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led, LOW);
  delay(1000);

Output:-



Task 3: Turn 5 LEDs in increasing order and turn them off in decreasing order.

Code:-
int led=13,led1=12,led2=11,led3=10,led4=9;
void setup()
{
  pinMode(led, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
}

void loop()
{
  digitalWrite(led, HIGH);
  delay(1000);
  digitalWrite(led1, HIGH);
  delay(1000);
  digitalWrite(led2, HIGH);
  delay(1000);
  digitalWrite(led3, HIGH);
  delay(1000);
  digitalWrite(led4, HIGH);
  delay(1000);
  digitalWrite(led4, LOW);
  delay(1000);
  digitalWrite(led3,LOW);
  delay(1000);
  digitalWrite(led2,LOW);
  delay(1000);
  digitalWrite(led1,LOW);
  delay(1000);
  digitalWrite(led,LOW);
  delay(1000);

Output:-