Lesson 02: Beyond the Board — External LEDs, Breadboards, and Your First Circuit
Robotics from Scratch · Lesson 02 · Beginner · ~15 min read · Updated April 2026
The Physical World Just Opened Up
Last lesson you blinked a light that was already on the board. You did not wire anything. You did not build a circuit. You told a pin to go high and a pre-installed LED responded.
Now we do it ourselves.
In the next twenty minutes you will wire an LED to a breadboard, connect it to your ESP32 with your own hands, and write code that controls it. You will understand what current means, why resistors exist, and why the LED only works in one direction.
This is the foundation of every circuit you will ever build. Motors, sensors, buzzers — it is all the same pattern. Open the circuit, something happens. Close it, something else happens. You are about to own that pattern.
What a Breadboard Is and Why It Exists
A breadboard is a reusable prototyping board. The word "bread" is literal — people used to build circuits on top of wooden cutting boards in their kitchens. The board has a grid of holes, and underneath those holes are metal clips that connect certain holes to each other.
Watch: VIDEO PLACEHOLDER — A breadboard walkthrough video will appear here once the CryptoTavern YouTube channel is set up.
Try it yourself:
The two outer rails on each side typically run the full length of the board and are used for power and ground. You connect your ESP32's 3.3V to one rail and GND to the other, and every row on that rail has access to power or ground.
This is why breadboards exist: you can build a circuit in seconds, change it in seconds more, and take it apart without destroying anything. For prototyping, it is the fastest tool available.
What You Need
For this lesson you need everything from Lesson 01 plus:
- A breadboard — any half-size or full-size breadboard will work. They cost around $5-8.
- An LED — any color. Standard 5mm through-hole LEDs work perfectly. A pack of 100 is under $3.
- A 330 Ohm resistor — the most common value for LED current limiting on 3.3V systems. A pack of 500 is under $2.
- Jumper wires — male-to-male, 22 AWG. A set of 40 is about $3.
You can get all of these in a single kit for under $15. Here is a budget option:
Breadboard kit with LEDs, resistors, and jumper wires on Amazon (affiliate link — supports CryptoTavern at no cost to you)
I make a small commission when you use this link. It does not change the price. This is how the course stays free.
Wiring the Circuit
The circuit you are building looks like this:
```
ESP32-C3
┌─────────┐
│ │
│ 3.3V ├───┬─────────────── Breadboard + rail
│ │ │
│ GND ├───┴─────────────── Breadboard - rail
│ │
│ GPIO 2 ├────┐
│ │ │ 330Ω
│ │ └───////────┬──┬── LED (+) long leg
│ │ │ │ LED (-) short leg
│ │ │ └─── GND rail
└─────────┘ │
─┴─
(gap — LED only connects
in one direction)
```
Let me break down what is happening at each point:
The 3.3V rail connects to the long leg of the LED (the positive leg, also called the anode). The LED needs current to flow in this direction — it is a diode, which means it only conducts in one direction.
GPIO 2 connects through the 330 Ohm resistor to the circuit. The resistor limits how much current can flow. Without it, too much current would pass through the LED and it would burn out.
GND connects to the short leg of the LED (the negative leg, also called the cathode). The circuit is completed: power → resistor → LED → ground. When GPIO 2 is set to HIGH, current flows and the LED lights. When GPIO 2 is set to LOW, there is no voltage difference and no current flows.
Why 330 Ohms? — Ohm's Law
The resistor value is not magic. It comes from Ohm's Law:
V = I × R
Where:
- V is voltage (in Volts)
- I is current (in Amps)
- R is resistance (in Ohms)
Rearrange to solve for R:
R = V / I
Your ESP32 outputs 3.3 Volts. A standard 5mm LED wants about 20mA (0.02 Amps) to light at full brightness, and it drops about 2 Volts across itself (this is called the forward voltage).
So the voltage across the resistor is:
3.3V (from the ESP32) - 2.0V (LED forward voltage) = 1.3V
The resistor needs to drop 1.3 Volts while allowing 20mA to flow:
R = 1.3V / 0.02A = 65 Ohms
So technically 65 Ohms would work. But we use 330 Ohms because:
- It is a standard value. Resistors come in fixed values. 330 Ohms is the next common step up from 220 Ohms.
- It is safer. 20mA is the maximum for a standard LED. Running at slightly lower current (about 10mA with 330 Ohms) still produces good brightness and your LED will last longer.
- It is the convention. 330 Ohms is the default resistor for LED circuits on 3.3V microcontrollers. You will see it everywhere.
If you use a different LED color, the forward voltage changes slightly. Red LEDs are around 2.0V. Blue and white LEDs are closer to 3.0V. For blue LEDs on 3.3V, there is almost no voltage left after the LED drop, so a 330 Ohm resistor results in very dim lighting — you might want 100 Ohms instead. But for most beginner kits with mixed-color LEDs, 330 Ohms is the right default.
LED Polarity — Why Direction Matters
LED stands for Light Emitting Diode. A diode is a component that only allows current to flow in one direction. If you connect it backwards, no current flows and the LED stays dark.
The two legs are not the same length:
- Long leg (+, anode): Current enters here
- Short leg (-, cathode): Current exits here
On most LEDs, there is also a flat edge on the plastic body next to the short leg. This is another visual indicator of polarity.
When you wire your circuit, make sure the long leg goes toward power (through the resistor) and the short leg goes toward ground. If the LED does not light up, flip it around.
The Code — MicroPython
We are switching to MicroPython for this lesson. Where Arduino is compiled C++, MicroPython runs as an interpreted script directly on the board. It is slower but much faster to write and test — great for prototyping.
In MicroPython on the ESP32, you control pins using the `machine.Pin` class:
```python
from machine import Pin
import time
GPIO 2 — change this if you wired to a different pin
led = Pin(2, Pin.OUT)
while True:
led.value(1) # Turn LED on
time.sleep(0.5) # Wait 500ms
led.value(0) # Turn LED off
time.sleep(0.5) # Wait 500ms
```
That is the entire program. `Pin.OUT` sets the pin as an output (sending signal out rather than reading it in). `led.value(1)` sets it HIGH (3.3V). `led.value(0)` sets it LOW (0V).
Upload this using your MicroPython tool (Thonny, mpfs, or `ampy` via command line). The board will immediately start running it.
Uploading MicroPython to Your ESP32
If you have not used MicroPython on your ESP32-C3 before, you need to flash the firmware first:
1. Download the firmware
Go to micropython.org/download and find the ESP32-C3 firmware. Look for a file like `esp32c3-usb.bin`.
2. Flash the firmware
With the board connected via USB, use esptool:
```bash
esptool.py --port /dev/ttyUSB0 erase_flash
esptool.py --port /dev/ttyUSB0 write_flash 0x0 esp32c3-usb.bin
```
On Windows, the port will be `COM3` or similar.
3. Connect and run
Use a tool like Thonny IDE (free, works on all platforms) to connect to the board via the serial port and send your script. You can also save the script as `main.py` on the board and it will run automatically on boot.
What You Built — Circuit Logic
The circuit you wired is a complete loop:
```
Power (3.3V) → Resistor (limits current) → LED (converts current to light) → Ground (GND)
↑
│
GPIO 2 (HIGH = closes the loop, LOW = breaks the loop)
```
When GPIO 2 is HIGH, there is a voltage difference across the entire path. Electrons flow. The LED emits light.
When GPIO 2 is LOW, both ends of the circuit are at the same voltage (3.3V at the resistor end, 3.3V at the GPIO end). No electron flow. No light.
This is the same pattern used for everything: a motor in a robot arm, a solenoid on a door lock, a relay that turns on your garage door. You are not controlling the device directly — you are controlling whether the circuit is open or closed. The microcontroller is just a very fast, very reliable switch.
Two LEDs, Alternating
Here is the challenge: wire a second LED and make them blink in alternation — one on while the other is off, then switch.
You will need:
- A second LED
- A second 330 Ohm resistor
- Another row on the breadboard to connect it
Wire the second LED to GPIO 3 (or any other free GPIO pin).
The code:
```python
from machine import Pin
import time
led1 = Pin(2, Pin.OUT)
led2 = Pin(3, Pin.OUT)
while True:
led1.value(1) # LED 1 on
led2.value(0) # LED 2 off
time.sleep(0.5)
led1.value(0) # LED 1 off
led2.value(1) # LED 2 on
time.sleep(0.5)
```
When this works — and it will — you have just controlled two independent outputs. That is the basis of everything that follows: multiple things happening in sequence, in coordination, on your command.
Key Concepts Learned
- Breadboard: A prototyping board with pre-connected holes for building circuits without soldering.
- Circuit: A complete loop through which current flows. Break the loop, nothing happens. Complete it, something happens.
- Ohm's Law: V = IR. Voltage, current, and resistance are related. Choose the right resistor to control current.
- LED polarity: LEDs only conduct in one direction. Long leg is positive, short leg is negative.
- MicroPython: A Python variant that runs directly on microcontrollers. Slower than C++ but faster to write and test.
- GPIO as a switch: Setting a GPIO pin HIGH or LOW opens or closes the circuit connected to it.
Troubleshooting
The LED is not lighting up.
- Check the polarity. Flip the LED around. Long leg should connect toward the resistor, short leg toward ground.
- Try a different GPIO pin. Your board might have the LED connected to GPIO 2 by default.
- Check that the resistor is in series (in line) with the LED, not parallel.
The LED is very dim.
- This usually means not enough current is reaching the LED. Try a 220 Ohm resistor instead of 330 Ohm. Do not go below 100 Ohms.
- If you are using a blue or white LED, the forward voltage is higher — try a 100 Ohm resistor.
The board is not responding after flashing MicroPython.
- Press the RESET button on the board.
- Check that you selected the correct serial port in your IDE.
- Try erasing and re-flashing the firmware.
What's Next
You now know how to build a circuit, control it with code, and reason about voltage and current. These are the tools of every electronics project you will ever touch.
In Lesson 03, we will add a push button and read an input. You will learn how the ESP32 can respond not just to timed loops, but to the physical world — pressing a button, flipping a switch — in real time.
From there we connect to WiFi and build a robot you can control from your phone.
The hardware side is no longer the hard part. You own it now.
CryptoTavern Robotics from Scratch is an evolving course. Each lesson improves over time as the community learns. If something was unclear, if you got stuck, or if something just worked and you want to say so — that is what the course is for.
Next lesson: Lesson 03 — Inputs and Outputs: Reading a Push Button