An LED or light-emitting diode is a type of semiconductor that emits light when current flows through it. LEDs have polarity and only allow current flow in one direction from the anode (+) to cathode (-). LEDs have a specific forward voltage i.e. threshold voltage at which it will turn on. This value is typically between 1.8 and 3.3V depending upon the specific color chemistry. LEDs want to maintain and hold that forward voltage. If there is too much voltage across them or too much current flowing through them, they will blow. Typically, they only want 10-20 mA of current.
Series Resistor
In order to protect LEDs, we add a series resistor. The series resistors limit current by helping the LED maintain the forward voltage. How do we calculate resistor value? Hint: Use Ohm’s Law.
For 5V circuits, a 220 or 330 Ohm resistor is the most commonly used.
Drive an LED with a digital pin configured as an output. Use pinMode() in setup() to configure the pin as an output then use digitalWrite() to set the pin HIGH or LOW to turn the LED on or off.