- :-

Program Review: Obstacle Detection Until Black Line

  • The program shown below is sample code for mini-challenge in the "Obstacle Detection" lesson.
Hover on any block in the program to view a detailed explanation.
Loop Block Color Sensor > Compare > Color Conditionally sends the program flow back to the start. Lets the flow out of loop if sensor's value is '1' (black). Robot repeats commands inside the loop until the color sensor sees the color Black.
Switch Block Ultrasonic Sensor - Compare - Distance Centimeters Checks whether Ultrasonic sensor value is less than '10'. If true, sends program flow to "true" (top) branch. If false, sends program flow to "false" (bottom) branch. Robot makes decision based on whether there is an obstacle within 10 cm.
Move Steering Block Off Stops both motors on the robot. Because this block is on the "Yes" branch of the Switch, it will only be reached if the Ultrasonic Sensor detects an object within 10cm. Stop the robot if there is an obstacle in front of it.
Move Steering Block On Turns both motors on at 50% power. Because this block is on the "No" branch of the Switch, it will only be reached if the Ultrasonic Sensor detects NO objects within 10 cm. Run the motors forward if there is no obstacle in the robot's way.
Move Steering Block Off Stops both motors on the robot. Because this block comes after the Light Sensor Loops, it will only be reached after the robot has detected a Black line. Stop the robot when it sees the black line.