Arduino - LED - Blink
This is a compact build guide. The full tutorial, with the wiring diagram and a line-by-line walkthrough of the code, is here: https://arduinogetstarted.com/tutorials/arduino-led-blink
This project turns an LED on and off with an Arduino Uno, first using the board's built-in LED, then an external LED wired to a digital pin. It is the basic building block for controlling any on/off device from code, from a single indicator light to a relay driving bigger machines.
Supplies
Everything below is what the build uses. The links go to the parts we make and test.
- Official Arduino Uno
- DIYables STEM V3, Fully Compatible with Arduino Uno R3
- USB 2.0 cable type A/B (for USB-A PC)
- USB 2.0 cable type C/B (for USB-C PC)
- LED Kit
- LED (red)
- LED Module
- Button and LED Kit
- 220Ω Resistor
- Breadboard
- Jumper Wires
- Screw Terminal Block Shield for Arduino Uno
- Sensors/Servo Expansion Shield for Arduino Uno
- Breadboard Shield for Arduino Uno
- Enclosure for Arduino Uno
- Prototyping Base Plate & Breadboard Kit for Arduino UNO
- DIYables STEM V3 Starter Kit (Arduino included)
- DIYables Sensor Kit (18 sensors/displays)
Wiring
The LED has two pins: cathode (-) and anode (+). Connect the cathode to GND. Connect the anode, through a 220 ohm resistor, to an Arduino digital pin such as pin 9. Using the LED Module with a built-in resistor simplifies this, since you only need to run two wires. The first example needs no external wiring at all, since it uses the Uno's built-in LED.
How It Works
A pin set to digital output mode can be driven to GND or to VCC by code. With the cathode tied to GND, driving the anode to GND turns the LED off, and driving it to VCC turns the LED on. Sending a PWM signal instead of a fixed HIGH/LOW would let you change the brightness, but this project only switches the LED fully on or off.
Code
The sketch sets a pin to OUTPUT with pinMode(), then uses digitalWrite() to alternate the pin between LOW and HIGH, with delay() pausing between each state. The first version toggles LED_BUILTIN every 1000 ms. For the external LED, change LED_BUILTIN to 9 and shorten the delay to 500 ms, which makes the LED blink faster.
arduino-led-blink.ino - the sketch from the tutorial, unchanged.
Things That Go Wrong
If the LED never lights, check that the cathode goes to GND and the anode goes to the pin through the resistor; a reversed LED won't light. If you changed the pin number in code, make sure the wiring uses that same pin. Make sure the correct board and port are selected in the Arduino IDE before uploading.
Full Tutorial
The complete tutorial, wiring diagram and code explanation: https://arduinogetstarted.com/tutorials/arduino-led-blink