Find a course

Module 2: How Robots WorkLesson 5 of 79 min

The Robot Brain

A robot's controller follows a program. Learn how programs use clear steps, if-then rules and loops, and find the bug in a robot's instructions.

Step 1 of 13Learn

The controller

A robot's brain is a small computer called the controller. It reads the sensors, runs the program and tells the motors what to do.

A program is a list of instructions written by people called programmers. The robot follows the instructions exactly. It does not guess what you meant.

If you tell a robot "go forward" but never say "stop," it will drive until it hits the wall!

Step 2 of 13Practice · Put in order

Put this program in order so a robot brings you a ball.

Drag the items, or use the arrow buttons, to put them in order.

  1. Drive back to you
  2. Open the gripper
  3. Close the gripper around the ball
  4. Drive to the ball
  5. Open the gripper to drop the ball

Step 3 of 13Learn

If-then rules

Robots make decisions with if-then rules. An if-then rule checks a sensor and picks an action.

  • If the bumper is pressed, then back up and turn.
  • If the floor sensor sees black, then steer left.
  • If the battery is low, then drive to the charger.

A program can have lots of these rules. Together they make the robot seem smart, even though each rule is simple.

Step 4 of 13Practice · Choose one

A rule says: "If the distance sensor sees something closer than 10 centimeters, then stop." The robot is 30 centimeters from a wall. What does it do?

Step 5 of 13Practice · Diagram

A robot's if-then choices

The battery is full and the bumper is pressed. Tap what the robot does.

Tap the shape that answers the question, then press Check.

A robot's if-then choicesHierarchy diagram: Is the battery low?, Yes: drive to the charger, No: is the bumper pressed?, Yes: back up and turn, No: keep driving.Is the battery low?Yes: drive to thechargerNo: is the bumperpressed?Yes: back up and turnNo: keep driving
Is the battery low?
Yes: drive to the charger
No: is the bumper pressed?
Yes: back up and turn
No: keep driving

Step 6 of 13Learn

Loops repeat

Imagine writing "check the bumper" a million times. That would take forever! Instead, programs use loops. A loop repeats steps again and again.

A robot vacuum's program is mostly one big loop: check sensors, decide, move, then start over. It might run that loop many times every second until the floor is clean or the battery is low.

Step 7 of 13Diagram

One big loop

One big loopCycle diagram: Check sensors → Decide → Move.Repeatsmany times asecondCheck sensorsDecideMove
Check sensors
Decide
Move

Step 8 of 13Practice · Work it out

A robot dance program says: "Repeat 4 times: spin, then clap." How many claps happen?

Step 9 of 13Practice · Match the pairs

Match each program idea to an example.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. Step
  2. If-then rule
  3. Loop
  4. Bug

Step 10 of 13Note

Step 11 of 13Compare

Rules robot or AI robot?

AspectRules robotAI robot
Who makes the rulesA programmer writes each oneIt learns from many examples
ExampleStop if the bumper is pressedSpot a cat in a photo
Has feelingsNoNo
Built and checked byPeoplePeople

Step 12 of 13Practice · What would you do?

What would you do?

Your robot is supposed to stop at the edge of the table, but it drives off. What is the best first thing to do?

Step 13 of 13Practice · True or false

A robot follows its program exactly, even if the program has a mistake.