How do I connect an LED? How does it work? What circuitry can I use it for? Introduction A light-emitting diode, or LED, is a component capable of emitting light when an electric current flows through it.Today, there are LEDs in different colors (red, green, blue, yellow, white) and even LEDs that can display several colors: red, blue and green, such as RGB LEDs. The LED only allows current to flow in one direction (from the anode to the cathode). The other direction is called the blocking direction. There are different types of LEDS:Low power LED: Quite low brightness but used for signaling on panels, traffic lights.Power LED: Used in maritime signaling as well as on permanent buoys.High power LED: Powerful to serve as main lighting in the automotive sector. Used primarily for position, stop, indicator or reversing lights, these will certainly eventually replace all incandescent lamps. Advantages of LED The energy consumption of LEDs is much lower than that of incandescent lamps.The LED can have a small size of around one pixel, which can be very useful for making a screen.The lifespan of LEDs is much longer than incandescent lamps. Disadvantages of LED The luminous efficiency of LEDs drops very quickly to only produce 20% of the initial quantity of light at the end of their life.So-called white LEDs are generally blue or UV emitting LEDs. LED electronic symbol The LED has a very particular symbol in an electronic circuit. It is symbolized by a triangle and a line. The line shows that the current only passes in one direction in the diode: from the anode to the cathode. How to connect an LED? The light-emitting diode is a very particular component: There is a blocking direction and a passing direction. The LED will only work if you connect the + voltage to the Anode and the – voltage to the Cathode. LED electronic symbol Do not connect the LED without resistance!As you can see from the voltage threshold table, the values are sometimes different from those that an Arduino card can deliver. As the Arduino card can only deliver 3.3V or 5V, it will be necessary to limit the current entering the LED in order to protect it. For this we will use a resistor. You have a demonstration of how to calculate its value in a circuit on our Resistance course.However, if you want to save yourself the details of the calculations, here are the resistors to choose in relation to the input voltage: a) Voltage of 3.3V If you plugged your sensor into the 3.3 volt port on your Arduino board, you will need a 220 ohm resistor a) Voltage of 5V If you plugged your sensor into the 5 volt port on your Arduino board, you will need a 1 kilo-ohm resistor. Lighting an LED on Arduino We will now see how to connect an LED. The circuit opposite will not allow you to control the LED (make it flash), but just to understand how to turn it on: Control the brightness of the LED with Arduino In this part we will control the LED in two forms: first by turning it on and off, then by gradually turning it on. Here is the circuit you will need for both parts: a) Turn your LED on and offHere is the code to turn an LED on and off. You can change the pin depending on where you plugged your LED into on the Arduino board: int led_Pin = 11; // We assign the LED to pin 11. void setup() { pinMode(led_Pin, OUTPUT); // We assign the LED as output } void loop() { digitalWrite(led_Pin,HIGH); // We turn on the LED delay(1000); // We pause to see the LED on before turning it off digitalWrite(led_Pin,LOW); // We turn off the LED delay(1000); } B) Control the brightness of the LEDWe will now see how to vary the brightness of the LED with the Arduino card. To do this, you will need to connect the LED to one of the PWM pins on the Arduino board. The Pulse Width Modulation pins allow you to “vary” the voltage of the arduino board with pulses. They are represented by “~”. Here is the diagram for varying the intensity of the LED: int led_Pin = 11; // We assign the LED to pin 11. float value; // Brightness value in percentage. void setup() { pinMode(led_Pin, OUTPUT); // We assign the LED as output } void loop() { for (int amount_counter = 0; amount_counter < 255; amount_counter++){ analogWrite(led_Pin, counter_amount); // We send the value to the LED delay(10); } for (int descending_counter = 255; descending_counter > 0; descending_counter--){ analogWrite(led_Pin, counter_down); // We send the value to the LED delay(10); } }