๐Ÿ”ด Unit 1: Turn On the Red LED

๐Ÿง  What You Will Learn

In this unit, you will learn how to turn on an LED using code. Along the way, youโ€™ll understand what an output is, and learn two important commands:


๐ŸŽฏ Objective

By the end of this unit, you will be able to:


๐Ÿงฉ Used Component

๐Ÿ› ๏ธ Step-by-Step Instructions

โœ… Step 1: Open the Arduino IDE

Connect your Waliduino via USB and launch the Arduino IDE.

โœ… Step 2: Create a new sketch

Delete any existing code and enter the following:

void setup() {
    pinMode(11, OUTPUT);
    digitalWrite(11, HIGH);  
}
void loop() {
} 

โœ… Step 3: Ensure your board and port are correct

โœ… Step 4: Upload the sketch

Click the Upload button (โ†’).
If everything is correct, the red LED turns on! ๐Ÿ”ด

๐Ÿ’กLetโ€™s break this sketch down step by step:


๐Ÿ› ๏ธ pinMode(11, OUTPUT);

This line tells the Arduino that pin 11 will be used as an output.
That means the pin is prepared to control something, like an LED.


โšก digitalWrite(11, HIGH);

This line sets pin 11 to 5 volts (HIGH).
Since the red LED is connected to that pin, the voltage makes the LED light up.


๐Ÿง  Why is the code only in setup()?

We only want the LED to turn on once, right when the program starts.
The setup() function runs only one time, so itโ€™s perfect for actions that donโ€™t need to be repeated.


๐Ÿ” What does loop() do here?

Nothing โ€” itโ€™s empty for now.
But it must still be included, because every Arduino sketch requires both setup() and loop().


๐Ÿ”ฃ What are the { } braces for?

Curly braces { } group instructions that belong together.
All the code inside setup() goes between its braces, and the same for loop().


๐Ÿ”š Why do we need semicolons ;?

Each command in Arduino must end with a semicolon ;.
It tells the Arduino: โ€œThis line is complete.โ€
โ— Forgetting a semicolon will cause an error when you try to upload your sketch.


๐Ÿ”Œ How the LED is wired and why we use a Resistor

When you turn on an LED with the Arduino, youโ€™re actually creating a small electrical circuit. Hereโ€™s how itโ€™s connected:

โžก๏ธ Arduino Pin โ†’ Resistor โ†’ LED โ†’ GND (Ground)

Letโ€™s break this down:

๐Ÿ”ด 1. The Arduino Pin

When you use digitalWrite(11, HIGH), the Arduino pin sends out 5 volts โ€” like turning on a tiny switch that allows current to flow.

๐Ÿงฑ 2. The Resistor

Before the current reaches the LED, it flows through a resistor (typically 220 or 330 ohms).

๐Ÿ‘‰ Why do we need it?
Without the resistor, too much current would flow into the LED โ€” which can burn it out or damage the Arduino. The resistor slows down the current to a safe level.

๐Ÿ’ก 3. The LED

After passing through the resistor, the current reaches the LED, making it light up.


๐Ÿ“˜ New Terms


What We Have Learned