Avoiding obstacles
Section 7: Motors and the carLesson 7.3 · ⏱ 10 min
We put the distance sensor on the front of the car: if an obstacle comes close, it backs up a little and turns, otherwise it moves forward. Now we have a smart robot that decides by itself.

📌 Another example: it stops before the wall
If the wall is closer than 20 cm it stops, otherwise it moves.



✍️ Practise
Stop before the wall.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
✍️ Practise
Avoiding obstacles.
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
Close: it backs up.
👀 Show the solution🙈 Hide the solution


Result: it backs up.
Medium
Close: it turns to avoid the wall.
👀 Show the solution🙈 Hide the solution


Result: it turns.
Hard
It slows down: between 20 and 50 cm speed 100, closer than 20 it stops, and farther speed 200.
👀 Show the solution🙈 Hide the solution


Result: it moves slowly near the wall.

