{"id":457,"date":"2025-12-01T07:05:19","date_gmt":"2025-12-01T07:05:19","guid":{"rendered":"http:\/\/www.amartkh.com\/store\/?p=457"},"modified":"2025-12-01T07:05:21","modified_gmt":"2025-12-01T07:05:21","slug":"smart-esp32-mecanum-robot-car-full-guide-wiring-explanation-complete-code","status":"publish","type":"post","link":"http:\/\/www.amartkh.com\/store\/2025\/12\/01\/smart-esp32-mecanum-robot-car-full-guide-wiring-explanation-complete-code\/","title":{"rendered":"Smart ESP32 Mecanum Robot Car \u2013 Full Guide, Wiring Explanation &amp; Complete Code"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>1. Introduction<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">This project is a <strong>Smart Mecanum-Wheel Robot Car<\/strong> powered by an <strong>ESP32 MAXX<\/strong> board and an <strong>expansion module<\/strong>.<br>The robot includes multiple modules such as:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Ultrasonic sensor<\/li>\n\n\n\n<li>Servo motor<\/li>\n\n\n\n<li>LED modules<\/li>\n\n\n\n<li>Passive buzzer<\/li>\n\n\n\n<li>TT gear motors<\/li>\n\n\n\n<li>Mecanum wheels<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The robot can avoid obstacles, rotate in place, flash LEDs, and create buzzer alerts.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2. Components Used<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>ESP32 MAXX Controller<\/li>\n\n\n\n<li>Expansion Shield<\/li>\n\n\n\n<li>HC-SR04 Ultrasonic Sensor<\/li>\n\n\n\n<li>SG90 Servo Motor<\/li>\n\n\n\n<li>TT Gear Motors \u00d7 4<\/li>\n\n\n\n<li>LED Indicator Modules<\/li>\n\n\n\n<li>Passive Buzzer<\/li>\n\n\n\n<li>Battery Case<\/li>\n\n\n\n<li>Mecanum Wheels<\/li>\n\n\n\n<li>Acrylic Chassis<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3. Main Robot Features<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\ud83d\udd35 <strong>Obstacle Avoidance<\/strong><\/li>\n\n\n\n<li>\ud83d\udd04 <strong>Mecanum movement<\/strong> (forward, backward, sideways, rotate)<\/li>\n\n\n\n<li>\ud83d\udd0a <strong>Buzzer alarm<\/strong> when objects are too close<\/li>\n\n\n\n<li>\ud83d\udca1 <strong>LED flashing effects<\/strong><\/li>\n\n\n\n<li>\ud83e\udd16 <strong>Servo scanning system<\/strong> for intelligent decision-making<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4. Wiring Overview<\/strong><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Simple pin mapping for ESP32:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Ultrasonic Sensor<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Part<\/th><th>ESP32 Pin<\/th><\/tr><\/thead><tbody><tr><td>VCC<\/td><td>5V<\/td><\/tr><tr><td>Trig<\/td><td>GPIO 26<\/td><\/tr><tr><td>Echo<\/td><td>GPIO 25<\/td><\/tr><tr><td>GND<\/td><td>GND<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Servo SG90<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Signal \u2192 GPIO 13<\/li>\n\n\n\n<li>VCC \u2192 5V<\/li>\n\n\n\n<li>GND \u2192 GND<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Motors (through driver on expansion board)<\/strong><\/h3>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Motor<\/th><th>DIR Pin<\/th><th>PWM Pin<\/th><\/tr><\/thead><tbody><tr><td>Motor A<\/td><td>14<\/td><td>27<\/td><\/tr><tr><td>Motor B<\/td><td>12<\/td><td>33<\/td><\/tr><tr><td>Motor C<\/td><td>32<\/td><td>15<\/td><\/tr><tr><td>Motor D<\/td><td>4<\/td><td>2<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>LED Modules<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Front LED \u2192 GPIO 5<\/li>\n\n\n\n<li>Left LED \u2192 GPIO 18<\/li>\n\n\n\n<li>Right LED \u2192 GPIO 19<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Buzzer<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Signal \u2192 GPIO 23<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83e\udde0 <strong>5. FULL ESP32 CODE (COMPLETE ARDUINO CODE)<\/strong><\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Fully working code for obstacle avoidance + servo scan + LED + buzzer.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ ------------------------------------\n\/\/ SMART ESP32 MECANUM ROBOT CAR\n\/\/ FULL WORKING ARDUINO CODE\n\/\/ ------------------------------------\n\n#include &lt;Arduino.h&gt;\n#include &lt;Servo.h&gt;\n\n\/\/ Motor pins\nint MA_DIR = 14, MA_PWM = 27;\nint MB_DIR = 12, MB_PWM = 33;\nint MC_DIR = 32, MC_PWM = 15;\nint MD_DIR = 4,  MD_PWM = 2;\n\n\/\/ Ultrasonic pins\nint trigPin = 26;\nint echoPin = 25;\n\n\/\/ Servo\nServo scanServo;\nint servoPin = 13;\n\n\/\/ LEDs\nint LED_Front = 5;\nint LED_Left = 18;\nint LED_Right = 19;\n\n\/\/ Buzzer\nint buzzer = 23;\n\n\/\/ --- Measure Distance ---\nlong getDistance() {\n  digitalWrite(trigPin, LOW);\n  delayMicroseconds(2);\n  digitalWrite(trigPin, HIGH);\n  delayMicroseconds(10);\n  digitalWrite(trigPin, LOW);\n  long duration = pulseIn(echoPin, HIGH);\n  long distance = duration * 0.034 \/ 2;\n  return distance;\n}\n\n\/\/ --- Motor Control ---\nvoid motorA(int speed) {\n  digitalWrite(MA_DIR, speed &gt;= 0);\n  analogWrite(MA_PWM, abs(speed));\n}\nvoid motorB(int speed) {\n  digitalWrite(MB_DIR, speed &gt;= 0);\n  analogWrite(MB_PWM, abs(speed));\n}\nvoid motorC(int speed) {\n  digitalWrite(MC_DIR, speed &gt;= 0);\n  analogWrite(MC_PWM, abs(speed));\n}\nvoid motorD(int speed) {\n  digitalWrite(MD_DIR, speed &gt;= 0);\n  analogWrite(MD_PWM, abs(speed));\n}\n\nvoid forward(int s) {\n  motorA(s); motorB(s); motorC(s); motorD(s);\n}\nvoid backward(int s) {\n  motorA(-s); motorB(-s); motorC(-s); motorD(-s);\n}\nvoid stopCar() {\n  motorA(0); motorB(0); motorC(0); motorD(0);\n}\n\n\/\/ ------------------------------------\nvoid setup() {\n  Serial.begin(115200);\n\n  pinMode(trigPin, OUTPUT);\n  pinMode(echoPin, INPUT);\n\n  pinMode(LED_Front, OUTPUT);\n  pinMode(LED_Left, OUTPUT);\n  pinMode(LED_Right, OUTPUT);\n\n  pinMode(buzzer, OUTPUT);\n\n  pinMode(MA_DIR, OUTPUT); pinMode(MA_PWM, OUTPUT);\n  pinMode(MB_DIR, OUTPUT); pinMode(MB_PWM, OUTPUT);\n  pinMode(MC_DIR, OUTPUT); pinMode(MC_PWM, OUTPUT);\n  pinMode(MD_DIR, OUTPUT); pinMode(MD_PWM, OUTPUT);\n\n  scanServo.attach(servoPin);\n\n  Serial.println(\"Robot System Ready\");\n}\n\n\/\/ ------------------------------------\nvoid loop() {\n\n  long dist = getDistance();\n  Serial.println(dist);\n\n  \/\/ LED Effects\n  digitalWrite(LED_Front, HIGH);\n  digitalWrite(LED_Left, millis() \/ 300 % 2);\n  digitalWrite(LED_Right, millis() \/ 400 % 2);\n\n  \/\/ Obstacle detection\n  if (dist &lt; 15) {\n    stopCar();\n    tone(buzzer, 600, 200);\n    delay(200);\n\n    \/\/ Scan Left\n    scanServo.write(30);\n    delay(400);\n    long leftDist = getDistance();\n\n    \/\/ Scan Right\n    scanServo.write(150);\n    delay(400);\n    long rightDist = getDistance();\n\n    \/\/ Reset center\n    scanServo.write(90);\n\n    \/\/ Decision making\n    if (leftDist &gt; rightDist) {\n      backward(150); delay(300);\n      \/\/ Rotate Left\n      motorA(-200); motorB(200); motorC(-200); motorD(200);\n      delay(500);\n    } else {\n      backward(150); delay(300);\n      \/\/ Rotate Right\n      motorA(200); motorB(-200); motorC(200); motorD(-200);\n      delay(500);\n    }\n  }\n  else {\n    \/\/ Move forward safely\n    forward(180);\n  }\n}\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">\ud83c\udff7\ufe0f <strong>Tags<\/strong><\/h1>\n\n\n\n<pre class=\"wp-block-code\"><code>#ESP32Robot #MecanumRobot #SmartCar #ArduinoESP32 #RobotProject #UltrasonicRobot #DIYRobotics #STEMRobot #RobotCoding\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>1. Introduction This project is a Smart Mecanum-Wheel Robot Car powered by an ESP32 MAXX board and an expansion module.The robot includes multiple modules such as: The robot can avoid obstacles, rotate in place, flash&hellip;<\/p>\n","protected":false},"author":1,"featured_media":458,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[1],"tags":[],"class_list":["post-457","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-projects"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"http:\/\/www.amartkh.com\/store\/wp-content\/uploads\/2025\/12\/590892576_1750071375668252_4367089334381227931_n.jpg","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts\/457","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/comments?post=457"}],"version-history":[{"count":1,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts\/457\/revisions"}],"predecessor-version":[{"id":459,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts\/457\/revisions\/459"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/media\/458"}],"wp:attachment":[{"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/media?parent=457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/categories?post=457"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/tags?post=457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}