This waste-collecting robot combines autonomous navigation with computer vision to identify and gather recyclable items. Built around an ESP32 microcontroller, the robot uses ultrasonic distance sensing and IR line tracking to navigate its environment, while an ESP32-CAM with AI processing recognizes waste objects. Dual DC motors drive the wheels, a servo-controlled arm mechanism grips collected items, and an encoder tracks movement distance.
The guide provides a complete parts list, wiring diagram showing motor driver connections and sensor hookups, step-by-step assembly instructions for the chassis and arm mechanism, and annotated firmware that handles motor control, distance measurement, servo positioning, and camera communication. Builders will learn how to calibrate the line-tracking sensors, test the vision recognition pipeline, and tune motor speeds for reliable autonomous operation.
Wiring diagram

Gather all the parts
Assemble it in 8 steps
1. ركّب العجلات والذراعين
ثبت محركي TT في الأمام مع عجلتين متطابقتين، وخلي العجلتين الخلفيتين حرتين. ثبت الذراعين الخفيفتين على السيرفو وثبت لوحة ESP32-CAM والحساس في المنتصف. افصل أذرع السيرفو عن محاورها في أول اختبار حتى تعاير الفتح والغلق بلا ضغط.
2. وصّل الأسلاك والطاقة قبل الاختبار
اتبع مخطط الأسلاك. ركّب مقسّم الجهد قبل ربط Echo باللوحة؛ مقاومة 10 kΩ بين Echo وGPIO13 ومقاومة 15 kΩ بين GPIO13 وGND. وصّل TRIG إلى GPIO8 وإشارتي السيرفو إلى GPIO21 وGPIO9؛ اختبر قبول إشارات 3.3 V قبل تركيب الأذرع. اربط GND تاع الحركة مع GND تاع لوحة الذكاء فقط؛ أرضي تغذية الكاميرا المستقلة يبقى منفصل. غذّ السيرفو ودرايفر المحركات من خرج 5 V منظم يتحمل 3 A على الأقل. غذّ ESP32-S3 عبر USB من نفس المصدر عند التشغيل المستقل.
- قبل التغذية انزع جسور 5V-EN وENA وENB. وصّل GPIO4 بطرف الإشارة فقط في ENA وENB. غذّ طرفي VS و5V في الدرايفر من نفس خرج 5V المنظّم. لا تستعمل 12V.
- طابق أسماء GPIO المطبوعة على ESP32-S3 مع المخطط، ولا تعتمد على ترتيب الأرجل.
- لا توصل Echo مباشرة بالـESP32 ولا تغذّ المحركات من طرف 3V3. افصل تغذية USB المحمولة عن ESP32-S3 قبل توصيل USB الكمبيوتر.
3. حضّر حلبة التجربة
خلّي المسار فارغ وحط قارورة فارغة وصندوق. حضّر الصندوق حسب ما يتعرّف عليه برنامج صاحبك. ثبّت الكاميرا والحساس بحيث القارورة الممسوكة ما تحجبهمش.
- اختبر والعجلات مرفوعة أولاً. لا تستعمله في الطريق العام. الحساس الأمامي لا يرى الجوانب أثناء الدوران. لا تضع عوائق بين الروبوت والصندوق.
4. جهّز درايفر L298N والمحركات
والطاقة مفصولة، انزع الجسور الثلاثة: 5V-EN وENA وENB. وصّل 5V المنظّم إلى طرف 5V (تغذية التحكم) وإلى VS (طرف تغذية المحركات المكتوب عليه +12V في هذه الوحدة، لا تستعمل 12V في هذا المخطط). وصّل GND المشترك. وصّل GPIO4 إلى طرف الإشارة في كل من ENA وENB، وليس إلى الطرف المجاور الموصول بـ5V. وصل محرك اليسار إلى OUT1 وOUT2 واليمين إلى OUT3 وOUT4. اختبر والعجلات مرفوعة قبل التجربة على الأرض.
- الدرايفر ينقص جهد المحركات وقد لا تقلع تحت الحمل مع 5V. أوقف الاختبار إذا توقفت العجلات أو سخن الدرايفر. لا ترفع جهد خط 5V.
5. ركّب حساس دوران العجلة اليسرى
ألصق 12 قطاعاً أبيض و12 قطاعاً أسود بالتناوب داخل العجلة اليسرى وثبّت TCRT5000 قبالتها. غذّه من 5V واضبط برغي الحساسية. وصّل DO عبر 10 kΩ إلى GPIO10، ومن GPIO10 عبر 15 kΩ إلى GND. اترك AO فارغاً. لا يوصل DO مباشرة باللوحة. الحساس يراقب دوران اليسار فقط، ولا يصحّح انحراف الروبوت.
6. اربط لوحة الذكاء بلوحة الحركة
وصّل GPIO17 في S3 إلى RX في لوحة صاحبك، وTX منها إلى GPIO16 في S3، واربط GND مع GND. صاحبك يحدد أرجل TX وRX من برنامجه. استعمل إشارات 3.3V فقط وغذّ لوحة صاحبك عبر منفذ USB تاعها للتجربة دون ربط خطي التغذية. اضبط UART على 9600 8N1 ورسائل من حرف واحد. عند طلب ? ردّ Y للقارورة أو N للرفض خلال 4.5 ثوانٍ. عند طلب B ردّ خلال ثانيتين بحرف L لليسار أو R لليمين أو F للأمام أو M إذا الصندوق ما بانش.
- حدّث ESP32-S3 فقط. لا تستبدل برنامج الذكاء الاصطناعي. اختبر الاتصال والعجلات مرفوعة باستعمال G على سرعة 115200 في نافذة Serial؛ أرسل X للتوقف.
7. ركّب لوحة ESP32-CAM مستقلة
خلّي الكاميرا مركبة في ESP32-CAM. غذّ هذه اللوحة من محوّل USB 5V مستقل باستعمال وصلة تفصل الموجب والسالب بوضوح، الموجب إلى 5V والسالب إلى GND الخاص بها. ما تربطش أرجل الكاميرا أو UART تاعها بلوحة الحركة. الربط المقترح للصور هو Wi-Fi بين ESP32-CAM وESP32-S3 تاع الذكاء الاصطناعي. صاحبك لازم يتأكد أن برنامج الكاميرا يرسل الصور وأن برنامج الذكاء يستقبلها بنفس الطريقة؛ المخطط ما يضيفش هذه الوظيفة للبرنامجين.
8. اختبر مسار الصورة قبل تشغيل المحركات
المسار: ESP32-CAM ترسل الصور عبر Wi-Fi إلى S3 تاع الذكاء، وS3 تاع الذكاء يرد على S3 تاع الحركة عبر UART. ما كاش سلك للصور. صاحبك يضبط البرنامجين على نفس الشبكة وعنوان بث الصور وإعداداته حسب برنامجه. تأكد أولاً أنه يستقبل صورة حية، ثم اختبر طلب ? ورد Y أو N، وبعده طلب B ورد الاتجاه والعجلات مرفوعة.
Review all connections
1. Connections between "sonar" and "ESP32"
2. Connections between "driver" and "ESP32"
3. Connections between "sleep" and "ESP32"
4. Connections between "left" and "ESP32"
5. Connections between "right" and "ESP32"
6. Connections between "cam" and "ESP32"
7. Connections between "supply" and "ESP32"
8. Connections between "armL" and "ESP32"
9. Connections between "armR" and "ESP32"
10. Connections between "encL" and "ESP32"
11. Connections between "echoTop" and "ESP32"
12. Connections between "echoBottom" and "ESP32"
13. Connections between "encTop" and "ESP32"
14. Connections between "encBottom" and "ESP32"
15. Connections between "cameraBoard" and "ESP32"
16. Connections between "cameraSupply" and "ESP32"
Deploy the firmware
#include <Arduino.h>
HardwareSerial camUart(2);
// GPIO4 enables both L298N channels via the shared ENA/ENB wire.
constexpr int en=4, trg=8, echo=13;
constexpr int encoder=10;
constexpr int motor[2][2]={{5,6},{7,14}};
constexpr int servoR=9;
volatile int ticks=0;
void IRAM_ATTR enc0(){++ticks;}
void drive(int i,int v){analogWrite(motor[i][v<0?0:1],0);analogWrite(motor[i][v<0?1:0],abs(v));}
void stop(){digitalWrite(en,LOW);drive(0,0);drive(1,0);}
// Approximate endpoints; adjust with horns disconnected first.
void arms(bool close){ledcWrite(21,close?117:77);ledcWrite(servoR,close?77:117);}
int cm(){digitalWrite(trg,HIGH);delayMicroseconds(12);digitalWrite(trg,LOW);auto t=pulseIn(echo,HIGH,22000);return t?t/58:0;}
void setup(){
Serial.begin(115200);
Serial.println("Controller idle; send G to run one trip");
}
void controllerInit(){
static bool initialized=false;if(initialized)return;initialized=true;
pinMode(en,OUTPUT);stop();pinMode(trg,OUTPUT);pinMode(echo,INPUT);
pinMode(encoder,INPUT);
attachInterrupt(encoder,enc0,FALLING);
ledcAttach(21,50,11);ledcAttach(servoR,50,11);
camUart.begin(9600,SERIAL_8N1,16,17);
}
bool recognized(){
while(camUart.available())camUart.read();camUart.write('?');
for(uint32_t t=millis();millis()-t<4500;){int r=camUart.read();if(r=='Y')return true;if(r=='N'||Serial.read()=='X')return false;delay(5);}return false;
}
char binRequest(){
while(camUart.available())camUart.read();camUart.write('B');
for(uint32_t t=millis();millis()-t<2000;){
if(Serial.read()=='X')return 0;
int r=camUart.read();if(r=='M'||r=='L'||r=='F'||r=='R')return r;delay(5);
}
return 0;
}
// Stop between camera observations; never drive forward without a sonar echo.
void deliver(){
int aligned=0;
for(uint32_t t=millis();millis()-t<25000;){
char r=binRequest();if(!r)break;
int d=cm();
if(d>0&&d<8)break;
if(r=='F'&&d>=8&&d<=16){
if(++aligned>=2){arms(false);Serial.println("Bin reached; jaws open");return;}
delay(70);continue;
}
aligned=0;
if(r=='F'&&d==0)break;
if(r!='F'&&d>0&&d<=16)break;
int l=r=='L'?-175:175, rr=(r=='R'||r=='M')?-175:175;
digitalWrite(en,HIGH);drive(0,l);drive(1,rr);
for(uint32_t start=millis();millis()-start<(r=='M'?180:100);){
if(Serial.read()=='X'){stop();return;}delay(5);
}
stop();delay(100);
}
stop();Serial.println("Bin not reached; jaws stay closed");
}
// Single encoder checks movement on the left only.
void trip(){
controllerInit();arms(false);delay(650);
int origin=ticks;int range=0;bool found=false;int near=0;
digitalWrite(en,HIGH);
for(uint32_t t=millis();millis()-t<6500;){
if(Serial.read()=='X'){stop();return;}
range=cm();if(range>0&&range<6){stop();Serial.println("Obstacle too close");return;}
if(range>0&&range<=16){stop();if(++near>=2){found=true;break;}delay(70);continue;}
near=0;digitalWrite(en,HIGH);
drive(0,160);drive(1,160);
if(millis()-t>900&&ticks==origin){stop();Serial.println("Check left encoder / motor");return;}
delay(70);
}
stop();
if(!found){Serial.println("No bottle in range");return;}
if(!recognized()){Serial.println("Object rejected; stopped");return;}
arms(true);
for(uint32_t t=millis();millis()-t<650;){if(Serial.read()=='X')return;delay(5);}
deliver();
}
void loop(){
if(Serial.read()=='G')trip();
delay(5);
}Remix this project
Make it yours in one click
Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.




