Track: Robots & Electronics · Lesson 2 of 10 · Ages: 7+ · Time: 30 minutes
You have eyes, ears, skin and a nose. They are how you find out about the world. Robots have their own set of senses, and they are called sensors. Let us meet them!
What you need
- A pencil and paper.
- A grown-up to explore the house with you.
- About half an hour.
Grown-ups This is a “look and talk” lesson, so no electronics are needed. A sensor turns something in the world (light, pressure, sound, heat) into a number or an on/off signal that a computer can read. The scavenger hunt below works best if you let your child lead and you ask questions.
A sensor turns the world into numbers
Your eyes tell your brain how bright a room is. A light sensor tells a robot’s brain the same thing, but as a number, such as 5 for very dark and 95 for very bright. A robot’s computer cannot see or hear in the way you do. It can only read numbers, so every sensor’s job is to turn something real into a number.
Five sensors and the senses they copy
| Robot sensor | Human sense | What it notices |
|---|---|---|
| Light sensor | Eyes | How bright it is, or whether a surface is light or dark |
| Touch sensor (a bump switch) | Skin | Whether something is pressing on it |
| Distance sensor | Eyes, plus a bat’s echo trick | How far away an object is |
| Microphone | Ears | Sound, such as a clap, and how loud it is |
| Temperature sensor | Skin | How warm or cold it is |
Beep says My bump switch is like your skin. When I touch something, a little button clicks inside me and I know right away. I like that. Beep boop!
How does a distance sensor work?
Many distance sensors work like a bat. Bats make squeaks that are too high for people to hear, and then they listen for the echo. A robot’s distance sensor can send out a short, very high sound, then time how long the echo takes to come back. A longer wait means the object is farther away. Other distance sensors use invisible light in a similar way.
Safety first: the sensor scavenger hunt
Safety first Look but do not touch! Never poke anything into a plug socket, and never take apart anything that plugs into the wall. Do not touch hot things like ovens, kettles or toasters. Stay with your grown-up the whole time.
Walk around your home with a grown-up. Find at least five machines that sense something, and write them down. Here are some ideas to get you started:
- A phone or tablet screen that gets brighter or darker by itself.
- A thermostat or a digital thermometer.
- A video doorbell, or a light that switches on when someone walks by.
- A toy that reacts when you clap or press a button.
- A kitchen scale (it senses weight).
For each one, ask: What does it sense? What does it do about it?
Readings are just numbers
Let us see how a robot’s brain might use light readings. We will say 0 is pitch dark and 100 is brilliant sunshine.
light_readings = [90, 65, 30, 10]
for light in light_readings:
if light < 20:
print(light, "-> dark")
elif light < 60:
print(light, "-> dim")
else:
print(light, "-> bright")
90 -> bright 65 -> bright 30 -> dim 10 -> dark
Look at the new word elif. It means “otherwise, if”. Python checks the first question, and only if the answer is no does it check the next one. The robot sorts every number into one of three groups.
Pixel says Sensors are not perfect. A light sensor cannot tell a shadow from a dark floor, and a microphone cannot tell a clap from a door slam. Good robot builders always ask, “How could this sensor be fooled?” Meow!
Did you know? Some robots have senses that you do not. A robot can have a sensor for magnets, or for invisible infrared light. Some robots even measure how fast they are tipping over, so they can keep their balance.
Challenges
Try it A robot night-light has a light sensor. It should switch on when the reading is below 40. Change the Python program so it prints “lamp on” for readings below 40 and “lamp off” for everything else, using only if and else.
Show the answer
light_readings = [90, 65, 30, 10]
for light in light_readings:
if light < 40:
print(light, "-> lamp on")
else:
print(light, "-> lamp off")
The readings 30 and 10 are below 40, so the lamp switches on for those two.
Try it Pick a sensor from the table. Think of a robot that could use it, and what the robot would do with the numbers it reads.
What you learned
- A sensor turns something in the world into a number a robot’s computer can read.
- Light, touch, distance, sound and temperature sensors copy our eyes, skin, ears and a bat’s echo trick.
- A program can sort readings into groups using
if,elifandelse. - Sensors can be fooled, so good robots are built with that in mind.
