Module 2: Meet the Arduino — Your First Programmed Circuit
Level: 🟢 Beginner
Board: Arduino Uno
Prerequisites: Module 1
Estimated time: 2–3 hours
Goal: Understand the Arduino ecosystem, set up the IDE, and write your first sketch.
What You'll Learn
In Module 1, you built a circuit that does one thing forever: light up an LED. In this module, you'll add a brain — the Arduino Uno. By the end, you'll understand the board's anatomy, have the IDE installed, and write a sketch that blinks an LED on and off. More importantly, you'll calculate the resistor value yourself, because you already know how.
2.1 What Is a Microcontroller?
A microcontroller is a tiny computer on a single chip. It has a processor, memory, and input/output pins — everything needed to read sensors, make decisions, and control things like LEDs, motors, and displays.
The Arduino Uno uses the ATmega328P microcontroller. It's not powerful by computer standards (16 MHz clock, 32 KB of program memory, 2 KB of RAM), but it's more than enough to read a temperature sensor, drive a display, or control a robot arm. And unlike your laptop, it starts running your code the instant it gets power — no boot time, no operating system, no updates.
Why Arduino?
Arduino isn't just a board — it's an ecosystem. The Arduino project gives you three things:
- Standardized hardware — consistent pin layouts across boards, well-documented specifications
- The Arduino IDE — a simple code editor that handles compilation and uploading
- A simplified C/C++ framework — functions like
digitalWrite()anddelay()that hide the complex register-level code
This means you can focus on what you want the circuit to do, not on low-level chip programming. As you advance, you can always peel back the layers and work closer to the hardware.
2.2 Arduino Uno Board Anatomy
Get your Uno in front of you. Here's what you're looking at:
Power Section
| Pin/Connector | What it does |
|---|---|
| USB-B port | Connects to your computer. Provides 5V power AND data for uploading code |
| Barrel jack | Accepts 7–12V DC external power (center-positive) |
| VIN | Input voltage pin — same as barrel jack, but as a pin you can wire to |
| 5V | Outputs regulated 5V (from either USB or barrel jack). Use this to power components |
| 3.3V | Outputs regulated 3.3V (max 50 mA). For 3.3V sensors |
| GND | Ground pins (there are three). Connect all component grounds here |
Digital Pins (0–13)
- 14 digital pins that can be set as INPUT or OUTPUT
- Output: HIGH = 5V, LOW = 0V
- Input: reads HIGH or LOW
- Pins 0 and 1 are also Serial TX/RX — avoid using them for general I/O when you need Serial communication
- Pins with ~ (3, 5, 6, 9, 10, 11) support PWM (analogWrite) — more on this in Module 3
- Pin 13 has a built-in LED on the board itself
Analog Pins (A0–A5)
- 6 analog input pins
- Read voltages between 0V and 5V
- Return a value from 0 (0V) to 1023 (5V) — 10-bit resolution
- Can also be used as digital pins if needed
Other Important Parts
| Part | Purpose |
|---|---|
| Reset button | Restarts your sketch from the beginning |
| TX/RX LEDs | Blink when data is being sent/received over USB |
| Power LED (ON) | Indicates the board has power |
| Pin 13 LED (L) | Built-in LED connected to digital pin 13 |
| ATmega328P chip | The microcontroller — the brain |
| Voltage regulator | Converts barrel jack/VIN voltage down to 5V |
| Crystal oscillator | The 16 MHz clock that keeps everything in sync |
| ICSP header | For advanced programming (you won't need this yet) |
How the Uno Gets Power
The Uno can be powered three ways:
- USB cable — provides 5V directly. Simplest option during development.
- Barrel jack — accepts 7–12V. The onboard voltage regulator steps it down to 5V. Recommended: 9V. Don't exceed 12V or the regulator overheats.
- VIN pin — same as barrel jack but via a wire. Same voltage rules apply.
Important: When both USB and barrel jack are connected, the Uno automatically selects the higher voltage source (barrel jack). The USB 5V line is protected by a diode so it won't back-feed your computer.
From Module 1: The voltage regulator converts excess voltage into heat. That's why 7V works fine (only 2V to burn off) but 20V would be dangerous (15V × current = lots of heat).
2.3 The Breadboard — Your Prototyping Surface
You used a breadboard in Module 1. Let's make sure you understand the internal connections thoroughly, because wiring mistakes are the #1 cause of "my circuit doesn't work."
Internal Connections
A standard breadboard has:
Terminal strips (the main area):
- Rows labeled 1–30 (or 1–63 on full-size boards)
- Columns labeled a–e and f–j
- Within each row: a–e are connected together, and f–j are connected together
- The center gap separates the two halves — a–e and f–j are NOT connected to each other
- Each row is independent from other rows
Power rails (the long strips on the sides):
- Marked with + (red) and − (blue)
- All holes in a + rail are connected together
- All holes in a − rail are connected together
- On full-size boards, some power rails have a break in the middle — verify with your multimeter's continuity test
Common Wiring Mistakes
- Two components in the same row when they shouldn't be — this creates an unintended connection
- Components spanning the wrong gap — ICs go across the center gap so each pin gets its own row
- Power rail break — on some boards, the + and − rails aren't continuous. Check with continuity
- Loose connections — if a wire isn't pushed in firmly, it may look connected but isn't
Debugging tip: When something doesn't work, check every connection with the continuity tester before questioning your code or circuit design.
2.4 Installing the Arduino IDE
Step 1: Download
Go to arduino.cc/en/software and download the Arduino IDE 2.x for your operating system.
Step 2: Install
Follow the installer. On Windows, allow the USB driver installation when prompted — this is what lets your computer talk to the Uno.
Step 3: Connect Your Uno
- Plug the USB-B cable into the Uno and into your computer
- The green power LED on the Uno should light up
- If the Uno came with a pre-loaded Blink sketch, the pin 13 LED will be blinking
Step 4: Configure the IDE
- Open the Arduino IDE
- Go to Tools → Board and select Arduino Uno
- Go to Tools → Port and select the port that appeared when you plugged in the Uno
- Windows: COM3, COM4, etc.
- Mac:
/dev/cu.usbmodem... - Linux:
/dev/ttyACM0or/dev/ttyUSB0
If no port appears, check your USB cable — some cables are charge-only and don't carry data. Try a different cable.
Step 5: Test the Connection
Click the Upload button (right arrow icon) with the default empty sketch. If it uploads without errors, your connection is working.
2.5 Your First Sketch: Understanding Blink
Every Arduino sketch has two required functions:
void setup() {
// Runs once when the board powers on or resets
}
void loop() {
// Runs repeatedly, forever, after setup() completes
}
This is the structure of every Arduino program. setup() initializes things (pin modes, serial communication, libraries). loop() is where the action happens — it runs your code over and over, hundreds or thousands of times per second.
The Blink Sketch — Annotated
/*
* Module 2: Blink
* Turns an LED on for one second, then off for one second, repeatedly.
*
* Circuit:
* - LED anode → 220Ω resistor → digital pin 8
* - LED cathode → GND
*
* Board: Arduino Uno
*/
// Define which pin the LED is connected to.
// Using a named constant makes the code readable and easy to change.
const int LED_PIN = 8;
void setup() {
// Configure LED_PIN as an output.
// This tells the Arduino to drive this pin HIGH (5V) or LOW (0V).
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// Turn the LED on by setting the pin to HIGH (5V)
digitalWrite(LED_PIN, HIGH);
// Wait for 1000 milliseconds (1 second)
delay(1000);
// Turn the LED off by setting the pin to LOW (0V)
digitalWrite(LED_PIN, LOW);
// Wait for 1000 milliseconds (1 second)
delay(1000);
// After this, loop() runs again from the top — so the LED blinks forever
}
Key Functions Explained
pinMode(pin, mode)
Configures a pin as INPUT or OUTPUT. You must call this in setup() before using the pin.
OUTPUT: The pin will drive HIGH (5V) or LOW (0V)INPUT: The pin will read voltages (more on this in Module 3)
digitalWrite(pin, value)
Sets an output pin to HIGH (5V) or LOW (0V).
HIGH: Pin outputs 5V — current flows out of the pin through your circuitLOW: Pin outputs 0V — effectively connected to ground
delay(milliseconds)
Pauses the program for the specified number of milliseconds.
delay(1000)= 1 seconddelay(500)= half a seconddelay(100)= 0.1 seconds
Important note about
delay(): While the Arduino is in adelay(), it does nothing else. It can't read buttons, can't update displays, can't respond to sensors. For Module 2, this is fine. In later modules, you'll learn non-blocking timing withmillis()that lets the Arduino multitask.
2.6 Why the Resistor Value Matters — Again
Let's apply Module 1's calculations to this circuit.
Given:
- Arduino output pin: 5V when HIGH
- Red LED: Vf = 2.0V, If = 20 mA
- Arduino pin max current: 40 mA (but recommended max is 20 mA)
Calculation:
V_resistor = 5V - 2.0V = 3.0V
R = 3.0V / 0.020A = 150Ω
Standard value: 150Ω works, or use 220Ω for extra safety margin (the LED will be slightly dimmer but well within safe operating range).
What happens without a resistor?
The LED has very low resistance when forward-biased. Without a current-limiting resistor, the current would spike far above 20 mA. This could:
- Burn out the LED immediately
- Damage the Arduino's output pin
- Or both
From Module 1: This is Ohm's Law in action. Low resistance + constant voltage = high current. The resistor is the brake pedal.
What if you use too large a resistor?
With a 10kΩ resistor:
I = 3.0V / 10000Ω = 0.3 mA
The LED might glow very faintly or not at all. Safe, but not useful. Finding the right resistor is about balance — enough to protect, not so much that it starves the component.
Module Project: Blinking LED with External Resistor
Objective
Wire an external LED to the Arduino, calculate the correct resistor, upload the Blink sketch, and verify the circuit works.
Components Needed
| Component | Quantity | Notes |
|---|---|---|
| Arduino Uno | 1 | |
| USB-B cable | 1 | Data-capable (not charge-only) |
| Breadboard | 1 | |
| 5mm Red LED | 1 | |
| 220Ω Resistor | 1 | (Red-Red-Brown-Gold) |
| Jumper wires | 2 | Male-to-male |
Wiring Steps
Step 1: Place the LED on the breadboard.
- Anode (long leg) into row 20, column E
- Cathode (short leg) into row 21, column E
Step 2: Place the 220Ω resistor.
- One leg into row 20, column A (same row as LED anode)
- Other leg into row 15, column A
Step 3: Connect the Arduino.
- Jumper wire from row 15, column B → Arduino digital pin 8
- Jumper wire from row 21, column A (LED cathode row) → Arduino GND
Step 4: Upload the sketch.
- Open the Arduino IDE
- Copy the Blink sketch from section 2.5
- Click Upload (right arrow)
- Wait for "Done uploading" message
Step 5: Observe.
- The LED should blink: 1 second on, 1 second off
Circuit Diagram
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 700 350" font-family="monospace" font-size="12">
<!-- Arduino Uno (simplified) -->
<rect x="50" y="50" width="180" height="260" fill="#1a7a8a" stroke="#333" stroke-width="2" rx="8"/>
<text x="140" y="80" text-anchor="middle" fill="white" font-size="16" font-weight="bold">Arduino</text>
<text x="140" y="100" text-anchor="middle" fill="white" font-size="14">Uno</text>
<!-- USB Port -->
<rect x="110" y="40" width="60" height="20" fill="#888" stroke="#333" stroke-width="2" rx="3"/>
<text x="140" y="55" text-anchor="middle" font-size="9" fill="white">USB</text>
<!-- Pin labels on Arduino -->
<rect x="230" y="130" width="30" height="18" fill="#2a8a9a" stroke="white" stroke-width="1" rx="2"/>
<text x="245" y="143" text-anchor="middle" fill="white" font-size="10">D8</text>
<rect x="230" y="260" width="30" height="18" fill="#2a8a9a" stroke="white" stroke-width="1" rx="2"/>
<text x="245" y="273" text-anchor="middle" fill="white" font-size="10">GND</text>
<!-- Wire from D8 to resistor -->
<line x1="260" y1="139" x2="350" y2="139" stroke="orange" stroke-width="2"/>
<!-- Resistor -->
<rect x="350" y="129" width="80" height="20" fill="none" stroke="#333" stroke-width="2" rx="3"/>
<text x="390" y="144" text-anchor="middle" font-size="11">220Ω</text>
<!-- Wire from resistor to LED -->
<line x1="430" y1="139" x2="500" y2="139" stroke="orange" stroke-width="2"/>
<!-- LED -->
<polygon points="500,119 500,159 540,139" fill="none" stroke="red" stroke-width="2"/>
<line x1="540" y1="119" x2="540" y2="159" stroke="red" stroke-width="2"/>
<text x="520" y="110" text-anchor="middle" font-size="11" fill="red">LED</text>
<!-- Wire from LED cathode back to GND -->
<line x1="540" y1="139" x2="600" y2="139" stroke="black" stroke-width="2"/>
<line x1="600" y1="139" x2="600" y2="269" stroke="black" stroke-width="2"/>
<line x1="600" y1="269" x2="260" y2="269" stroke="black" stroke-width="2"/>
<!-- Labels -->
<text x="305" y="130" text-anchor="middle" font-size="10" fill="#666">Pin 8 (HIGH=5V)</text>
<text x="390" y="170" text-anchor="middle" font-size="10" fill="#0066cc">3.0V drop</text>
<text x="520" y="175" text-anchor="middle" font-size="10" fill="red">2.0V drop</text>
</svg>
Circuit Schema (JSON)
{
"module": 2,
"project": "Blinking LED",
"board": "Arduino Uno",
"schematic": {
"components": [
{
"id": "U1",
"type": "arduino_uno",
"pins_used": {
"D8": "net_d8_out",
"GND": "net_gnd",
"USB": "power_and_programming"
}
},
{
"id": "R1",
"type": "resistor",
"value": "220",
"unit": "ohm",
"power_rating": "0.25W",
"color_code": ["red", "red", "brown", "gold"],
"pins": {
"pin1": "net_d8_out",
"pin2": "net_r1_led"
}
},
{
"id": "LED1",
"type": "led",
"color": "red",
"forward_voltage": 2.0,
"forward_current_ma": 20,
"pins": {
"anode": "net_r1_led",
"cathode": "net_gnd"
}
}
],
"nets": [
{
"name": "net_d8_out",
"description": "Arduino pin 8 output to resistor",
"nodes": ["U1.D8", "R1.pin1"]
},
{
"name": "net_r1_led",
"description": "Resistor to LED anode",
"nodes": ["R1.pin2", "LED1.anode"]
},
{
"name": "net_gnd",
"description": "Ground rail",
"nodes": ["U1.GND", "LED1.cathode"]
}
],
"power": {
"source": "USB",
"board_voltage": 5.0,
"pin_output_voltage": 5.0,
"total_current_ma": 20
}
},
"breadboard": {
"connections": [
{
"step": 1,
"instruction": "Place LED: anode (long leg) into row 20 column E, cathode (short leg) into row 21 column E",
"component": "LED1"
},
{
"step": 2,
"instruction": "Place 220Ω resistor: one leg into row 20 column A, other leg into row 15 column A",
"component": "R1"
},
{
"step": 3,
"instruction": "Jumper wire (orange) from row 15 column B to Arduino digital pin 8",
"type": "wire",
"color": "orange"
},
{
"step": 4,
"instruction": "Jumper wire (black) from row 21 column A to Arduino GND pin",
"type": "wire",
"color": "black"
}
]
},
"code": {
"filename": "module02_blink.ino",
"language": "cpp"
},
"validation": {
"expected_behavior": "LED blinks: 1 second ON, 1 second OFF",
"measurements": {
"voltage_pin8_high": { "min": 4.8, "max": 5.2, "unit": "V" },
"voltage_pin8_low": { "min": -0.1, "max": 0.2, "unit": "V" },
"voltage_across_led": { "min": 1.8, "max": 2.2, "unit": "V" },
"current_through_led": { "min": 12, "max": 22, "unit": "mA" }
},
"common_mistakes": [
"LED not lighting: check LED polarity (long leg = anode = toward resistor)",
"LED always on: check that pin number in code matches wired pin",
"Upload error: verify correct board and port selected in IDE",
"No port available: try a different USB cable (must be data-capable)",
"Resistor in wrong row: verify with multimeter continuity test"
]
}
}
Experiments to Try
Once your Blink sketch is working, try these modifications to build your intuition:
Experiment 1: Change the Timing
// Fast blink
delay(100); // 0.1 seconds — LED flickers rapidly
// Slow blink
delay(3000); // 3 seconds — leisurely blink
// Asymmetric blink
digitalWrite(LED_PIN, HIGH);
delay(200); // Short flash
digitalWrite(LED_PIN, LOW);
delay(1800); // Long pause
Experiment 2: Multiple LEDs
Add a second LED on pin 9 with its own resistor. Modify the code:
const int LED_PIN_1 = 8;
const int LED_PIN_2 = 9;
void setup() {
pinMode(LED_PIN_1, OUTPUT);
pinMode(LED_PIN_2, OUTPUT);
}
void loop() {
// Alternating blink
digitalWrite(LED_PIN_1, HIGH);
digitalWrite(LED_PIN_2, LOW);
delay(500);
digitalWrite(LED_PIN_1, LOW);
digitalWrite(LED_PIN_2, HIGH);
delay(500);
}
Experiment 3: SOS in Morse Code
const int LED_PIN = 8;
const int DOT = 200;
const int DASH = 600;
const int SYMBOL_GAP = 200;
const int LETTER_GAP = 600;
const int WORD_GAP = 1400;
void flash(int duration) {
digitalWrite(LED_PIN, HIGH);
delay(duration);
digitalWrite(LED_PIN, LOW);
delay(SYMBOL_GAP);
}
void setup() {
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// S: ...
flash(DOT); flash(DOT); flash(DOT);
delay(LETTER_GAP);
// O: ---
flash(DASH); flash(DASH); flash(DASH);
delay(LETTER_GAP);
// S: ...
flash(DOT); flash(DOT); flash(DOT);
delay(WORD_GAP);
}
Self-Check: Module 2
Before moving to Module 3, make sure you can:
- Identify the main sections of the Arduino Uno board
- Explain the three ways to power the Uno and when each is appropriate
- Describe the breadboard's internal connections
- Install the Arduino IDE, select the correct board and port, and upload a sketch
- Explain what
setup()andloop()do - Use
pinMode(),digitalWrite(), anddelay()correctly - Calculate the correct resistor for an LED on a 5V Arduino pin
- Modify the Blink sketch to change timing or add LEDs
Key Terms Glossary
| Term | Definition |
|---|---|
| Microcontroller | A small computer on a single chip with processor, memory, and I/O |
| Sketch | Arduino's name for a program |
| setup() | Function that runs once at startup — used for initialization |
| loop() | Function that runs repeatedly after setup — the main program logic |
| pinMode() | Configures a pin as INPUT or OUTPUT |
| digitalWrite() | Sets an output pin to HIGH (5V) or LOW (0V) |
| delay() | Pauses execution for a specified number of milliseconds |
| HIGH / LOW | Logic levels — HIGH = 5V (on), LOW = 0V (off) |
| IDE | Integrated Development Environment — the software for writing and uploading code |
| PWM | Pulse Width Modulation — simulating analog output (covered in Module 3) |
Previous: ← Module 1 — Electricity Fundamentals Next: Module 3 — Inputs & Outputs: Talking to the Physical World →