Sign in to save

Bookmark this page so you can find it later.

Sign in to save

Bookmark this page so you can find it later.

Robots can seem smart because they react to what they sense around them. A simple way robots make choices is with if then logic. This means the robot checks a condition, such as whether an obstacle is close, and then follows an instruction.

This idea is important because it helps robots move safely, avoid crashes, and repeat tasks on their own.

A wheeled robot with an ultrasonic distance sensor can measure how far away a wall or block is. The robot might follow the rule, if the obstacle is closer than 20 cm, then stop and turn. If the path is clear, then the robot drives forward.

This decision repeats in a loop, so the robot keeps reading the sensor, checking the condition, and choosing the next action.

Key Facts

  • If then logic follows the pattern: if condition is true, then do an action.
  • A robot sensor collects information, such as distance, light, sound, or touch.
  • Example rule: if distance < 20 cm, then stop and turn.
  • Example rule: if distance >= 20 cm, then drive forward.
  • A flowchart diamond shows a decision, such as obstacle detected?
  • A loop lets a robot repeat steps: read sensor, decide, act, then read sensor again.

Vocabulary

If then logic
A decision rule where a robot checks a condition and performs an action when the condition is true.
Condition
A statement that can be true or false, such as distance is less than 20 cm.
Sensor
A device that detects information from the environment and sends it to the robot controller.
Ultrasonic sensor
A sensor that uses sound waves to measure the distance to nearby objects.
Loop
A set of instructions that repeats until the program tells it to stop.

Common Mistakes to Avoid

  • Forgetting to read the sensor again, which is wrong because the robot would keep using old information instead of reacting to new obstacles.
  • Using the wrong comparison sign, which is wrong because distance < 20 cm means close, while distance > 20 cm means farther away.
  • Putting the action inside the decision diamond, which is wrong because the diamond should contain the condition and the action should go in the next step.
  • Leaving out the no path in a flowchart, which is wrong because a robot needs instructions for both true and false results.

Practice Questions

  1. 1 A robot is programmed with the rule if distance < 15 cm, then stop. The sensor reads 12 cm. What action should the robot take?
  2. 2 A robot drives forward if distance >= 25 cm and turns if distance < 25 cm. For sensor readings of 40 cm, 25 cm, 18 cm, and 7 cm, list the robot action for each reading.
  3. 3 A robot gets stuck turning in place even when no obstacle is nearby. Explain one possible if then logic mistake in its program and how to fix it.