Robotics for Beginners: Learn ESP32 PlatformIO with VS Code | Blink LED Tutorial

An ESP32 microcontroller on a breadboard connected to a red LED and resistor, with a laptop in the background running PlatformIO in VS Code.

I still remember the first time I made an LED blink.

It wasn’t the LED that excited me. It was the realization that I told a piece of hardware what to do, and it listened.

No magic. No mystery. Just code, a microcontroller, and a tiny light.

That moment changed everything. It was the first step toward RC cars, soccer bots, security cameras, and eventually a full robotics channel.

And today? That moment is yours.

Welcome to the Roborear Robotics Course. This is Episode 1. And by the end of this tutorial, you will have:

  • ✅ A professional coding environment (VS Code + PlatformIO)

  • ✅ Your first C++ program running on an ESP32

  • ✅ A blinking LED (the “Hello World” of hardware)

  • ✅ The foundation for every robotics project after this

Why ESP32? (And Why Not Arduino Uno?)

Let me be honest. The Arduino Uno is a great board. It’s simple, it’s everywhere, and it’s perfect for learning.

But for real robotics? The ESP32 is simply better.

 
 
FeatureArduino UnoESP32
Processor Speed16 MHz160-240 MHz
RAM2 KB520 KB
Flash Storage32 KB4-16 MB
Built-in WiFi❌ No✅ Yes
Built-in Bluetooth❌ No✅ Yes
Number of Pins2025+
Price~$20-25~$5-7
Best ForSimple projects, learning basicsRobotics, IoT, complex projects

For a BUET mechanical engineering student building soccer bots? The ESP32 is the obvious choice.

In this course, we’ll use the ESP32 for everything:

  • RC cars (wireless control)

  • Obstacle avoidance robots (sensors + motors)

  • Line followers (speed + precision)

  • Smart home devices (WiFi + Bluetooth)

But first? We blink an LED.

Check out my detailed review of the ESP32-C3 Super Mini -> The ESP32-C3 Super Mini: This Tiny Board Stole My Heart (And Yes, It Has WiFi)

What You’ll Need (Under $10!)

 
 
ComponentSpecsApprox Price (USD)
ESP32 Development BoardAny version (30-pin or 38-pin)$5.00 – $7.00
USB Cable (Data Cable!)USB-A to Micro-USB or USB-C$2.00 – $4.00
LED (Optional external)5mm, any color$0.10 – $0.20
220Ω Resistor (Optional)For external LED$0.02 – $0.05
Breadboard (Optional)400 points$0.85 – $1.25
Jumper Wires (Optional)Male-to-male or male-to-female$0.40 – $0.85

Total (with just ESP32 and cable): ~$7.00 – $11.00 USD

Note: Most ESP32 boards have a built-in LED on GPIO 2. You don’t even need external components for this tutorial!

 
 
ComponentWhere to Find
ESP32 Development BoardAliExpress 
USB Data CableAliExpress
LED Kit (Various Colors)AliExpress
220Ω Resistors (Pack)AliExpress
Breadboard + Jumper KitAliExpress
Close-up of an ESP32 development board on a green cutting mat with a red circle highlighting the onboard LED labeled D2, used for PlatformIO blink tests.

Why VS Code + PlatformIO? (Say Goodbye to Arduino IDE)

Most beginners start with the Arduino IDE. It’s simple. It works. But it has limits.

 
 
FeatureArduino IDEVS Code + PlatformIO
Autocomplete❌ Basic or none✅ Intelligent (IntelliSense)
Code suggestions❌ No✅ Yes (GitHub Copilot optional)
Project organization❌ Single file only✅ Multiple files + folders
Library management❌ Manual ZIP install✅ One-click library search
Git integration❌ No✅ Built-in
Multiple platforms⚠️ Limited✅ 1000+ boards
Professional tool❌ No✅ Yes (industry standard)

For quick tests? Arduino IDE is fine.

For building robots, managing complex code, and learning professional tools? VS Code + PlatformIO is the answer.

I use VS Code for everything:

  • ESP32 robotics code

  • Python scripts for data analysis

  • Web development for Roborear

  • GitHub Copilot for AI-assisted coding

One editor. Everything in one place.

A screenshot of Visual Studio Code showing a C++ blink sketch for an ESP32 project within the PlatformIO environment, featuring the main.cpp file and project explorer.

Step 1: Installing VS Code and PlatformIO

1.1 Download and Install VS Code

Go to code.visualstudio.com

Download the version for your operating system (Windows, Mac, Linux)

Install it (default settings are fine)

1.2 Install PlatformIO Extension

Open VS Code

Click the Extensions icon on the left sidebar (or press Ctrl+Shift+X)

Search for “PlatformIO IDE”

Click Install (it’s the one with the little ant logo)

Wait for the installation to complete (it may take a few minutes)

 

1.3 Verify PlatformIO is Working

After installation, you’ll see a new icon on the left sidebar (looks like an ant head)

Click it. You should see “PlatformIO Home”

Congratulations! You now have a professional embedded development environment.

A screenshot of the Visual Studio Code Extension Marketplace showing the PlatformIO IDE installation page, used for programming ESP32 boards.

Step 2: Creating Your First PlatformIO Project

2.1 Start a New Project

Click the PlatformIO icon (ant) on the left sidebar

Click “New Project”

Fill in:

 
 
FieldWhat to Enter
NameBlink_LED (or anything you like)
BoardSearch and select DOIT ESP32 DEVKIT V1
FrameworkArduino (this is the easiest for beginners)
LocationKeep default or choose your folder

Click “Finish”

PlatformIO will now create your project and download the necessary tools. This may take a minute or two.

A screenshot of the platformio.ini configuration file in VS Code showing environment settings for an esp32dev board using the Arduino framework.

2.2 Understanding the Project Structure

Your project folder will look like this:

text
Blink_LED/
├── .pio/           (PlatformIO build files - don't touch)
├── .vscode/        (VS Code settings)
├── include/        (Header files - for advanced projects)
├── lib/            (Custom libraries - for later)
├── src/            (YOUR CODE GOES HERE!)
│   └── main.cpp    (This is where you'll write code)
├── platformio.ini  (Project configuration file)
└── .gitignore      (For Git version control)

For now, we only care about src/main.cpp and platformio.ini.

Open src/main.cpp. Delete everything in it. Copy and paste this code:

cpp
// ============================================================
// ESP32 Blink LED - First Robotics Program
// This blinks the built-in LED on GPIO 2
// ============================================================

// The setup function runs once when the board powers on
void setup() {
  // Initialize the built-in LED pin as an output
  pinMode(LED_BUILTIN, OUTPUT);
}

// The loop function runs repeatedly forever
void loop() {
  digitalWrite(LED_BUILTIN, HIGH);   // Turn the LED ON
  delay(1000);                       // Wait 1 second (1000 milliseconds)
  digitalWrite(LED_BUILTIN, LOW);    // Turn the LED OFF
  delay(1000);                       // Wait 1 second
}

 

If you haven’t set up VS Code with PlatformIO yet, follow this guide first -> I Used Arduino IDE for 3 Months. Then I Found VS Code + PlatformIO and Never Went Back 

What Each Line Means

 
 
CodeWhat It Does
void setup()Runs once when the board starts. Used for initialization.
pinMode(LED_BUILTIN, OUTPUT)Tells the ESP32 that GPIO 2 is an OUTPUT pin (we want to send voltage out, not read it)
void loop()Runs repeatedly, forever. This is where the action happens.
digitalWrite(LED_BUILTIN, HIGH)Sends 3.3V to the pin. LED turns ON.
delay(1000)Pauses the program for 1000 milliseconds (1 second)
digitalWrite(LED_BUILTIN, LOW)Sends 0V to the pin. LED turns OFF.

The result: LED on for 1 second, off for 1 second, repeating forever.

Step 4: Understanding the platformio.ini File

Open platformio.ini. It should look like this:

ini
[env:doit_esp32_devkit_v1]
platform = espressif32
board = doit_esp32_devkit_v1
framework = arduino
monitor_speed = 115200
 
 
SettingWhat It Means
platform = espressif32We’re using Espressif’s ESP32 platform
board = doit_esp32_devkit_v1The specific board model
framework = arduinoUsing Arduino framework (easiest for beginners)
monitor_speed = 115200Serial monitor baud rate (we’ll use this later)

You don’t need to change anything here. Just know it exists.

Step 5: Connecting Your ESP32

5.1 Connect the Board

Plug your ESP32 into your computer using a USB cable.

Important: Use a data cable, not just a charging cable. Many USB cables only have power wires, no data wires. If your computer doesn’t detect the board, try a different cable.

5.2 Select the Correct Port

In VS Code, look at the bottom status bar (blue bar at the bottom)

You’ll see something like: COM3 or /dev/ttyUSB0 (depending on your OS)

If you don’t see a port:

  • Windows: Check Device Manager under “Ports (COM & LPT)”

  • Mac/Linux: Try unplugging and re-plugging the board

A computer screen showing a dropdown menu for selecting a COM port, specifically the CP210x USB to UART Bridge, used for an ESP32 connection in PlatformIO.

Step 6: Uploading Your Code

6.1 Build and Upload

Click the “Upload” arrow (→) at the bottom of VS Code (next to the checkmark and plug icons)

Or press: Ctrl+Alt+U (Windows/Linux) or Cmd+Alt+U (Mac)

6.2 Watch the Terminal

A terminal panel will open at the bottom showing:

text
Processing doit_esp32_devkit_v1...
Compiling .pio/build/doit_esp32_devkit_v1/src/main.cpp
Linking .pio/build/doit_esp32_devkit_v1/firmware.elf
Checking size .pio/build/doit_esp32_devkit_v1/firmware.elf
RAM: [=== ] 8.2% (used 42808 bytes from 524288)
Flash: [= ] 6.1% (used 79602 bytes from 1310720)
Uploading...

6.3 The Moment of Truth

After a few seconds, you should see:

text
Leaving...
Hard resetting via RTS pin...

And on your ESP32, the blue LED should start blinking! ON for 1 second, OFF for 1 second.

(Photo: ESP32 with blue LED glowing)

6.4 Troubleshooting Upload Failures

If the upload fails, you might see a “Connecting…” message that hangs.

The Fix: Some ESP32 boards need to be put into “download mode” manually:

  1. Hold down the BOOT button on the ESP32

  2. Press and release the EN (Reset) button

  3. Release the BOOT button

  4. Try uploading again

This is normal for many ESP32 boards. After a few uploads, you’ll get used to it.

Step 7: Optional – Adding an External LED

Want to blink an external LED? Here’s how:

Wiring

 
 
ComponentConnect To
LED Anode (long leg)GPIO 5 (or any free pin) through a 220Ω resistor
LED Cathode (short leg)GND

Modified Code

cpp
// Define which pin the LED is connected to
#define EXTERNAL_LED 5

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  pinMode(EXTERNAL_LED, OUTPUT);
}

void loop() {
  // Blink built-in LED
  digitalWrite(LED_BUILTIN, HIGH);
  digitalWrite(EXTERNAL_LED, LOW);
  delay(500);
  
  digitalWrite(LED_BUILTIN, LOW);
  digitalWrite(EXTERNAL_LED, HIGH);
  delay(500);
}

Now the built-in LED and external LED will blink alternately!

An ESP32 microcontroller on a breadboard connected to a red LED and resistor, with a laptop in the background running PlatformIO in VS Code.

Final Thoughts

Blinking an LED might seem small. But it’s the first step toward building robots that move, see, and think.

Every expert was once a beginner. Every complex robot started with a single blinking light.

So take a moment. Watch that LED blink. You just programmed a microcontroller.

That’s not nothing. That’s everything.

Now go build something cool.

Ready to build something that moves? start with the ESP32 RC Car project -> Build Your Own ESP32 RC Car: Wireless Joystick Controller Guide for Beginners

FAQs

Subscribe to The Newsletter

Join robotics enthusiasts getting weekly project ideas:

• 🔧 Under $50 projects

• ⚙️ Under $100 projects

• 🎥 New video tutorials

• 📝 Blog updates

We don’t spam! Read our privacy policy for more info.

Similar Posts

One Comment

Leave a Reply

Your email address will not be published. Required fields are marked *