An autonomous ESP32-based robot that tracks and follows gingerbread cookies using computer vision!
- Keyboard Control: WASD or Arrow keys for driving
- Hand Tracking: Control with hand gestures via webcam
- Gingerbread Tracking: Browser-based color tracking
Server-side Python autonomous tracking with OpenCV:
- Search Left/Right: Robot spins to search for gingerbread
- Track Mode: Automatically follows detected gingerbread
- Real-time Vision: Python popup window shows detection overlay
- Multi-client Control: Trigger autonomous modes from any connected device
Browser UI โโ Node.js Server โโ Python (OpenCV) โโ ESP32 Robot
โ
OpenCV Window (Visual Feedback)
npm installpip3 install -r requirements.txtRequirements:
opencv-python- Computer visionnumpy- Array operations
Upload controller.c to your ESP32 using Arduino IDE or PlatformIO.
Configure WiFi credentials in the code:
static const char* WIFI_SSID = "YOUR_WIFI";
static const char* WIFI_PASS = "YOUR_PASSWORD";node server.jsServer will start on:
- Local:
http://localhost:3000 - Network:
http://<your-ip>:3000
- Open the web interface
- Enter your ESP32's IP address
- Click "INITIATE CONNECTION"
- Use on-screen buttons or keyboard (WASD/Arrows)
- Press
Ffor fire (relay toggle) - Press
SPACEfor emergency stop
-
Click ๐ช GINGERBREAD button
-
Choose an autonomous mode:
- ๐ SEARCH LEFT: Robot spins counterclockwise until gingerbread is found
- ๐ SEARCH RIGHT: Robot spins clockwise until gingerbread is found
- ๐ฏ TRACK: Directly enters tracking mode (if gingerbread visible)
- โฌ STOP: Emergency stop autonomous mode
-
Python process starts on server with OpenCV window showing:
- Live camera feed
- Detection overlay
- Deadzone visualization
- Current mode status
-
Keyboard controls in Python window:
L- Switch to Search LeftR- Switch to Search RightT- Switch to Track modeS- StopESC- Exit autonomous mode
- Search Mode: Robot spins until brown (gingerbread) object is detected
- Auto-Switch: Automatically switches from Search โ Track when target found
- Lost Target: If target lost for 2 seconds, switches back to Search Left
- Deadzone: 30% center deadzone - robot goes straight when target is centered
- Differential Steering: Smooth turning based on target position
LEFT MOTOR: DIR=15, STEP=2
RIGHT MOTOR: DIR=17, STEP=5
ENABLE: PIN=33 (active-low)
RELAY (FIRE): PIN=13
- ESP32 Dev Board
- 2x Stepper Motor Drivers (e.g., A4988, DRV8825)
- 2x Stepper Motors
- Relay Module (optional, for firing mechanism)
- Power Supply (appropriate for your motors)
- USB Webcam or Laptop camera (for autonomous mode)
To adjust gingerbread detection for your specific lighting/cookie:
Edit autonomous_gingerbread.py:
# Line ~235 - Adjust HSV color range
lower_brown = np.array([8, 60, 60]) # H, S, V lower bounds
upper_brown = np.array([25, 255, 200]) # H, S, V upper boundsHSV Color Guide:
- H (Hue): 8-25 for brown/orange tones
- S (Saturation): 60-255 for color intensity
- V (Value): 60-200 for brightness range
- HTTP/WebSocket: 3000 (configurable in
server.js) - ESP32 UDP: 4210 (default)
Ensure these ports are open:
- TCP 3000 (Node.js server)
- UDP 4210 (ESP32 communication)
# List available cameras
python3 -c "import cv2; print([i for i in range(10) if cv2.VideoCapture(i).isOpened()])"
# Try different camera index
python3 autonomous_gingerbread.py --camera 1 --esp32-ip <IP>- Check lighting conditions
- Adjust HSV color ranges in code
- Ensure minimum blob size threshold is appropriate
- Test with actual gingerbread (brown/tan color)
- Check WiFi connection and IP address
- Verify ESP32 is on same network
- Check UDP port (4210)
- Test with manual control mode first
- Ensure Node.js server is running
- Check firewall settings
- Verify network allows WebSocket connections
Gingerbread/
โโโ autonomous_gingerbread.py # Python autonomous tracking
โโโ server.js # Node.js WebSocket/UDP server
โโโ controller.c # ESP32 firmware
โโโ package.json # Node.js dependencies
โโโ requirements.txt # Python dependencies
โโโ public/
โโโ index.html # Web UI
โโโ app.js # Client JavaScript
โโโ styles.css # Styling
- Add mode to
Modeenum inautonomous_gingerbread.py - Implement behavior in main control loop
- Add button to
index.html - Add event handler in
app.js
Created for EEZY robotics platform
MIT License - Feel free to use and modify!
๐ช Happy Gingerbread Hunting! ๐ค