Open Source Hardware

Build with ESP32

Step-by-step guides, copyable code, and deployment strategies for the world's most versatile IoT microcontroller.

Development Environments

Choose your toolchain. Arduino IDE is best for beginners, MicroPython for Python developers, and ESP-IDF for production-grade firmware.

Arduino IDE

Add the ESP32 board manager URL and install the core in under 2 minutes.

https://espressif.github.io/arduino-esp32/package_esp32_index.json
  1. Open Arduino IDE → File → Preferences.
  2. Paste the URL into Additional Boards Manager URLs.
  3. Go to Tools → Board → Boards Manager.
  4. Search esp32 and install esp32 by Espressif Systems.
  5. Select your board under Tools → Board → ESP32 Arduino.

MicroPython

Flash the firmware and run Python natively on the ESP32.

esptool.py --chip esp32 --port /dev/ttyUSB0 write_flash -z 0x1000 ESP32_GENERIC-20240602-v1.23.0.bin
  1. Download the latest .bin firmware for your board.
  2. Install esptool: pip install esptool
  3. Put the board in bootloader mode (hold BOOT, press RESET).
  4. Flash the firmware using the command above.
  5. Connect with any serial terminal at 115200 baud.

ESP-IDF

Professional C/C++ framework with FreeRTOS and advanced debugging.

./install.sh esp32 . ./export.sh idf.py set-target esp32 idf.py build flash monitor
  1. Clone the ESP-IDF repository and run install.sh.
  2. Export the environment with export.sh.
  3. Navigate to your project and set the target chip.
  4. Build, flash, and monitor in one command.

Project Library

Each project includes required parts, step-by-step instructions, and copyable code. Click any card to expand the full tutorial.

Weather Station with DHT22 & OLED

~45 min
Beginner
IoT / WiFi

Display real-time temperature and humidity on an OLED screen and push data to ThingSpeak every 30 seconds.[reference:0]

Parts Required

ESP32 DevKit V1 DHT22 Sensor SSD1306 OLED (128×64, I2C) 10kΩ Resistor Jumper Wires Breadboard USB Cable

Wiring

ESP32 DHT22 3.3V ──── VCC GND ──── GND GPIO4 ───[10k]─ DATA ESP32 SSD1306 OLED 3.3V ──── VCC GND ──── GND GPIO21 ─── SDA GPIO22 ─── SCL

Steps

  1. Install libraries: DHT sensor library, Adafruit SSD1306, Adafruit GFX Library.
  2. Wire the components as shown above.
  3. Open the sketch and set your WiFi credentials and ThingSpeak API key.
  4. Select ESP32 Dev Module and the correct port.
  5. Upload and open Serial Monitor at 115200 baud.

Code Snippet

#include <WiFi.h> #include <DHT.h> #include <Adafruit_SSD1306.h> #define DHTPIN 4 #define DHTTYPE DHT22 DHT dht(DHTPIN, DHTTYPE); Adafruit_SSD1306 display(128, 64, &Wire, -1); void setup() { Serial.begin(115200); dht.begin(); display.begin(SSD1306_SWITCHCAPVCC, 0x3C); display.clearDisplay(); WiFi.begin("SSID", "PASSWORD"); while (WiFi.status() != WL_CONNECTED) delay(500); } void loop() { float t = dht.readTemperature(); float h = dht.readHumidity(); display.clearDisplay(); display.setTextSize(1); display.setTextColor(WHITE); display.setCursor(0, 0); display.print("Temp: "); display.print(t); display.println(" C"); display.print("Hum: "); display.print(h); display.println(" %"); display.display(); delay(30000); }

Air Quality Monitor with MQ135 & MQ2

~1 hour
Intermediate
Environmental

Capture CO₂, LPG, and smoke levels with MQ135 and MQ2 sensors, then visualize the Air Quality Index on ThingSpeak.[reference:1]

ESP32 MQ135 Sensor MQ2 Sensor Mini Breadboard Jumper Wires
#define MQ135_PIN 34 #define MQ2_PIN 35 void setup() { Serial.begin(115200); analogReadResolution(12); } void loop() { int co2 = analogRead(MQ135_PIN); int gas = analogRead(MQ2_PIN); Serial.print("CO2: "); Serial.print(co2); Serial.print(" | Gas: "); Serial.println(gas); delay(15000); }

IoT Alarm System with PIR & Ultrasonic

~1.5 hours
Intermediate
MQTT / Node-RED

Detect motion and distance, publish to MQTT, and visualize on a Node-RED dashboard with local RGB LED alerts.[reference:2]

ESP32 DevKit C v4 PIR HC-SR501 HC-SR04 Ultrasonic RGB LED + 3×220Ω Breadboard Jumper Wires
#include <WiFi.h> #include <PubSubClient.h> #include <NewPing.h> #define PIR_PIN 21 #define TRIG_PIN 27 #define ECHO_PIN 14 #define LED_R 15 #define LED_G 32 #define LED_B 33 NewPing sonar(TRIG_PIN, ECHO_PIN, 200); WiFiClient espClient; PubSubClient client(espClient); void setup() { Serial.begin(115200); pinMode(PIR_PIN, INPUT); pinMode(LED_R, OUTPUT); pinMode(LED_G, OUTPUT); pinMode(LED_B, OUTPUT); WiFi.begin("SSID", "PASS"); while (WiFi.status() != WL_CONNECTED) delay(500); client.setServer("test.mosquitto.org", 1883); } void loop() { int motion = digitalRead(PIR_PIN); int distance = sonar.ping_cm(); if (motion) { digitalWrite(LED_R, HIGH); } else { digitalWrite(LED_R, LOW); } client.publish("esp32/alarm", String(distance).c_str()); delay(1000); }

ESP32 Web Server with GPIO Control

~30 min
Beginner
Web / HTTP

Host a responsive web page from the ESP32 and toggle LEDs from any browser on your local network.[reference:3]

ESP32 LED 220Ω Resistor Breadboard
#include <WiFi.h> #include <WebServer.h> WebServer server(80); const int ledPin = 2; void handleRoot() { String html = "<html><body>"; html += "<h1>ESP32 Web Server</h1>"; html += "<a href='/on'><button>ON</button></a>"; html += "<a href='/off'><button>OFF</button></a>"; html += "</body></html>"; server.send(200, "text/html", html); } void setup() { Serial.begin(115200); pinMode(ledPin, OUTPUT); WiFi.begin("SSID", "PASS"); while (WiFi.status() != WL_CONNECTED) delay(500); server.on("/", handleRoot); server.on("/on", []() { digitalWrite(ledPin, HIGH); server.send(200); }); server.on("/off", []() { digitalWrite(ledPin, LOW); server.send(200); }); server.begin(); } void loop() { server.handleClient(); }

Bluetooth Classic Serial Bridge

~20 min
Beginner
Bluetooth

Create a wireless serial connection between your phone and the ESP32 using Bluetooth Classic.[reference:4]

#include <BluetoothSerial.h> BluetoothSerial SerialBT; void setup() { Serial.begin(115200); SerialBT.begin("ESP32_Bridge"); Serial.println("Bluetooth ready. Pair with ESP32_Bridge."); } void loop() { if (Serial.available()) SerialBT.write(Serial.read()); if (SerialBT.available()) Serial.write(SerialBT.read()); }

Battery-Powered Deep Sleep Logger

~40 min
Intermediate
Power Management

Reduce power consumption to under 10 µA and extend battery life to months by using deep sleep and RTC memory.[reference:5]

#define uS_TO_S_FACTOR 1000000 #define TIME_TO_SLEEP 300 RTC_DATA_ATTR int bootCount = 0; void setup() { Serial.begin(115200); bootCount++; Serial.println("Boot number: " + String(bootCount)); esp_sleep_enable_timer_wakeup(TIME_TO_SLEEP * uS_TO_S_FACTOR); esp_deep_sleep_start(); } void loop() {}

Servo Motor Sweep & Control

~20 min
Beginner
Actuator

Control a standard servo motor with the ESP32Servo library. Perfect for robotics and automation prototypes.[reference:6]

#include <ESP32Servo.h> Servo myservo; void setup() { myservo.attach(18); } void loop() { for (int pos = 0; pos <= 180; pos += 1) { myservo.write(pos); delay(15); } for (int pos = 180; pos >= 0; pos -= 1) { myservo.write(pos); delay(15); } }

Deployment & OTA

Over-the-air updates let you push firmware wirelessly. The ESP32 supports ArduinoOTA and ESP-IDF HTTPS OTA out of the box.

ArduinoOTA

Wireless firmware updates from the Arduino IDE over WiFi.

#include <ArduinoOTA.h> void setup() { ArduinoOTA.begin(); } void loop() { ArduinoOTA.handle(); }
  1. Include the ArduinoOTA library.
  2. Call ArduinoOTA.begin() in setup.
  3. Call ArduinoOTA.handle() in loop.
  4. Select the network port in the IDE and upload.

ESP-IDF HTTPS OTA

Production-grade OTA with rollback and secure HTTPS.

esp_https_ota_config_t ota_config = { .http_config = &config, }; esp_err_t ret = esp_https_ota(&ota_config); if (ret == ESP_OK) { esp_restart(); }
  1. Add the esp_https_ota component.
  2. Configure the firmware URL and certificate.
  3. Call esp_https_ota() and reboot on success.
  4. Use rollback configuration for safe updates.

First-Time Flash Command

Use this command to flash any compiled .bin file to the ESP32 over USB.

esptool.py --chip esp32 --port /dev/ttyUSB0 --baud 460800 write_flash -z 0x1000 firmware.bin