LED
Component | Light Emitting Diode (LED) |
Type | Output |
Function | Produce light |
Introduction
A Light Emitting Diode (LED) is a type of semiconductor diode that emits light when a current flows through it. LEDs are commonly used in electronic projects to provide visual feedback to the user. They are available in a variety of colors, and can be used to indicate the status of a system, provide illumination, or create visual effects.
When using an LED in a circuit, you must connect it to a current-limiting resistor to prevent it from drawing too much current and burning out. The value of the resistor depends on the forward voltage and forward current of the LED, and the supply voltage of the circuit.
Pin Description
An LED has two pins: an anode and a cathode. The anode is the positive pin, and the cathode is the negative pin. You connect the anode to a digital output pin on a microcontroller, and the cathode to a current-limiting resistor, which is then connected to the ground pin. When you apply a high signal to the anode, the LED emits light.
Code Example
The following code example demonstrates how to turn an LED on and off using a digital output pin on an Arduino board.
1 2 3 4 5 6 7 8 9 10 11 12 |
|
In this example, we use the digitalWrite
function to apply a high signal to the LED pin, causing the LED to emit light. We then wait for 1 second using the delay
function, and then apply a low signal to the LED pin to turn the LED off.