--- title: "Activity: Roaming Rover" date: "2021-06-03" categories: ["Activities", "All"] tags: ["Iteration", "Ultrasonic", "Motors", "Beginner"] excerpt: "Learn to avoid obstacles with the ultrasonic sensor." featuredImage: "/images/resources/roaming-rover.png" --- ** | ** Program the rover to move around the room using the ultrasonic sensor to avoid running into obstacles. If the rover detects an object, turn away from the object and keep moving forward. #### Relevant Coding Skills Branching --> Iteration Functions Variables --> Algorithm Design --> Maths #### Relevant Rover Concepts Ultrasonic IR --> Colour Gyroscope Accelerometer Motors LEDs --> Buzzer --> Activity Demonstration ### Setup When running the exercise, it can often work well to have a small obstacle course setup with flat surfaces like boxes and books for the rover to detect. The ultrasonic sensor works best against flat hard surfaces as it is detecting reflected sound waves. Angled or soft surfaces are harder to detect. ### Here’s Our Approach #### **Stage 1** Use an IF statement block with a logic comparison block to check if the ultrasonic sensor detects an obstacle in front of the rover. **Stage 2** Use the IF ELSE block to turn when an obstacle is detected and drive forward when it is not detected using motor blocks. #### **Stage 3** Repeat this behaviour by wrapping everything in a while loop. While true will repeat forever. ![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/fae3c482-6d8c-4595-b85d-24375477e65a/Screenshot+2023-10-31+083156.png) Example Code ### Related Posts Resources [ ![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1639455538805-9NI7CPKR7IYG6D4RBKAN/high+quality+sumo.png) ](/resources/creating-a-sumo-unit) [All](/resources?category=All) [Creating A Sumo Unit For Your Digital Technologies Class](/resources/creating-a-sumo-unit) [All](/resources?category=All) How to run a sumo unit in your digital technologies classroom. [Read More →](/resources/creating-a-sumo-unit) [All](/resources?category=All) [ ![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1637464845856-BBPD7GTIIHHOSJCFORWF/the+ultrasonic+sensor.png) ](/resources/ultrasonic-sensor) [All](/resources?category=All), [Guides](/resources?category=Guides) [The Ultrasonic Sensor](/resources/ultrasonic-sensor) [All](/resources?category=All), [Guides](/resources?category=Guides) Learn all about the ultrasonic sensor! [Read More →](/resources/ultrasonic-sensor) [All](/resources?category=All), [Guides](/resources?category=Guides) [ ![](https://images.squarespace-cdn.com/content/v1/60a43bf842d7b601064a8828/1625616494179-LZHZP5MUA0E0MQKEB7HC/cropped+image+4.png) ](/resources/year-7-digital-tech-at-st-peters) [All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories) [Case Study: Year 7 Digital Tech at St Peters Lutheran College](/resources/year-7-digital-tech-at-st-peters) [All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories) See how Meg Foley at St Peters conducted a challenge for their Year 7s using Micromelon. [Read More →](/resources/year-7-digital-tech-at-st-peters) [All](/resources?category=All), [Customer Stories](/resources?category=Customer+Stories)