Smart Industrial AGV System Complete Circuit Wiring, Operations, Practical Applications & Embedded C++ Code 1. Circuit Pin Mapping & Wiring Matrix Module Module Pin ESP32 GPIO Wire Color Signal Description MFRC522 RFID 3.3V / GND 3.3V / GND Red / Black Power Supply RST GPIO 4 Orange Reset Control SDA (SS) GPIO 5 Yellow SPI Chip Select MOSI GPIO 23 Blue SPI MOSI MISO GPIO 19 Green SPI MISO SCK GPIO 18 Yellow SPI Clock LCD 20x4 (I2C) VCC / GND 5V / GND Red / Black 5V Power SDA / SCL GPIO 21 / 22 Blue / Yellow I2C Communication HC-SR04 Sensor VCC / GND 5V / GND Red / Black 5V Power TRIG / ECHO GPIO 13 / 12 Orange / Green Ultrasonic Trigger & Echo A4988 Driver VDD / VMOT 3.3V / 12V Red Logic & Motor Power Supply STEP / DIR GPIO 14 / 27 Blue / Yellow Step Pulse & Direction Control Indicators Piezo Buzzer GPIO 26 Red Audio Alarm Signal Red E-STOP LED GPIO 25 Red Visual Warning Light 2. Circuit Operation & System Flow Initialization: System boots, initializes SPI (RFID), I2C (LCD 2004), and GPIO pins. LCD displays system boot status. Path Navigation: ESP32 outputs continuous pulses to A4988 driver via GPIO 14, causing the NEMA 17 motor to rotate smoothly. Station Detection: MFRC522 scans floor RFID/NFC tags. Upon detecting Station A UID, the stepper motor stops for material unloading. Obstacle Avoidance: HC-SR04 measures obstacle distance continuously. If an object is detected (< 20 cm), the system triggers an emergency stop (E-STOP), sounding the buzzer and flashing the LED until the path clears. 3. Real-World Practical Applications CNC Workshops: Automatic transfer of raw materials and machined parts between milling/lathe stations. Smart Warehouses: Autonomous pallet transport and material sorting along magnetic/RFID floor tracks. Automotive Assembly: Transporting component trays straight to specialized assembly stations. 4. Complete Final Firmware Code (ESP32 C++) Below is the complete C++ firmware controlling the entire AGV simulation system: #include <SPI.h> #include <MFRC522.h> #include <Wire.h> #include <LiquidCrystal_I2C.h> // Pin Definitions #define SS_PIN 5 #define RST_PIN 4 • • • • • • • Smart AGV System — Final Technical Documentation Page 1 of 3 #define TRIG_PIN 13 #define ECHO_PIN 12 #define STEP_PIN 14 #define DIR_PIN 27 #define BUZZER_PIN 26 #define LED_PIN 25 // Instances MFRC522 rfid(SS_PIN, RST_PIN); LiquidCrystal_I2C lcd(0x27, 20, 4); void setup() { Serial.begin(115200); SPI.begin(); rfid.PCD_Init(); lcd.init(); lcd.backlight(); pinMode(TRIG_PIN, OUTPUT); pinMode(ECHO_PIN, INPUT); pinMode(STEP_PIN, OUTPUT); pinMode(DIR_PIN, OUTPUT); pinMode(BUZZER_PIN, OUTPUT); pinMode(LED_PIN, OUTPUT); digitalWrite(DIR_PIN, HIGH); // Forward direction lcd.setCursor(0, 0); lcd.print("SMART AGV SYSTEM"); lcd.setCursor(0, 1); lcd.print("INITIALIZING..."); delay(2000); lcd.clear(); } long getDistance() { digitalWrite(TRIG_PIN, LOW); delayMicroseconds(2); digitalWrite(TRIG_PIN, HIGH); delayMicroseconds(10); digitalWrite(TRIG_PIN, LOW); long duration = pulseIn(ECHO_PIN, HIGH, 30000); // 30ms timeout if (duration == 0) return 999; return duration * 0.034 / 2; } void loop() { long distance = getDistance(); // 1. Obstacle Detection (E-STOP) if (distance > 0 && distance < 20) { digitalWrite(BUZZER_PIN, HIGH); digitalWrite(LED_PIN, HIGH); lcd.setCursor(0, 0); lcd.print("E-STOP: OBSTACLE "); lcd.setCursor(0, 1); lcd.print("OBJECT DETECTED! "); delay(200); return; // Halt stepper motion } else { digitalWrite(BUZZER_PIN, LOW); digitalWrite(LED_PIN, LOW); } // 2. Station Detection (RFID Scan) if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) { digitalWrite(BUZZER_PIN, HIGH); delay(100); digitalWrite(BUZZER_PIN, LOW); lcd.setCursor(0, 0); lcd.print("STATION A DETECTED!"); lcd.setCursor(0, 1); Smart AGV System — Final Technical Documentation Page 2 of 3 lcd.print("UNLOADING MAT... "); delay(5000); // Wait for unloading rfid.PICC_HaltA(); rfid.PCD_StopCrypto1(); lcd.clear(); } // 3. Normal Path Tracking Motion lcd.setCursor(0, 0); lcd.print("STATUS: MOVING "); lcd.setCursor(0, 1); lcd.print("SCANNING TAGS... "); digitalWrite(STEP_PIN, HIGH); delayMicroseconds(800); digitalWrite(STEP_PIN, LOW); delayMicroseconds(800); } Smart AGV System — Final Technical Documentation Page 3 of 3