.. note::
Hello, welcome to the SunFounder Raspberry Pi & Arduino & ESP32 Enthusiasts Community on Facebook! Dive deeper into Raspberry Pi, Arduino, and ESP32 with fellow enthusiasts.
**Why Join?**
- **Expert Support**: Solve post-sale issues and technical challenges with help from our community and team.
- **Learn & Share**: Exchange tips and tutorials to enhance your skills.
- **Exclusive Previews**: Get early access to new product announcements and sneak peeks.
- **Special Discounts**: Enjoy exclusive discounts on our newest products.
- **Festive Promotions and Giveaways**: Take part in giveaways and holiday promotions.
👉 Ready to explore and create with us? Click [|link_sf_facebook|] and join today!
.. _ar_led:
2.2 LED
=========
Overview
--------
In this lesson, you will learn how to use LED. LED is a kind of common
light-emitting device that works according to the principle that the
recombination of electron and hole releases energy to give out light.
This component is used widely in the current society, such as
illumination, panel display, medical device and so on.
Components Required
-------------------
.. image:: img/list_2.2.png
* :ref:`cpn_mega2560`
* :ref:`cpn_breadboard`
* :ref:`cpn_wires`
* :ref:`cpn_led`
* :ref:`cpn_resistor`
Schematic Diagram
-----------------
.. image:: img/image401.png
Fritzing Circuit
----------------
In this example, we use pin 9 to drive LED. Insert one side of the
resistor in the digital pin 9 and connect the longer pin (a positive
electrode, referred to as anode) of the LED with the other side of the
resistor. Extend the shorter pin (a negative electrode, referred to as
cathode) of the LED to GND.
.. image:: img/image30.png
Code
----
.. note::
* You can open the file ``2.2_led.ino`` under the path of ``sunfounder_vincent_kit_for_arduino\code\2.2_led`` directly.
* Or copy this code into Arduino IDE.
**Example 1:**
.. raw:: html
Finished uploading the codes to the Mega2560 board, you can see the LED flashing. Refer to :ref:`ar_digital_write` to check the detail code explanation.
**Example 2:**
.. note::
* You can open the file ``2.2_led_2.ino`` under the path of ``sunfounder_vincent_kit_for_arduino\code\2.2_led_2`` directly.
* Or copy this code into Arduino IDE.
.. raw:: html
After uploading the codes to the Mega2560 board, you can see the LED
getting brighter, then turning off, getting brighter, then turning off
again...this loop will continue in this way. About the detail code
explanation, please refer to :ref:`ar_analog_write`.
Phenomenon Picture
------------------
.. image:: img/image36.jpeg