Obstacle Detection
In the previous program the robot moves forward and then checks for something in the way. As we observed it only checks for things after it moves forward not all the time.
The robot should move if nothing is in the way and stop if there is checking constantly for obstacles.
Obstacle Detection Program Using a Switch Block
How the Ultrasonic Switch Block Works
How the Ultrasonic Switch Block Works
How the Ultrasonic Switch Block Works The Sensor Value is greater than the switches compared value. The distance is above the threshold. The object is far from the robot.
How the Ultrasonic Switch Block Works The Sensor Value is less than the switches compared value. The distance is below the threshold. The object is near the robot.
Ultrasonic Sensor Block Details
Stop Motors Block Details
Move Forward Motor Block Details
Loop Block Details
Drag the Switch Block Into the Loop Block
Stop Motors After 4 Rotations
Test the robot to see if it keeps moving as long as nothing is in the way and stops if there is. Try placing the object in front of the robot at different times during the program to make sure the robot is checking constantly for obstacles.