Quick Start Guide¶
Get your ESP32 Distance Sensor up and running in minutes! This guide covers both hardware and QEMU emulation paths.
Prerequisites¶
What You Need¶
Minimum Requirements:
Web browser with serial port support (Chrome or Edge recommended)
GitHub account (free tier sufficient)
Internet connection
For Hardware Development:
ESP32 development board
HC-SR04 ultrasonic sensor
WS2812 LED strip (40 LEDs)
USB cable
Jumper wires
(Optional) External 5V power supply
For Emulation Only:
Just a browser! QEMU runs everything in the cloud.
Note
First time with ESP32? Don’t worry! GitHub Codespaces handles all the complex setup automatically. No local installation required.
Path 1: QEMU Emulation (No Hardware)¶
Perfect for learning, testing, or remote workshops.
Step 1: Get the Code¶
# Fork or clone the repository
git clone https://github.com/enthali/esp32-distance.git
cd esp32-distance
Step 2: Open in Codespaces¶
Click Code button on GitHub
Select Codespaces tab
Click Create codespace on main (or your branch)
Wait 2-5 minutes for initial setup (ESP-IDF installation)
Note
What’s happening? Codespaces is installing ESP-IDF v5.4.1, QEMU emulator, and all development tools. This only happens once per codespace.
Step 3: Build the Project¶
# Build for QEMU target
idf.py build
Expected output:
Project build complete. To flash, run:
idf.py flash
Build time: ~30-60 seconds (incremental builds are much faster)
Step 4: Run in QEMU¶
Option A: Using VS Code Task (Recommended)
Press
Ctrl+Shift+P(orCmd+Shift+Pon Mac)Type “Tasks: Run Task”
Select “Run QEMU (No Debug)”
Option B: Using Command Line
# Start QEMU with network support
./tools/qemu/run_qemu.sh
What you’ll see:
🚀 Starting ESP32 Distance Sensor in QEMU
📡 Starting network bridge...
🌐 HTTP proxy running on http://localhost:8080
✅ QEMU started successfully
Distance Sensor Simulator:
🟢🟢🟢⚪⚪⚪⚪⚪⚪⚪ (15cm)
Step 5: Access Web Interface¶
Open your browser to:
http://localhost:8080
Features available:
View current distance reading
See LED strip visualization
Access configuration interface (when implemented)
Tip
Port Forwarding: GitHub Codespaces automatically forwards port 8080. You can access it from your local browser even though QEMU runs in the cloud!
Step 6: Debug (Optional)¶
Want to set breakpoints and step through code?
Press
F5in VS CodeOr use Run and Debug panel
Select “Debug in QEMU” configuration
Debugging features:
Set breakpoints in code
Step through execution line-by-line
Inspect variables and memory
View call stack and registers
Stop QEMU¶
# Stop QEMU emulator
./tools/qemu/stop_qemu.sh
# Or use VS Code task: "Stop QEMU"
Path 2: Hardware Development¶
Build and flash to real ESP32 hardware.
Step 1: Assemble Hardware¶
Follow the pin configuration from Hardware Specifications:
Connections:
ESP32 → HC-SR04 Sensor:
GPIO14 → Trig
GPIO13 → Echo
5V → VCC
GND → GND
ESP32 → WS2812 LED Strip:
GPIO12 → DIN
5V → 5V/VCC
GND → GND
Warning
Power Check: If using all 40 LEDs at high brightness, connect an external 5V power supply (3A+) to both ESP32 VIN and LED strip VCC. Share common ground!
Step 2: Get the Code¶
# Fork or clone the repository
git clone https://github.com/enthali/esp32-distance.git
cd esp32-distance
Step 3: Open in Codespaces¶
Same as Path 1:
Click Code → Codespaces → Create codespace
Wait for ESP-IDF setup (~2-5 minutes first time)
Step 4: Connect ESP32¶
Connect ESP32 to your computer via USB
In Codespaces, allow USB device access when prompted
Verify connection:
# List available serial ports
ls /dev/ttyUSB* /dev/ttyACM*
Expected output:
/dev/ttyUSB0 # Your ESP32 serial port
Note
Port name varies: May be /dev/ttyUSB0, /dev/ttyACM0, or similar.
Use the port name you see in your system.
Step 5: Build the Project¶
# Build for ESP32 hardware
idf.py build
Build time: ~30-60 seconds
Step 6: Flash to ESP32¶
# Flash and start monitoring serial output
idf.py -p /dev/ttyUSB0 flash monitor
Replace /dev/ttyUSB0 with your actual port name.
What happens:
Erase flash - Clears existing firmware
Flash bootloader - Low-level boot code
Flash partition table - Memory layout
Flash application - Your firmware
Monitor serial - Show boot logs and output
Expected output:
I (123) boot: ESP-IDF v5.4.1
I (234) main: Starting ESP32 Distance Sensor
I (345) wifi: WiFi initialized
I (456) sensor: Distance sensor ready
I (567) led: LED controller initialized
🟢 Distance: 25cm
Step 7: Verify Operation¶
Check LED Test Sequence:
At boot, you should see LEDs cycle through:
Red sweep (left to right)
Green sweep (right to left)
Blue sweep (left to right)
All LEDs off
Check Distance Measurement:
Move hand in front of sensor (10-50cm range)
LED position should track hand movement
Green LED = normal range
Red LED = out of range
Check WiFi:
I (2000) wifi: AP started
I (2100) wifi: SSID: ESP32-Distance-Sensor
I (2200) wifi: Connect to configure
Look for WiFi network “ESP32-Distance-Sensor”
Connect (no password required)
Browser should open captive portal automatically
If not, navigate to
http://192.168.4.1
Step 8: Monitor Serial Output¶
To exit monitor: Press Ctrl+]
Useful monitor commands:
Ctrl+T→Ctrl+R: Reset ESP32Ctrl+T→Ctrl+H: Show help
To monitor without flashing:
idf.py -p /dev/ttyUSB0 monitor
Common Issues & Troubleshooting¶
Build Errors¶
Error: “idf.py not found”
ESP-IDF not sourced in current shell
In Codespaces, this should be automatic
Try opening a new terminal
Error: “Component not found”
Check CMakeLists.txt in main/ and components/
Verify all component directories exist
Run
idf.py fullcleanthen rebuild
Flash Errors¶
Error: “Serial port not found”
ESP32 not connected or detected
Check USB cable (must support data, not just power)
Try different USB port
Check device permissions:
ls -l /dev/ttyUSB0
Error: “Failed to connect to ESP32”
Hold BOOT button while connecting
Press RESET button after
Connecting...messageCheck USB cable and connection
Hardware Issues¶
LEDs not lighting:
Check power supply (USB may be insufficient for 40 LEDs)
Verify GPIO12 connection to DIN
Test with fewer LEDs first
Check LED strip polarity (DIN, not DOUT)
Sensor not responding:
Verify GPIO13/14 connections
Check sensor power (VCC=5V, GND=GND)
Ensure nothing blocking sensor (remove tape, plastic)
Test sensor range (2cm-400cm specification)
WiFi not starting:
Check serial output for errors
Verify antenna is connected (if using external antenna)
Try different WiFi channel (default is auto)
QEMU Issues¶
QEMU won’t start:
Another QEMU instance may be running:
./tools/qemu/stop_qemu.shCheck port conflicts (5555, 5556, 8080)
Review console output for errors
Web interface not accessible:
Verify HTTP proxy is running (should auto-start)
Check port forwarding in Codespaces
Try direct access:
curl http://192.168.100.2
Next Steps¶
Now that your system is running:
Explore the Code - Check out
main/main.cand component sourcesRead Requirements - See Requirements Documentation for specifications
Understand Design - Review Design Specifications for architecture
Join Workshop - (Coming soon) Hands-on exercises and challenges
Customize - Add features, change LED patterns, implement color zones
Useful Commands¶
Build & Flash:
# Clean build
idf.py fullclean
idf.py build
# Flash only (no rebuild)
idf.py -p /dev/ttyUSB0 flash
# Build, flash, and monitor in one command
idf.py -p /dev/ttyUSB0 build flash monitor
Configuration:
# Open menuconfig (TUI configuration)
idf.py menuconfig
# Set target (if needed)
idf.py set-target esp32
Analysis:
# Check memory usage
idf.py size
# Check memory details by component
idf.py size-components
QEMU:
# Run QEMU (no debug)
./tools/qemu/run_qemu.sh
# Run QEMU with debug server
./tools/qemu/run_qemu_debug.sh
# Stop QEMU
./tools/qemu/stop_qemu.sh
# View UART0 output
./tools/qemu/uart0_terminal.sh
Getting Help¶
Documentation:
Development Guide - Development guides (QEMU, debugging, devcontainer)
Requirements Documentation - System requirements
Design Specifications - Design specifications
API Reference - API reference
Community:
GitHub Issues - Report bugs or ask questions
GitHub Discussions - General questions and ideas
ESP-IDF Resources:
Happy Building! 🚀¶
You’re now ready to explore, learn, and customize the ESP32 Distance Sensor project. Have fun experimenting!