Tutorpip← About this lessonOpen the sheet →Download PDF
Ages 8+ · Coding · Decisions
Sensing: touching and colour
Color sensor• shines a little light down• measures what bounces back• tells yellow from blueTouch sensor• a little button on the front• clicks when pushed• notices a wall
Two sensors, two jobs.
The big ideaA sensor tells a robot about the world, so its program can react.

How it works

A sensor tells a robot about the world.

A program can only use what its robot can sense.

A color sensor tells colors apart. A touch sensor tells when something pushes it.

The program uses an if to react to what a sensor says.

1follow the road2if the floor is yellow3 stop4if the touch sensor is pressed5 back up
Two rules, one for each sensor.

Example 1: No sensor

  1. Bo's rule is follow the road, and if the floor is yellow, stop.
  2. Bo cannot tell yellow from blue.
  3. He rolls right over the yellow tile.

Example 2: A color sensor

  1. A color sensor shines a little light down and measures what bounces back.
  2. Yellow bounces back differently from blue.
  3. The sensor says yellow, so the if is true and Bo stops on the tile.
1follow the road2if the floor is yellow3 stop
Line 2 uses the color sensor.

Example 3: A touch sensor

  1. A touch sensor is a little button on the front.
  2. Bo meets the wall, the button clicks, and the program asks if it is pressed.
  3. It is, so Bo backs away, turns and rolls on.

Example 4: Which sensor?

  1. Priya wants Bo to stop on yellow and to back away from the wall.
  2. Yellow needs a color sensor, and the wall needs a touch sensor.
  3. So Bo needs 2 kinds of sensor.

Words to know

sensor
A part that tells a robot about the world.
color sensor
Tells colors apart.
touch sensor
Clicks when something pushes it.
react
To do something because of what a sensor says.

Watch out

Try it

  1. Which sensor tells a blue tile from a yellow tile?
  2. Which sensor notices that Bo bumped a wall?
  3. Can a robot react to a color with no sensor?
  4. Which sensor does Bo need to hear a loud clap?
  5. What does a program use to react to a sensor's answer?
Answers: 1. A color sensor · 2. A touch sensor · 3. No · 4. A sound sensor · 5. An if
Try at homeIn a clear room, play robot with a grown-up. Close your eyes for a few slow steps. Your grown-up is the program and uses only what you can sense. Try a touch rule: if you feel the wall, turn around. Which senses did you use?
For grown-upsDo the Mission: in a clear room, play robot together. Close your eyes for a few slow steps while your grown-up is the program. Try a touch rule: if you feel the wall, turn around. Which senses did you use?
Open these notes on screenScan the code, or go to tutorpip.com.