{"id":869,"date":"2026-06-12T15:55:48","date_gmt":"2026-06-12T07:55:48","guid":{"rendered":"https:\/\/projectleon.net\/make\/blog\/obstacle-avoidance-hcsr04-ir-ugv-collision-avoidance-farsi\/"},"modified":"2026-06-12T15:55:49","modified_gmt":"2026-06-12T07:55:49","slug":"obstacle-avoidance-hcsr04-ir-ugv-collision-avoidance-farsi","status":"publish","type":"post","link":"https:\/\/projectleon.net\/make\/blog\/obstacle-avoidance-hcsr04-ir-ugv-collision-avoidance-farsi\/","title":{"rendered":"Obstacle Avoidance \u0628\u0627 HC-SR04 \u0648 IR \u0628\u0631\u0627\u06cc UGV \u2014 \u062c\u0644\u0648\u06af\u06cc\u0631\u06cc \u0627\u0632 \u0628\u0631\u062e\u0648\u0631\u062f (\u0641\u0627\u0631\u0633\u06cc)"},"content":{"rendered":"<div class='hero-image-container' style='margin-bottom:28px;border-radius:14px;overflow:hidden;box-shadow:0 4px 18px rgba(0,0,0,0.08)'>\n<img src='https:\/\/projectleon.net\/make\/wp-content\/uploads\/2026\/06\/post184-obstacle-avoidance-ugv.jpg' alt='Obstacle Avoidance UGV HC-SR04 \u0633\u0648\u0646\u0627\u0631 IR' style='width:100%;height:auto;display:block' loading='eager'\/>\n<\/div>\n<div class='beginner-intro' style='background:#f0f7ff;border-right:4px solid #2e5fb6;padding:16px 20px;border-radius:10px;margin-bottom:22px'>\n<h2 style='margin-top:0'>\u0627\u062c\u062a\u0646\u0627\u0628 \u0627\u0632 \u0645\u0648\u0627\u0646\u0639 \u2014 \u062d\u0633 \u06f6\u0645 \u0631\u0628\u0627\u062a<\/h2>\n<p><strong>HC-SR04<\/strong> \u06cc\u06a9 \u0633\u0648\u0646\u0627\u0631 \u0627\u0648\u0644\u062a\u0631\u0627\u0633\u0648\u0646\u06cc\u06a9 \u0627\u0633\u062a \u06a9\u0647 \u0628\u0627 \u0627\u0631\u0633\u0627\u0644 \u067e\u0627\u0644\u0633 \u0635\u0648\u062a\u06cc \u06f4\u06f0kHz \u0648 \u0632\u0645\u0627\u0646\u200c\u0628\u0646\u062f\u06cc \u0628\u0627\u0632\u06af\u0634\u062a \u0622\u0646 \u0641\u0627\u0635\u0644\u0647 \u0631\u0627 \u0627\u0646\u062f\u0627\u0632\u0647 \u0645\u06cc\u200c\u06af\u06cc\u0631\u062f: \u0641\u0627\u0635\u0644\u0647(cm) = \u0632\u0645\u0627\u0646(\u03bcs) \/ 58. \u0628\u0631\u062f \u06f2\u2013\u06f4\u06f0\u06f0cm \u0648 \u062f\u0642\u062a \u00b1\u06f3mm \u062f\u0627\u0631\u062f. \u0627\u0631\u0632\u0627\u0646 (~\u06f4\u06f0K) \u0648 \u0645\u062d\u0628\u0648\u0628.<\/p>\n<p><strong>\u062d\u0633\u06af\u0631 IR \u0634\u0627\u0631\u067e<\/strong> (GP2Y0A21) \u0628\u0627 \u0646\u0648\u0631 \u0645\u0627\u062f\u0648\u0646 \u0642\u0631\u0645\u0632 \u0641\u0627\u0635\u0644\u0647 \u06f1\u06f0\u2013\u06f8\u06f0cm \u0631\u0627 \u0627\u0646\u062f\u0627\u0632\u0647 \u0645\u06cc\u200c\u06af\u06cc\u0631\u062f \u2014 \u0622\u0646\u0627\u0644\u0648\u06af\u060c \u0633\u0631\u06cc\u0639\u200c\u062a\u0631 \u0627\u0632 \u0633\u0648\u0646\u0627\u0631 \u0627\u0645\u0627 \u062a\u062d\u062a\u200c\u062a\u0623\u062b\u06cc\u0631 \u0646\u0648\u0631 \u0622\u0641\u062a\u0627\u0628. \u062a\u0631\u06a9\u06cc\u0628 \u0647\u0631 \u062f\u0648 \u0628\u0647\u062a\u0631\u06cc\u0646 \u0646\u062a\u06cc\u062c\u0647 \u0631\u0627 \u0645\u06cc\u200c\u062f\u0647\u062f.<\/p>\n<p><strong>\u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Bug0<\/strong> \u0633\u0627\u062f\u0647\u200c\u062a\u0631\u06cc\u0646 \u0631\u0648\u0634 \u0627\u062c\u062a\u0646\u0627\u0628 \u0627\u0632 \u0645\u0648\u0627\u0646\u0639 \u0627\u0633\u062a: \u0628\u0647 \u0633\u0645\u062a \u0647\u062f\u0641 \u0628\u0631\u0648\u060c \u0627\u06af\u0631 \u0645\u0627\u0646\u0639 \u062f\u06cc\u062f\u06cc \u0622\u0646 \u0631\u0627 \u062f\u0648\u0631 \u0628\u0632\u0646 \u062a\u0627 \u0645\u062c\u062f\u062f \u0645\u0633\u06cc\u0631 \u0622\u0632\u0627\u062f \u0634\u0648\u062f.<\/p>\n<\/div>\n<h2>BOM \u062d\u0633\u06af\u0631\u0647\u0627<\/h2>\n<table style='width:100%;border-collapse:collapse;margin-bottom:18px'>\n<thead>\n<tr style='background:#e8f0fe'>\n<th style='padding:9px;border:1px solid #ddd;text-align:right'>\u0642\u0637\u0639\u0647<\/th>\n<th style='padding:9px;border:1px solid #ddd;text-align:right'>\u0628\u0631\u062f<\/th>\n<th style='padding:9px;border:1px solid #ddd;text-align:right'>\u0642\u06cc\u0645\u062a<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style='padding:8px;border:1px solid #ddd'>HC-SR04 (\u062c\u0644\u0648)<\/td>\n<td style='padding:8px;border:1px solid #ddd'>\u06f2\u2013\u06f4\u06f0\u06f0cm<\/td>\n<td style='padding:8px;border:1px solid #ddd'>~\u06f4\u06f0K<\/td>\n<\/tr>\n<tr style='background:#fafafa'>\n<td style='padding:8px;border:1px solid #ddd'>HC-SR04 \u00d7 \u06f2 (\u06a9\u0646\u0627\u0631\u06cc)<\/td>\n<td style='padding:8px;border:1px solid #ddd'>\u06f2\u2013\u06f4\u06f0\u06f0cm<\/td>\n<td style='padding:8px;border:1px solid #ddd'>~\u06f8\u06f0K<\/td>\n<\/tr>\n<tr>\n<td style='padding:8px;border:1px solid #ddd'>IR Sharp GP2Y0A21 (\u0639\u0642\u0628)<\/td>\n<td style='padding:8px;border:1px solid #ddd'>\u06f1\u06f0\u2013\u06f8\u06f0cm<\/td>\n<td style='padding:8px;border:1px solid #ddd'>~\u06f1\u06f5\u06f0K<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u06a9\u062f \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Bug0 \u0628\u0627 HC-SR04<\/h2>\n<pre style='background:#1e1e1e;color:#d4d4d4;padding:14px;border-radius:8px;font-size:12px;margin-bottom:18px'><code>long readSonar(int trigPin, int echoPin){\n  digitalWrite(trigPin, LOW); delayMicroseconds(2);\n  digitalWrite(trigPin, HIGH); delayMicroseconds(10);\n  digitalWrite(trigPin, LOW);\n  long dur = pulseIn(echoPin, HIGH, 30000);  \/\/ timeout 30ms\n  return dur \/ 58;  \/\/ cm\n}\n\n\/\/ \u062d\u0633\u06af\u0631\u0647\u0627: TRIG\/ECHO \u062c\u0644\u0648\u060c \u0686\u067e\u060c \u0631\u0627\u0633\u062a\n#define TRIG_F 4  #define ECHO_F 5\n#define TRIG_L 6  #define ECHO_L 7\n#define TRIG_R 8  #define ECHO_R 9\n#define SAFE_DIST 30  \/\/ cm\n\nvoid loop(){\n  long dF = readSonar(TRIG_F, ECHO_F);\n  long dL = readSonar(TRIG_L, ECHO_L);\n  long dR = readSonar(TRIG_R, ECHO_R);\n\n  if(dF > SAFE_DIST){\n    \/\/ \u0645\u0633\u06cc\u0631 \u0622\u0632\u0627\u062f \u2014 \u0628\u0647 \u0633\u0645\u062a GPS Waypoint\n    navigateToWaypoint();\n  } else if(dR > dL && dR > SAFE_DIST){\n    \/\/ \u0633\u0645\u062a \u0631\u0627\u0633\u062a \u0622\u0632\u0627\u062f\u062a\u0631 \u2014 \u062f\u0648\u0631 \u0628\u0632\u0646\n    drive(-100, 100);  \/\/ \u0686\u0631\u062e\u0634 \u0631\u0627\u0633\u062a\n    delay(300);\n  } else if(dL > SAFE_DIST){\n    drive(100, -100);  \/\/ \u0686\u0631\u062e\u0634 \u0686\u067e\n    delay(300);\n  } else {\n    \/\/ \u0647\u0645\u0647 \u0637\u0631\u0641 \u0628\u0633\u062a\u0647 \u2014 \u0639\u0642\u0628 \u0628\u0631\u0648\n    drive(-150, -150);\n    delay(500);\n  }\n}<\/code><\/pre>\n<p><svg viewBox='0 0 860 170' width='100%' xmlns='http:\/\/www.w3.org\/2000\/svg' style='background:#fff;border:1px solid #ddd;border-radius:12px;margin-bottom:18px'>\n<text x='430' y='18' text-anchor='middle' font-size='12' font-family='Tahoma' fill='#333'>\u062c\u0627\u0646\u0645\u0627\u06cc\u06cc \u062d\u0633\u06af\u0631\u0647\u0627\u06cc \u0645\u0627\u0646\u0639 \u0631\u0648\u06cc UGV<\/text>\n<rect x='310' y='40' width='240' height='100' rx='10' fill='#e3f2fd' stroke='#1565c0' stroke-width='2'\/>\n<text x='430' y='95' text-anchor='middle' font-size='11' font-family='Tahoma' fill='#0d47a1'>UGV<\/text>\n<!-- \u062d\u0633\u06af\u0631 \u062c\u0644\u0648 -->\n<rect x='400' y='25' width='60' height='20' rx='4' fill='#e65100'\/>\n<text x='430' y='38' text-anchor='middle' font-size='9' font-family='Tahoma' fill='#fff'>HC-SR04 F<\/text>\n<path d='M400,25 L380,5 M460,25 L480,5' stroke='#ff9800' stroke-width='1' stroke-dasharray='3,2'\/>\n<!-- \u062d\u0633\u06af\u0631 \u0686\u067e -->\n<rect x='280' y='75' width='35' height='20' rx='4' fill='#2e7d32'\/>\n<text x='297' y='88' text-anchor='middle' font-size='8' font-family='Tahoma' fill='#fff'>HC-L<\/text>\n<!-- \u062d\u0633\u06af\u0631 \u0631\u0627\u0633\u062a -->\n<rect x='545' y='75' width='35' height='20' rx='4' fill='#2e7d32'\/>\n<text x='562' y='88' text-anchor='middle' font-size='8' font-family='Tahoma' fill='#fff'>HC-R<\/text>\n<!-- \u062d\u0633\u06af\u0631 \u0639\u0642\u0628 -->\n<rect x='400' y='140' width='60' height='20' rx='4' fill='#7b1fa2'\/>\n<text x='430' y='153' text-anchor='middle' font-size='9' font-family='Tahoma' fill='#fff'>IR Sharp B<\/text>\n<!-- \u0641\u0644\u0634\u200c\u0647\u0627 -->\n<text x='430' y='13' text-anchor='middle' font-size='14' fill='#1565c0'>\u2191 \u062c\u0644\u0648<\/text>\n<\/svg><\/p>\n<div style='display:grid;grid-template-columns:repeat(auto-fit,minmax(300px,1fr));gap:18px;margin:20px 0'>\n<iframe width='100%' height='280' src='https:\/\/www.youtube.com\/embed\/6yQ5H0bJgdc' title='HC-SR04 Obstacle Avoidance Arduino Robot' frameborder='0' allowfullscreen><\/iframe><br \/>\n<iframe width='100%' height='280' src='https:\/\/www.youtube.com\/embed\/aDLmqxSqEso' title='Bug Algorithm Robot Navigation Tutorial' frameborder='0' allowfullscreen><\/iframe>\n<\/div>\n<ul>\n<li><a href='https:\/\/lastminuteengineers.com\/arduino-sr04-ultrasonic-sensor-tutorial\/' target='_blank'>Last Minute Engineers: HC-SR04 \u0622\u0631\u062f\u0648\u06cc\u0646\u0648<\/a><\/li>\n<li><a href='https:\/\/www.aparat.com\/result\/%D8%AD%D8%B3%DA%AF%D8%B1+%D9%85%D8%A7%D9%86%D8%B9+%D8%B1%D8%A8%D8%A7%D8%AA' target='_blank'>\u0622\u067e\u0627\u0631\u0627\u062a: \u062d\u0633\u06af\u0631 \u0645\u0627\u0646\u0639 \u0631\u0628\u0627\u062a<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u0622\u0645\u0648\u0632\u0634 \u067e\u06cc\u0627\u062f\u0647\u200c\u0633\u0627\u0632\u06cc \u0633\u06cc\u0633\u062a\u0645 \u0627\u062c\u062a\u0646\u0627\u0628 \u0627\u0632 \u0645\u0648\u0627\u0646\u0639 \u0628\u0631\u0627\u06cc UGV: \u0633\u0648\u0646\u0627\u0631 HC-SR04 \u062f\u0631 \u062c\u0644\u0648\u060c \u062d\u0633\u06af\u0631 IR \u062f\u0631 \u06a9\u0646\u0627\u0631\u0647\u0627\u060c \u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 Bug0 \u0628\u0631\u0627\u06cc \u062f\u0648\u0631 \u0632\u062f\u0646 \u0645\u0648\u0627\u0646\u0639 \u0648 \u0627\u062f\u063a\u0627\u0645 \u0628\u0627 \u0646\u0627\u0648\u0628\u0631\u06cc GPS.<\/p>\n","protected":false},"author":1,"featured_media":868,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"pagelayer_contact_templates":[],"_pagelayer_content":"","footnotes":""},"categories":[19,16],"tags":[671,47,62,93,670,48,673,672],"class_list":["post-869","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tutorials-2","category-ugv","tag-bug-algorithm","tag-gps","tag-hc-sr04","tag-ir-sensor","tag-obstacle-avoidance","tag-ugv","tag-673","tag-672"],"_links":{"self":[{"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/posts\/869","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/comments?post=869"}],"version-history":[{"count":1,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/posts\/869\/revisions"}],"predecessor-version":[{"id":870,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/posts\/869\/revisions\/870"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/media\/868"}],"wp:attachment":[{"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/media?parent=869"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/categories?post=869"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/projectleon.net\/make\/wp-json\/wp\/v2\/tags?post=869"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}