Tutorials

Your first ESP32 project in 30 minutes

CircuitBay Team · · Updated · 8 min read

The ESP32 is the go-to board for IoT projects: it has Wi-Fi and Bluetooth built in, a fast dual-core processor and plenty of pins, and it costs about the same as an Arduino Uno. In this tutorial you will build a tiny Wi-Fi thermometer — the ESP32 reads a DHT11 temperature and humidity sensor and serves the reading as a web page that any phone on the same network can open.

What you'll need

  • ESP32 DevKit V1 (or any ESP32 development board)
  • DHT11 temperature and humidity sensor module
  • 830-point breadboard and three jumper wires
  • A micro-USB or USB-C data cable (not a charge-only cable)
  • Arduino IDE 2 on your laptop

Set up the Arduino IDE for ESP32

Open the Boards Manager in the Arduino IDE, search for "esp32" and install the package by Espressif Systems. Then open the Library Manager and install "DHT sensor library" by Adafruit (accept its dependency, Adafruit Unified Sensor). Select "ESP32 Dev Module" as the board and pick the right COM port. If no port appears, install the USB-to-serial driver for your board — most DevKits use a CP2102 or CH340 chip.

Wiring it up

Connect the DHT11 module's VCC pin to 3V3 on the ESP32, GND to GND, and the DATA pin to GPIO 4. Most DHT11 modules already include the 10 kΩ pull-up resistor on the data line; if you are using a bare 4-pin sensor, add one between DATA and 3V3.

The code

Replace the Wi-Fi name and password, upload the sketch, and open the Serial Monitor at 115200 baud. When the board connects, it prints its IP address.

#include <WiFi.h>
#include <WebServer.h>
#include <DHT.h>

const char* SSID = "your-wifi";
const char* PASS = "your-password";

DHT dht(4, DHT11);
WebServer server(80);

void handleRoot() {
  float t = dht.readTemperature();
  float h = dht.readHumidity();
  if (isnan(t) || isnan(h)) {
    server.send(500, "text/plain", "Sensor read failed");
    return;
  }
  server.send(200, "text/html",
    "<h1>" + String(t, 1) + " &deg;C</h1><p>Humidity " + String(h, 0) + "%</p>");
}

void setup() {
  Serial.begin(115200);
  dht.begin();
  WiFi.begin(SSID, PASS);
  while (WiFi.status() != WL_CONNECTED) delay(500);
  Serial.println(WiFi.localIP());
  server.on("/", handleRoot);
  server.begin();
}

void loop() {
  server.handleClient();
}

Test it

Type the printed IP address into your phone's browser (the phone must be on the same Wi-Fi network). Refresh the page to take a new reading. Breathe gently on the sensor and watch the humidity climb.

Troubleshooting

  • "Sensor read failed": check the DATA wire is on GPIO 4 and wait two seconds between readings — the DHT11 updates about once a second.
  • Upload fails with "Failed to connect": hold the BOOT button while the IDE says "Connecting…".
  • Stuck connecting to Wi-Fi: the ESP32 only supports 2.4 GHz networks, not 5 GHz.

Next steps

Log readings to a spreadsheet, add an OLED display, or switch a fan with a relay when it gets hot — the ESP32 IoT Starter Kit has all three. When it works, share it with the bay.

Questions or improvements? Join the discussion →

Built this? Share it with the bay.

Submit your project →

FROM THE COMMUNITY

Related projects

IoT

AirLoo

A smart washroom air-quality monitor that alerts staff before things get bad.

  • ESP32
  • MQ-135
  • IoT
IoT

Smart Agriculture

Soil-moisture sensing and automatic irrigation, reporting live to a phone dashboard.

  • ESP8266
  • Soil sensor
  • Relay