{"id":369,"date":"2025-08-15T02:20:12","date_gmt":"2025-08-15T02:20:12","guid":{"rendered":"http:\/\/www.amartkh.com\/store\/?p=369"},"modified":"2025-08-15T02:22:04","modified_gmt":"2025-08-15T02:22:04","slug":"how-to-make-a-diy-arduino-obstacle-avoiding-car-at-home","status":"publish","type":"post","link":"http:\/\/www.amartkh.com\/store\/2025\/08\/15\/how-to-make-a-diy-arduino-obstacle-avoiding-car-at-home\/","title":{"rendered":"How To Make A DIY Arduino Obstacle Avoiding Car At Home?"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Alright \u2014 let\u2019s walk through building a <strong>DIY Arduino Obstacle Avoiding Car<\/strong> step-by-step.<br>I\u2019ll give you the <strong>parts list<\/strong>, <strong>wiring diagram explanation<\/strong>, <strong>Arduino code<\/strong>, and <strong>how it works<\/strong> so you can make it at home.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>1. Parts You\u2019ll Need<\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Component<\/th><th>Quantity<\/th><th>Purpose<\/th><\/tr><\/thead><tbody><tr><td>Arduino UNO (or Nano)<\/td><td>1<\/td><td>Main controller<\/td><\/tr><tr><td>Ultrasonic Sensor (HC-SR04)<\/td><td>1<\/td><td>Distance measurement<\/td><\/tr><tr><td>Servo Motor (SG90)<\/td><td>1<\/td><td>Rotates the sensor for scanning<\/td><\/tr><tr><td>L298N Motor Driver Module<\/td><td>1<\/td><td>Controls DC motors<\/td><\/tr><tr><td>DC Motors with Wheels<\/td><td>2\u20134<\/td><td>Movement<\/td><\/tr><tr><td>Caster wheel<\/td><td>1<\/td><td>Support<\/td><\/tr><tr><td>Chassis (DIY or ready-made)<\/td><td>1<\/td><td>Body frame<\/td><\/tr><tr><td>Jumper wires<\/td><td>\u2014<\/td><td>Connections<\/td><\/tr><tr><td>Battery pack (6V\u201312V)<\/td><td>1<\/td><td>Power supply<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>2. Wiring Connections<\/strong><\/h2>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Ultrasonic Sensor (HC-SR04) \u2192 Arduino<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>VCC \u2192 5V<\/li>\n\n\n\n<li>GND \u2192 GND<\/li>\n\n\n\n<li>TRIG \u2192 D9<\/li>\n\n\n\n<li>ECHO \u2192 D10<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Servo Motor \u2192 Arduino<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Signal \u2192 D11<\/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>L298N Motor Driver \u2192 Arduino<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>IN1 \u2192 D2<\/li>\n\n\n\n<li>IN2 \u2192 D3<\/li>\n\n\n\n<li>IN3 \u2192 D4<\/li>\n\n\n\n<li>IN4 \u2192 D5<\/li>\n\n\n\n<li>ENA \u2192 5V (or PWM pin if speed control)<\/li>\n\n\n\n<li>ENB \u2192 5V<\/li>\n\n\n\n<li>Motor A \u2192 Left motor<\/li>\n\n\n\n<li>Motor B \u2192 Right motor<\/li>\n\n\n\n<li>L298N VCC \u2192 Battery + (6\u201312V)<\/li>\n\n\n\n<li>L298N GND \u2192 Battery \u2013 &amp; Arduino GND<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<figure class=\"wp-block-jetpack-image-compare\"><div class=\"juxtapose\" data-mode=\"horizontal\"><img fetchpriority=\"high\" decoding=\"async\" id=\"370\" src=\"https:\/\/i0.wp.com\/www.amartkh.com\/store\/wp-content\/uploads\/2025\/08\/d8629382-373c-4400-9851-c7c829337f0c.png\" alt=\"\" width=\"1536\" height=\"1024\" class=\"image-compare__image-before\"\/><img decoding=\"async\" id=\"370\" src=\"https:\/\/i0.wp.com\/www.amartkh.com\/store\/wp-content\/uploads\/2025\/08\/d8629382-373c-4400-9851-c7c829337f0c.png\" alt=\"\" width=\"1536\" height=\"1024\" class=\"image-compare__image-after\"\/><\/div><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>3. Arduino Code<\/strong><\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#include &lt;Servo.h&gt;\n\nServo myServo;\n#define trigPin 9\n#define echoPin 10\n#define servoPin 11\n\n#define IN1 2\n#define IN2 3\n#define IN3 4\n#define IN4 5\n\nlong distance;\nlong duration;\n\nvoid setup() {\n  Serial.begin(9600);\n  myServo.attach(servoPin);\n  \n  pinMode(trigPin, OUTPUT);\n  pinMode(echoPin, INPUT);\n  \n  pinMode(IN1, OUTPUT);\n  pinMode(IN2, OUTPUT);\n  pinMode(IN3, OUTPUT);\n  pinMode(IN4, OUTPUT);\n}\n\nlong getDistance() {\n  digitalWrite(trigPin, LOW);\n  delayMicroseconds(2);\n  digitalWrite(trigPin, HIGH);\n  delayMicroseconds(10);\n  digitalWrite(trigPin, LOW);\n  duration = pulseIn(echoPin, HIGH);\n  return duration * 0.034 \/ 2; \/\/ Convert to cm\n}\n\nvoid forward() {\n  digitalWrite(IN1, HIGH);\n  digitalWrite(IN2, LOW);\n  digitalWrite(IN3, HIGH);\n  digitalWrite(IN4, LOW);\n}\n\nvoid backward() {\n  digitalWrite(IN1, LOW);\n  digitalWrite(IN2, HIGH);\n  digitalWrite(IN3, LOW);\n  digitalWrite(IN4, HIGH);\n}\n\nvoid left() {\n  digitalWrite(IN1, LOW);\n  digitalWrite(IN2, HIGH);\n  digitalWrite(IN3, HIGH);\n  digitalWrite(IN4, LOW);\n}\n\nvoid right() {\n  digitalWrite(IN1, HIGH);\n  digitalWrite(IN2, LOW);\n  digitalWrite(IN3, LOW);\n  digitalWrite(IN4, HIGH);\n}\n\nvoid stopCar() {\n  digitalWrite(IN1, LOW);\n  digitalWrite(IN2, LOW);\n  digitalWrite(IN3, LOW);\n  digitalWrite(IN4, LOW);\n}\n\nvoid loop() {\n  myServo.write(90); \/\/ Forward facing\n  delay(200);\n  distance = getDistance();\n  \n  if (distance &gt; 20) {\n    forward();\n  } else {\n    stopCar();\n    delay(300);\n    \n    myServo.write(0); \/\/ Scan left\n    delay(500);\n    long leftDist = getDistance();\n    \n    myServo.write(180); \/\/ Scan right\n    delay(500);\n    long rightDist = getDistance();\n    \n    myServo.write(90); \/\/ Reset center\n    \n    if (leftDist &gt; rightDist) {\n      left();\n      delay(500);\n    } else {\n      right();\n      delay(500);\n    }\n  }\n}\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>4. How It Works<\/strong><\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The <strong>servo motor<\/strong> rotates the <strong>ultrasonic sensor<\/strong> to scan front, left, and right.<\/li>\n\n\n\n<li>The <strong>Arduino<\/strong> measures distances using the <strong>HC-SR04<\/strong> sensor.<\/li>\n\n\n\n<li>If the path is clear, the car moves <strong>forward<\/strong>.<\/li>\n\n\n\n<li>If there\u2019s an obstacle, it <strong>stops<\/strong>, looks <strong>left<\/strong> and <strong>right<\/strong>, then chooses the side with more space.<\/li>\n\n\n\n<li><strong>Motor driver<\/strong> powers the DC motors based on Arduino signals.<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>5. Tips<\/strong><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Use a <strong>rechargeable Li-ion battery<\/strong> for better performance.<\/li>\n\n\n\n<li>Reduce <strong>servo movement delays<\/strong> for faster reaction.<\/li>\n\n\n\n<li>Add LEDs to indicate movement direction for fun.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Alright \u2014 let\u2019s walk through building a DIY Arduino Obstacle Avoiding Car step-by-step.I\u2019ll give you the parts list, wiring diagram explanation, Arduino code, and how it works so you can make it at home. 1.&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"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":false,"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-369","post","type-post","status-publish","format-standard","hentry","category-projects"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts\/369","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=369"}],"version-history":[{"count":2,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts\/369\/revisions"}],"predecessor-version":[{"id":372,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/posts\/369\/revisions\/372"}],"wp:attachment":[{"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/media?parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/categories?post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.amartkh.com\/store\/wp-json\/wp\/v2\/tags?post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}