An autonomous robotic waste management system that uses computer vision to detect thrown trash and moves a motorized dustbin to intercept it.
The system watches a live camera feed, identifies red-colored trash objects, determines which zone they land in, and drives the dustbin autonomously to that position. Communication between the host computer and the robot is handled over Bluetooth, with an ESP32 microcontroller controlling the DC motors.
- Real-time red object detection using OpenCV and HSV color space filtering
- 4-zone spatial awareness (Front, Back, Left, Right)
- Autonomous movement: forward, backward, and 90° turns
- Bluetooth RFCOMM communication with an ESP32 microcontroller
- Dry-run mode for testing without hardware connected
- Manual keyboard override for direct motor control
- Action cooldown to prevent repeated triggering
- On-screen status overlay and zone visualization
- ESP32 microcontroller
- L298N motor driver
- 2× DC motors (for differential drive)
- Webcam or smartphone camera (USB tethering supported)
- Bluetooth-capable host computer (Linux recommended)
- Power supply for motors
- Python 3.x
- OpenCV (
cv2) - NumPy
- PySerial (
serial) — optional; system runs in dry-run mode without it
Install dependencies:
pip install opencv-python numpy pyserialEdit the constants at the top of the script before running:
| Variable | Default | Description |
|---|---|---|
VIDEO_SRC |
0 |
Camera index |
ESP_MAC |
F8:B3:B7:21:F2:62 |
Bluetooth MAC address of the ESP32 |
RFCOMM_PORT |
/dev/rfcomm0 |
Serial port for Bluetooth |
FORWARD_TIME |
1.0 s |
Duration for forward movement |
BACKWARD_TIME |
1.0 s |
Duration for backward movement |
TURN_90_TIME |
0.5 s |
Duration for a 90° turn |
SIDE_FORWARD_TIME |
1.0 s |
Forward duration after a side turn |
MIN_RED_AREA |
500 px² |
Minimum contour area to count as detection |
ACTION_COOLDOWN |
3.0 s |
Minimum time between actions |
DRY_RUN_IF_NO_SERIAL |
True |
Simulate commands if no serial connection |
sudo python3 esp32_autocar_tracker.py
sudois required for Bluetooth RFCOMM binding on Linux.
- Place the robot in the white box shown at the bottom center of the camera feed.
- Orient it so the front faces upward (toward the green arrow on screen).
- Press Spacebar or type
Gin the terminal to enable detection. - Throw a red object into one of the four colored zones.
- The robot will execute the corresponding movement sequence.
- After the action completes, return the robot to the starting box and re-enable detection.
The camera frame is divided into four detection zones:
┌──────────────────────────┐
│ FRONT │ ← green
├──────┬───────────┬───────┤
│ │ │ │
LEFT │ │ (center) │ │ RIGHT
(cyan) │ │ │ │ (yellow)
│ │ [CAR] │ │
├──────┴───────────┴───────┤
│ BACK │ ← blue
└──────────────────────────┘
| Zone | Movement |
|---|---|
| FRONT | Move forward |
| BACK | Move backward |
| LEFT | Turn 90° left, then move forward |
| RIGHT | Turn 90° right, then move forward |
Single-character commands are sent over serial:
| Command | Action |
|---|---|
U |
Forward |
D |
Backward |
L |
Turn left |
R |
Turn right |
S |
Stop |
| Key | Action |
|---|---|
G / Space |
Enable detection |
W |
Forward |
S |
Backward |
A |
Left |
D |
Right |
X |
Stop |
1 |
Test FRONT zone action |
2 |
Test BACK zone action |
3 |
Test LEFT zone action |
4 |
Test RIGHT zone action |
Q |
Quit |
Camera Feed
│
▼
RedTrashDetector (OpenCV / HSV masking)
│
▼
ZoneManager (centroid → zone mapping)
│
▼
ActionExecutor (hardcoded movement sequence)
│
▼
ESP32AutoConnect (Bluetooth RFCOMM)
│
▼
ESP32 → L298N Motor Driver → DC Motors
No serial connection found The system falls back to dry-run mode automatically. Commands are printed to the console instead of sent over Bluetooth.
Bluetooth bind fails Make sure the ESP32 is powered and paired with the host machine before running. Try releasing any existing binding manually:
sudo rfcomm release /dev/rfcomm0Camera not opening
Change VIDEO_SRC to the correct index (try 1, 2, etc.) or provide a video file path.
False detections
Increase MIN_RED_AREA to filter out small red patches, or adjust RED_LOWER1/RED_UPPER1/RED_LOWER2/RED_UPPER2 to better match your lighting conditions.
- Machine learning-based object recognition to support multiple trash types and colors
- Predictive movement using trajectory estimation
- Additional sensors (ultrasonic, IR) for obstacle avoidance
- Enhanced Bluetooth protocol for higher reliability and feedback
- Web or mobile dashboard for remote monitoring
This project was developed for academic purposes. No license is currently specified.