{"id":5417,"date":"2024-03-06T17:43:43","date_gmt":"2024-03-06T17:43:43","guid":{"rendered":"https:\/\/rodmilstead.com\/pt\/?page_id=5417"},"modified":"2026-05-04T20:28:04","modified_gmt":"2026-05-04T20:28:04","slug":"2024-ultrasonic-robot","status":"publish","type":"page","link":"https:\/\/rodmilstead.com\/pt\/2024-ultrasonic-robot\/","title":{"rendered":"Ultrasonic Robot"},"content":{"rendered":"<p>Now you will add an ultrasonic sensor to your robot.<\/p>\n<p>You will need to remove the button from your circuit and code.\u00a0 Scroll down for details and screenshots.<\/p>\n<p><a href=\"https:\/\/www.tinkercad.com\/things\/iLHWlOJIDvC\/editel?sharecode=h31un7tHvPAQZbZVSYcf1Vr4iFVM7Nw1gPWqEqQ2eR8\" target=\"_blank\" rel=\"noopener\">Full code and diagram right here<\/a><\/p>\n<p>Use the physical circuit and program that you built for <a href=\"https:\/\/rodmilstead.com\/pt\/arduino-sample-coderesources\/arduino-ultrasonic-sensor-part-1\/part-2-arduino-ultrasonic-sensor-and-leds\/\" target=\"_blank\" rel=\"noopener\">Ultrasonic Sensor Part 2<\/a> as the brains and eyes of your robot.<\/p>\n<p>Your goal is to build a two-wheel robot that can change it&#8217;s path to get around obstacles.\u00a0 The ultrasonic sensor will tell the robot how close it is to an object.<\/p>\n<p><strong>In addition to the circuit that you have already built, you will need the following:<\/strong><br \/>\n-your own cardboard mount to attach the ultrasonic sensor<br \/>\n-use a small breadboard to mount the sensor &#8211; please glue this down &#8211; <span style=\"color: #ff0000;\"><strong>DO NOT PEEL the adhesive off.<\/strong><\/span>\u00a0 Pay close attention to HOW the sensor is attached to the breadboard.<br \/>\n-1 ultrasonic sensor<a href=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2024\/03\/ultrasonic_robot_sensor-scaled.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-5432 aligncenter\" src=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2024\/03\/ultrasonic_robot_sensor-768x1024.jpg\" alt=\"\" width=\"223\" height=\"297\" srcset=\"https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2024\/03\/ultrasonic_robot_sensor-768x1024.jpg 768w, https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2024\/03\/ultrasonic_robot_sensor-225x300.jpg 225w, https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2024\/03\/ultrasonic_robot_sensor-1152x1536.jpg 1152w, https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2024\/03\/ultrasonic_robot_sensor-1536x2048.jpg 1536w, https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2024\/03\/ultrasonic_robot_sensor-scaled.jpg 1920w\" sizes=\"auto, (max-width: 223px) 100vw, 223px\" \/><\/a><\/p>\n<p><a href=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2026\/04\/ultrasonicsensor.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-medium wp-image-8383\" src=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2026\/04\/ultrasonicsensor-225x300.png\" alt=\"\" width=\"225\" height=\"300\" srcset=\"https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2026\/04\/ultrasonicsensor-225x300.png 225w, https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2026\/04\/ultrasonicsensor-768x1024.png 768w, https:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2026\/04\/ultrasonicsensor.png 800w\" sizes=\"auto, (max-width: 225px) 100vw, 225px\" \/><\/a><br \/>\n-4 wires for the sensor<\/p>\n<p><strong>Robot requirements:<\/strong><br \/>\n1. your robot should turn when it encounters an obstacle.<br \/>\n2. after the turn is completed your robot should drive straight until it detects another obstacle.\u00a0 Then it will repeat step 1.<\/p>\n<p>Changing your circuit:<br \/>\n1. you need to wire the ultrasonic sensor \u00a0following the diagram in <a href=\"https:\/\/rodmilstead.com\/pt\/arduino-sample-coderesources\/arduino-ultrasonic-sensor-part-1\/part-2-arduino-ultrasonic-sensor-and-leds\/\" target=\"_blank\" rel=\"noopener\">Ultrasonic Sensor Part 2<\/a>.|<br \/>\n2. you need to remove the button and replace it with a wire.\u00a0 <a href=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2024\/03\/2024-ultrasonic-robot-button-wire.jpg\" target=\"_blank\" rel=\"noopener\">Click here to see what this looks like.\u00a0<\/a><\/p>\n<p><strong>Programming requirements:<\/strong><br \/>\nYour program should include a function that tells the robot what to do while it is searching for an obstacle. If you need a refresher on Arduino Functions follow this link.<\/p>\n<p><strong>Programming &#8211; you can work in Tinkercad OR go directly to real components.\u00a0 While I would start in Tinkercad, the choice is up to you.<br \/>\n<\/strong>1. make a copy of your code from the first version of this robot.<br \/>\n2. <a href=\"http:\/\/rodmilstead.com\/pt\/wp-content\/uploads\/2024\/03\/2024-ultrasonic-robot-class-notes.jpg\" target=\"_blank\" rel=\"noopener\">click here for starter code.\u00a0<\/a> \u00a0You will need to add your OWN code for making the robot drive straight, stop and turn.<br \/>\n3. you only need ONE loop function (named void loop() ).\u00a0 Don&#8217;t add a second loop function.\u00a0 Instead, modify the one that you already have.<\/p>\n<p><strong>Test your robot:<\/strong><br \/>\n1. setup some boxes as obstacles.<br \/>\n2. let the robot drive towards the obstacles.<br \/>\n3. questions&#8230;<br \/>\n&gt;does it stop?<br \/>\n&gt;does it turn?<br \/>\n&gt;does it have enough room to turn?<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Now you will add an ultrasonic sensor to your robot. You will need to remove the button from your circuit and code.\u00a0 Scroll down for details and screenshots. Full code and diagram right here Use the physical circuit and program that you built for Ultrasonic Sensor Part 2 as the brains and eyes of your &hellip; <a href=\"https:\/\/rodmilstead.com\/pt\/2024-ultrasonic-robot\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Ultrasonic Robot<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-5417","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages\/5417","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/comments?post=5417"}],"version-history":[{"count":21,"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages\/5417\/revisions"}],"predecessor-version":[{"id":8457,"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/pages\/5417\/revisions\/8457"}],"wp:attachment":[{"href":"https:\/\/rodmilstead.com\/pt\/wp-json\/wp\/v2\/media?parent=5417"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}