pu-robot-kit-case-08
Let students convert the logic into MakeCode blocks step by step according to the flowchart, understanding the design idea of "flowchart → program".
- Group Programming & Actual Testing: Each group sets blocks as obstacles on the desktop or ground, and completes the following tasks:
- Basic Task: Write an obstacle avoidance program to realize "detect an obstacle (distance < 10cm) → stop → turn right 90° → keep moving forward", and test whether the robot can successfully bypass a single obstacle;
- Each group conducts repeated tests and adjusts the turning angle to ensure the robot can move forward normally after avoiding obstacles, cultivating debugging and problem-solving abilities.
MakeCode Programming
Program 1: Detect the Distance to Obstacles

Program Link: https://makecode.microbit.org/_RfC1cCfL2ikA
Program 2: Stop and Turn When Obstacle is Detected

Program Link: https://makecode.microbit.org/_1ofLLt7iVJ3M
Summary & Sharing
Invite each group to demonstrate the obstacle avoidance effect and share the problems encountered and solutions during debugging: How do different distance thresholds affect the robot’s obstacle avoidance behavior? What are the differences and connections between the conditional judgment module and the previously learned sequential execution and loop modules? Combining students’ sharing, the teacher summarizes the relationship between the three core program structures:
Sequential execution lets the robot "do things step by step";
Loops let the robot "keep doing things repeatedly";
Conditional judgment lets the robot "decide what to do according to the situation";
Combined, the three structures enable the robot to complete more complex and intelligent tasks. Preview that subsequent courses will comprehensively use these three structures to challenge more complex programming projects.