Skip to content

Getting Started with ESP32 – Your First IoT Project

Introduction

The ESP32 is one of the most powerful and affordable microcontroller boards for IoT projects. With built‑in Wi‑Fi, Bluetooth, and dual‑core processing, it allows you to connect hardware projects to the internet or your smartphone with ease.

In this beginner guide, you’ll learn:

  • How to set up an ESP32 in Arduino IDE.
  • How to connect it to your Wi‑Fi.
  • Your first IoT project: ESP32 Web Server to control an LED from your phone/browser.

By the end, you’ll have gone from unboxing your ESP32 to hosting a mini IoT smart device

What You Need

  • ESP32 DevKit V1 board (classic version works fine).
  • Micro‑USB cable (for programming + power).
  • Arduino IDE installed on your PC.
  • Home Wi‑Fi network (with SSID and password).
  • 1x LED + 220Ω resistor (optional, because ESP32 has a built‑in LED on GPIO2).

Step 1: Install ESP32 Board Support in Arduino IDE

  1. Open Arduino IDE.
  2. Go to File → Preferences.
  3. In “Additional Board Manager URLs”, paste:

text

https://dl.espressif.com/dl/package_esp32_index.json

  1. Then go to Tools → Board → Boards Manager.
  2. Search for “ESP32” → Install.
  3. Under Tools → Board, select: ESP32 Dev Module (or your specific ESP32 board).

 

Step 2: Connect ESP32 to Your PC

  • Plug ESP32 via Micro‑USB cable.
  • Go to Tools → Port → Select the COM port (it appears when ESP32 is connected).

Step 3: First Program – Connect ESP32 to Wi‑Fi

This verifies your ESP32 is working and can connect to your Wi‑Fi.

C++

#include <WiFi.h>

 

const char* ssid = “YourWiFiName”;

const char* password = “YourWiFiPassword”;

 

void setup() {

Serial.begin(115200);

delay(1000);

 

Serial.println(“Connecting to Wi-Fi…”);

WiFi.begin(ssid, password);

 

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(“.”);

}

 

Serial.println(“\nWi-Fi connected!”);

Serial.print(“ESP32 IP Address: “);

Serial.println(WiFi.localIP());  // Shows local IP

}

 

void loop() {

// Nothing here yet

}

✅ Upload → Open Serial Monitor → ESP32 prints “Wi-Fi connected” + its IP address

Code: ESP32 Web Server LED Control

C++

#include <WiFi.h>

#include <WebServer.h>

 

const char* ssid = “YourWiFiName”;

const char* password = “YourWiFiPassword”;

 

WebServer server(80);  // HTTP server

int ledPin = 2; // GPIO2 = onboard LED

 

void handleRoot() {

String page = “<h1>ESP32 Web Server</h1>”;

page += “<p><a href=\”/on\”>Turn ON LED</a></p>”;

page += “<p><a href=\”/off\”>Turn OFF LED</a></p>”;

server.send(200, “text/html”, page);

}

 

void handleOn() {

digitalWrite(ledPin, HIGH);

server.send(200, “text/html”, “LED is ON<br><a href=\”/\”>Back</a>”);

}

 

void handleOff() {

digitalWrite(ledPin, LOW);

server.send(200, “text/html”, “LED is OFF<br><a href=\”/\”>Back</a>”);

}

 

void setup() {

pinMode(ledPin, OUTPUT);

digitalWrite(ledPin, LOW);

 

Serial.begin(115200);

WiFi.begin(ssid, password);

 

Serial.print(“Connecting”);

while (WiFi.status() != WL_CONNECTED) {

delay(500);

Serial.print(“.”);

}

Serial.print(“\nConnected! IP: “);

Serial.println(WiFi.localIP());

 

server.on(“/”, handleRoot);

server.on(“/on”, handleOn);

server.on(“/off”, handleOff);

server.begin();

}

 

void loop() {

server.handleClient();

}

Project Extensions

  • Add multiple LEDs/Relays → Multi‑appliance control.
  • Add a DHT11/22 sensor → Display temperature/humidity on webpage.
  • Add password login to restrict access.
  • Upgrade to ESP32 + Blynk, Thingspeak, or Google Sheets for cloud dashboards.

How to Use It

  1. Upload the code.
  2. Open Serial Monitor → Copy the IP address.
  3. Enter IP into your phone or PC browser.
  4. You’ll see webpage → Click ON or OFF → LED toggles instantly.

Congrats, you just made your first IoT smart device with ESP32.

Project Extensions

  • Add multiple LEDs/Relays → Multi‑appliance control.
  • Add a DHT11/22 sensor → Display temperature/humidity on webpage.
  • Add password login to restrict access.
  • Upgrade to ESP32 + Blynk, Thingspeak, or Google Sheets for cloud dashboards.

FAQs

Q1: Why doesn’t my ESP32 board show in Arduino IDE?
→ Make sure you installed the ESP32 boards package and selected the correct COM port.

Q2: Is this web server local only?
→ Yes. To control from outside home, you need port forwarding, MQTT, or a cloud IoT service.

Q3: Does ESP32 need Arduino Uno to work?
→ No. ESP32 is a standalone microcontroller.

Conclusion

The ESP32 makes it easy to move from “blinking LEDs” to true IoT smart devices.

  • ✅ Connected to Wi‑Fi.
  • ✅ Hosted your first web server.
  • ✅ Controlled an LED from your browser.

This foundation opens the door to home automation, cloud dashboards, and full IoT projects.