LEDs INTERFACED WITH ARDUINO

LED's interfaced with Arduino UNO

LED is the abbreviation for LIGHT EMITTING DIODE. It is a semiconductor light source that emits light when current flows through it. LEDs are the same as you will find them ideal for numerous applications like night lighting, art lighting and outdoor lighting.

LEDs convert electrical energy directly into light, delivering efficient light generation with little-wasted electricity. Many industries  are using LEDs because they are significantly more energy efficient as compared to the fluorescent lighting products. 

 

 

How does an LED Work?

Light emitting diode comes in different colors and each single LED consists of two pins, cathode and anode. Cathode pin carries positive charge and anode pin carries negative charge. These pins are differentiated by their height. Cathode pin is longer than anode which simplifies connecting the positive charge to the longer pin and negative charge/ground to the shorter pin.

LED pin out

How To Interface Arduino With LED?

Interface LED with the PWM (pulse width modulus) pins on Arduino. PWM pins on the Arduino UNO are identified as the pin numbers that have a tilde (~) sign with them. There is no need to add any resistor to the circuit if the LED is being connected to PWM pin. 

Connecting LED with Arduino UNO

Now that we have to complete the understanding on how the LED works, we can begin hooking it up with Arduino UNO. 

Requirements

  1. Arduino UNO
  2. LEDs
  3. Jumper wires (pin to pin)
  4. Resistor 1k ohm (if not using PWM pin)
  5. Bread board
  6. USB serial cable (for Arduino UNO)

Arduino

Interfacing LED is compatible with any Arduino Microcontroller board (Arduino NANO, UNO, or MEGA). LEDs require a minimal voltage to operate. On Arduino UNO, pin number thirteen (13) is a built-in LED pin. To program the Arduino microcontroller board, use the integrated development environment which can be downloaded from here.

Schematics

Follow the circuit diagram below and help yourself to operate a standalone LED. 

Single LED interfaced with arduino UNO

Arduino Code

With that you are ready to upload some code and get the LED working

//initializing pins

int LED1 = 11;

// the setup function begins, runs only once

void setup(){

         Serial.begin(9600);                // Begins the serial monitor

         pinMode(LED1, OUTPUT);   // Led1 set to output state

}                                                       // Setup function ends

// loop function begins, keeps on running again and again 

void loop(){

         digitalWrite(LED1, HIGH);   // Writing LED1 to state on

         delay(1000);                        // LED stays on for one second, delay provides time to wait for a defined time

         digitalWrite(LED1, LOW);  // Writing LED1 to state off

         delay(1000); 

}

Taking you miles ahead

Adding More LEDs

Add more LEDs to the circuit and help yourself understand how the code and circuit can be updated. 

Two LEDs interfaced with Arduino UNO

Arduino Code

Upload the code provided below for operating two LEDs one by one

//initializing pins

int LED1 = 11;

int LED2 = 10;

// the setup function begins, runs only once

void setup(){

         Serial.begin(9600);                // Begins the serial monitor

         pinMode(LED1, OUTPUT);   // Led1 set to output state

         pinMode(LED1, OUTPUT);   // Led2 set to output state

}                                                       // Setup function ends

// loop function begins, keeps on running again and again 

void loop(){

         digitalWrite(LED1, HIGH);   // Writing LED1 to state on

         delay(1000);                        // LED stays on for one second, delay provides time to wait for a defined time

         digitalWrite(LED1, LOW);  // Writing LED1 to state off

         delay(1000); 

         digitalWrite(LED2 HIGH);   // Writing LED2 to state on

         delay(1000);                        // LED stays on for one second, delay provides time to wait for a defined time

         digitalWrite(LED2, LOW);  // Writing LED2 to state off

         delay(1000); 

}

Taking you miles ahead

Blink in Direction - Forward and Reverse

Add one more LED to the circuit and help yourself understand how the code and circuit can be updated. 

Three LEDs interfaced with arduino UNO

Code

LEDs will blink from left to right first and then from right to left.  They will keep on performing the function till the time power is connected to the Arduino board. You can change delay values in the loop structure of the code below and then observe how fast and slow LEDs blink. Delay value can be anywhere from zero to the highest number. Delay is measured in microseconds and for one second the value in microsecond is 1000.  

int Ledpins[] ={9,10,11};  //array defining LED pins

 

void setup() {

  // put your setup code here, to run once:

  for (int i =0; i <4; i++)   // for loop starting

  {

    pinMode(Ledpins[i],OUTPUT);  Initializing the array for 

  }

}

 

void loop() {

  // put your main code here, to run repeatedly:

int i = 0;

while(i<6){

  digitalWrite(Ledpins[i],HIGH);

      delay(80);                                                     //change delay value

      digitalWrite(Ledpins[i],LOW);

      delay(80);                                                    //change delay value

      i++;

}

 

i = 4;

while(i>0){

  digitalWrite(Ledpins[i], HIGH);

  delay(80);                                                        //change delay value

  digitalWrite(Ledpins[i], LOW);

  delay(80);                                                      //change delay value

  i–;

}

}

Conclusion

You should observe your LED to turn on and off. If the required output is not seen, make sure that the circuit is assembled correctly along with the verification and uploading of the code to your Arduino board.