Skip to the content.

💡 GPIO Output – Light Up and Blink an LED

When learning any microcontroller, one of the simplest yet most essential experiments is controlling an LED using a GPIO pin. This lesson will walk you through how to light up and blink an LED on the ESP32, and now includes instructions on using the custom extension board you designed!

✅ By the end of this tutorial, you’ll:


🧠 Basic Concepts

1. What is a GPIO Pin?

GPIO stands for General Purpose Input/Output. These are the pins on the ESP32 that can either send or receive electrical signals.

On the ESP32 board, you’ll notice pins labeled with “D” like D2, D4, D15 — these are GPIO pins. Today, we’ll focus on output, where a pin sends out a voltage signal. alt text

⚡ What is a voltage level?

Microcontrollers “talk” using electricity in the form of voltage levels, often referred to as logic levels in digital electronics.

In simple terms:

By changing the voltage on a GPIO pin, we can turn things on and off. For example:

Exact thresholds may vary slightly — feel free to test and confirm!

📐 How Many GPIOs Are There? The ESP32 has 30+ GPIO pins, and each can serve different roles:

Not all pins are equal — some are input-only, some are strapped (used during boot), and some should be avoided during startup. 🧭 Use this pinout guide to check which pins are safe for your specific application:
🔗 ESP32 Pinout Guide (Random Nerd Tutorials)


2. What is an LED?

An LED (Light Emitting Diode) is a tiny light source that emits light when current flows through it in the correct direction. alt text

When lit, an LED typically shows a forward voltage drop of about 1.7V.


🔌 Hardware Setup

The extension board is designed to make wiring easier and reduce the possibility of damaging the components.

✅ Steps:

Use female-to-male jumper wires to make the following connections:

LED Board Pin ESP32 Pin
GND GND
LED1 GPIO12 (D12)

alt text

Option B: Use a Breadboard (Alternative)

If you don’t have your extension board with you, here’s how to wire it on a breadboard:

📋 Bill of Materials (BOM)

Item Quantity
LED (through-hole) 1
1kΩ Resistor 1
Jumper wires Some
Breadboard 1

🧩 Circuit Wiring


💻 Software Design

1. Light Up the LED

To light up the LED:

// Set LED pin
int led_pin = 12;

void setup() {
  pinMode(led_pin, OUTPUT);       // Set pin as output
  digitalWrite(led_pin, HIGH);    // Turn on the LED
}

void loop() {
  // Nothing here for now
}

Upload this code using your Arduino IDE — the LED should turn on!


Now, let’s make it blink! Blinking means:

Here’s how to do it:

// Set LED pin
int led_pin = 12;

void setup() {
  pinMode(led_pin, OUTPUT);  // Set pin as output
}

void loop() {
  digitalWrite(led_pin, HIGH); // Turn on LED
  delay(1000);                 // Wait 1 second
  digitalWrite(led_pin, LOW);  // Turn off LED
  delay(1000);                 // Wait 1 second
}

Upload the code — you’ll see your LED blinking on and off every second.

🧠 Bonus:

🌈 Running Light Experiment