Turing ON/OFF an LED 💡

Updated: May 5, 2020



Know it

The LED is a tiny light bulb that you see in most devices around the house. LED is short for Light-Emitting Diode and it emits light as an electric current passes through.

The LED has two legs, the long read is the positive side and shorter leg is the negative side.



Wire it

Now we are going to make a circuit for the LED. You need a complete circuit for electricity to pass through. For that, you need the items below:

  • Breadboard and Jumper wires

  • 220Ω Resistor

  • 5mm LED

  • Arduino board and USB cable


















Connections:

  • Arduino pin GND LED Short leg

  • Arduino pin 13 Resistor (220Ω) LED long leg

Code it

This is a simple example sketch that turns on an LED for one second, off for one second, and repeats forever. Basically blinking an LED.


Try it out! Copy the code below:

/*   
  Turing ON/OFF an LED
  
  Tutorial link: https://www.learn.voltaat.com/post/led-blink
  
  This is a simple example sketch that turns on an LED 
  for one second, off for one second, and repeats forever.
  
  Components Needed:
  1. Led 5mm ...........x1
  2. 220ohm Resistor ...x1

 Connections:
  - Arduino pin GND → LED Short leg
  - Arduino pin 13  → Resistor (220Ω) → LED long leg
*/

int led = 13; // LED is connected to 13

// This routine runs only once upon reset
void setup()
{
  pinMode(led, OUTPUT); // Initialize 13 pin as output
}

// This routine loops forever
void loop()
{
  digitalWrite(led, HIGH);  // Turn ON the LED
  delay(1000);              // Wait for 1000mS = 1 second
  digitalWrite(led, LOW);   // Turn OFF the LED
  delay(1000);              // Wait for 1 second
}