Robotics & Sensors
Lesson 2 of 2 8 min +40 XP

Robot Logic: If-Then Rules

Turning sensor readings into actions.

What you'll learn

  • Write if-then rules
  • Explain line following
  • Combine simple rules
Turning readings into moves

IF the front sensor sees a wall, THEN turn right — a robot converts sensor readings into actions with simple rules. Robot logic is stacking these if-then rules so the machine responds to whatever the world throws at it.

If this, then that

A robot acts on rules: IF the distance sensor sees a wall, THEN stop and turn. Chain a few of these and simple behavior appears. A line-following robot uses one rule for each side: if it drifts off the line, steer back toward it.

Simulation · Logic gate explorer
AND
0
0,00
0,10
1,00
1,11

Tap the inputs and switch gates — every computer is built from these.

Combine inputs with AND, OR, and NOT — the same logic a robot uses to decide when to act.

Lab · Program a maze-runner (on paper)
  1. Write a rule for what the robot does when its front sensor sees a wall.
  2. Write a rule for what it does when the path ahead is clear.
  3. Add a rule for turning at a dead end.
  4. Trace your rules through a simple maze and check the robot escapes.

What you should see: You expressed robot behavior as if-then rules and tested them against a maze.

Knowledge Check

+10 XP / correct

1. A line-following robot mainly reacts to…

2. 'IF wall ahead, THEN turn' is an example of a…