{"id":5237,"date":"2018-10-13T13:02:21","date_gmt":"2018-10-13T10:02:21","guid":{"rendered":"http:\/\/roboromania.ro\/?p=5237"},"modified":"2018-10-13T13:02:21","modified_gmt":"2018-10-13T10:02:21","slug":"robot-2wd-roboromania-autonom-cu-radar-ocolire-obstacole","status":"publish","type":"post","link":"https:\/\/roboromania.ro\/?p=5237","title":{"rendered":"Robot 2WD Roboromania autonom cu radar ocolire obstacole"},"content":{"rendered":"<h4><strong><span style=\"color: #0000ff;\">Robot 2WD Roboromania autonom cu <span style=\"color: #ff0000;\">radar<\/span> ocolire obstacole<\/span><\/strong><\/h4>\n<p><a href=\"http:\/\/roboromania.ro\/wp-content\/uploads\/2017\/03\/robot.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-3243\" src=\"http:\/\/roboromania.ro\/wp-content\/uploads\/2017\/03\/robot-300x200.jpg\" alt=\"robot\" width=\"300\" height=\"200\" srcset=\"https:\/\/roboromania.ro\/wp-content\/uploads\/2017\/03\/robot-300x200.jpg 300w, https:\/\/roboromania.ro\/wp-content\/uploads\/2017\/03\/robot.jpg 800w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Unul dintre cele mai simple coduri pentru Robot 2WD autonom cu radar ocolire obstacole.<\/p>\n<p>Avem nevoie de :<br \/>\no plac\u0103 de dezvoltare tip Arduino UNO (oricare)<br \/>\nun modul driver motoare L298N<br \/>\nun senzor cu ultrasunete<br \/>\n\u0219asiu cu 2 motoare 2WD<br \/>\nservomotor<br \/>\ncabluri Dupont<\/p>\n<p><a href=\"http:\/\/roboromania.ro\/wp-content\/uploads\/2017\/03\/Robot-2WD-roboromania.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-3756\" src=\"http:\/\/roboromania.ro\/wp-content\/uploads\/2017\/03\/Robot-2WD-roboromania-300x250.jpg\" alt=\"robot-2wd-roboromania\" width=\"300\" height=\"250\" srcset=\"https:\/\/roboromania.ro\/wp-content\/uploads\/2017\/03\/Robot-2WD-roboromania-300x250.jpg 300w, https:\/\/roboromania.ro\/wp-content\/uploads\/2017\/03\/Robot-2WD-roboromania-1024x852.jpg 1024w, https:\/\/roboromania.ro\/wp-content\/uploads\/2017\/03\/Robot-2WD-roboromania.jpg 1028w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/p>\n<p>Cel mai simplu cod :<\/p>\n<p>\/\/&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;<\/p>\n<p>\/\/ roboromania.ro Arduino Object Avoiding Robot with Ultrasonic Sensor<br \/>\n#include &lt;Servo.h&gt;<br \/>\n#include &#8222;Ultrasonic.h&#8221;<\/p>\n<p>const int buzzer = 8;<br \/>\nconst int motorA1= 2;<br \/>\nconst int motorA2= 6;<br \/>\nconst int enableA = 3;<br \/>\nconst int motorB1= 10;<br \/>\nconst int motorB2= 9;<br \/>\nconst int enableB = 5;<\/p>\n<p>Ultrasonic ultrasonic(A2 ,A3); \/\/(trig pin,echo pin)<br \/>\nServo myservo;<\/p>\n<p>int distance;<br \/>\nint checkRight;<br \/>\nint checkLeft;<br \/>\nint pos=100;<br \/>\nint speedPWM = 150; \/\/Change speed (PWM max 255)<\/p>\n<p>void setup()<br \/>\n{<br \/>\nmyservo.attach(7); \/\/Servo pin connected to pin 7<br \/>\nmyservo.write(pos);<br \/>\npinMode(buzzer, OUTPUT);<br \/>\npinMode(motorA1,OUTPUT);<br \/>\npinMode(motorA2,OUTPUT);<br \/>\npinMode(motorB1,OUTPUT);<br \/>\npinMode(motorB2,OUTPUT);<br \/>\npinMode(enableA, OUTPUT);<br \/>\npinMode(enableB, OUTPUT);<br \/>\ndelay(1000);<br \/>\n}<\/p>\n<p>void loop(){<br \/>\nanalogWrite(enableA, speedPWM);<br \/>\nanalogWrite(enableB, speedPWM+50);<br \/>\n\/\/Read distance&#8230;<br \/>\ndistance = ultrasonic.Ranging(CM); \/\/ CM= centimeters INC= inches<br \/>\ndelay(20);<br \/>\n\/\/Check for objects&#8230;<br \/>\nif (distance &gt; 15){<br \/>\nforward(); \/\/All clear, move forward!<br \/>\nnoTone(buzzer);<br \/>\n}<br \/>\nelse if (distance &lt;=15){<br \/>\nstop(); \/\/Object detected! Stop the robot and check left and right for the better way out!<br \/>\ntone(buzzer,500); \/\/ play a tone<br \/>\n\/\/Start scanning&#8230;<br \/>\nfor(pos = 30; pos &lt; 170; pos += 1){<br \/>\nmyservo.write(pos);<br \/>\ndelay(10);<br \/>\n}<\/p>\n<p>checkLeft = ultrasonic.Ranging(CM);<\/p>\n<p>for(pos = 170; pos&gt;=30; pos-=1){<br \/>\nmyservo.write(pos);<br \/>\ndelay(10);<br \/>\n}<\/p>\n<p>checkRight= ultrasonic.Ranging(CM);<\/p>\n<p>myservo.write(100); \/\/ Sensor &#8222;look&#8221; forward again<\/p>\n<p>\/\/ decision turn left or right?<br \/>\nif (checkLeft &lt; checkRight){<br \/>\nleft();<br \/>\ndelay(500);<br \/>\n}<br \/>\nelse if (checkLeft &gt; checkRight){<br \/>\nright();<br \/>\ndelay(500);<br \/>\n}<br \/>\nelse if (checkLeft &lt;=10 &amp;&amp; checkRight &lt;=10){<br \/>\nbackward();<br \/>\nleft();<br \/>\n}<br \/>\n}<br \/>\ndelay(150);<br \/>\n}<br \/>\nvoid forward(){<br \/>\ndigitalWrite(motorA1, HIGH);<br \/>\ndigitalWrite(motorA2, LOW);<br \/>\ndigitalWrite(motorB1, HIGH);<br \/>\ndigitalWrite(motorB2, LOW);<br \/>\n}<\/p>\n<p>void backward(){<br \/>\ndigitalWrite(motorA1, LOW);<br \/>\ndigitalWrite(motorA2, HIGH);<br \/>\ndigitalWrite(motorB1, LOW);<br \/>\ndigitalWrite(motorB2, HIGH);<br \/>\n}<\/p>\n<p>void left(){<br \/>\ndigitalWrite(motorA1, HIGH);<br \/>\ndigitalWrite(motorA2, LOW);<br \/>\ndigitalWrite(motorB1, LOW);<br \/>\ndigitalWrite(motorB2, HIGH);<br \/>\n}<\/p>\n<p>void right(){<br \/>\ndigitalWrite(motorA1, LOW);<br \/>\ndigitalWrite(motorA2, HIGH);<br \/>\ndigitalWrite(motorB1, HIGH);<br \/>\ndigitalWrite(motorB2, LOW);<br \/>\n}<\/p>\n<p>void stop(){<br \/>\ndigitalWrite(motorA1, LOW);<br \/>\ndigitalWrite(motorA2, LOW);<br \/>\ndigitalWrite(motorB1, LOW);<br \/>\ndigitalWrite(motorB2, LOW);<br \/>\n}<\/p>\n<p>\/\/&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;&#8211;<\/p>\n<p>Aten\u021bie la declararea pinilor. Dac\u0103 copia\u021bi codul aten\u021bie la fonturi.<\/p>\n<p><strong><span style=\"color: #0000ff;\">Succes !<\/span><\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Robot 2WD Roboromania autonom cu radar ocolire obstacole Unul dintre cele mai simple coduri pentru Robot 2WD autonom cu radar ocolire obstacole. Avem nevoie de : o plac\u0103 de dezvoltare tip Arduino UNO (oricare) un modul driver motoare L298N un senzor cu ultrasunete \u0219asiu cu 2 motoare 2WD servomotor cabluri Dupont Cel mai simplu cod [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[176],"tags":[],"class_list":["post-5237","post","type-post","status-publish","format-standard","hentry","category-tutoriale-arduino"],"_links":{"self":[{"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/posts\/5237","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/roboromania.ro\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5237"}],"version-history":[{"count":1,"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/posts\/5237\/revisions"}],"predecessor-version":[{"id":5239,"href":"https:\/\/roboromania.ro\/index.php?rest_route=\/wp\/v2\/posts\/5237\/revisions\/5239"}],"wp:attachment":[{"href":"https:\/\/roboromania.ro\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5237"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/roboromania.ro\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5237"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/roboromania.ro\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5237"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}