Close your eyes and try to walk across the room. Tricky, isn't it? You would probably stretch out your hands, listen carefully and take tiny steps. Robots have the same problem. They have no eyes, ears or fingers, so engineers give them sensors instead. A sensor is a part that notices something about the world, such as light, distance or touch, and turns it into a number the robot's code can use.
Sense, think, act
Almost every robot follows the same simple loop, over and over again:
- Sense: read the sensors. How far away is the wall? Is the floor dark or light?
- Think: the code decides what to do. "If the wall is closer than 10 centimetres, turn."
- Act: the motors move the wheels, arms or grippers.
Then it goes straight back to step one. A robot might run this loop many times every second. That is why a good robot seems to react so quickly: it is checking again and again.
Big idea: a sensor does not "understand" anything. It just gives the robot a number. The clever part is the code that decides what the number means.
Seeing with sound: distance sensors
Many robots measure distance with an ultrasonic sensor. It looks a bit like a pair of round eyes, but it actually works like a bat.
- One side sends out a very high-pitched click of sound, too high for people to hear.
- The sound bounces off the nearest object and comes back.
- The other side listens for the echo.
The robot times how long the echo takes. A quick echo means the object is close. A slow echo means it is far away. Bats and dolphins use the same trick, called echolocation, to find their way and catch food.
Some robots use infrared light instead of sound. Infrared is a kind of light our eyes cannot see. The idea is similar: send it out, see how much bounces back.
Following a line: light sensors
Have you ever seen a small robot follow a black line around a track? It is not looking at the line the way you would. Underneath, it has a tiny light that shines down at the floor and a sensor that measures how much light reflects back.
- White paper reflects lots of light, so the sensor reads a high number.
- Black tape soaks up most of the light, so the sensor reads a low number.
The code says something like: "If I see black, steer one way. If I see white, steer the other way." The robot wobbles along the edge of the line, making hundreds of tiny corrections. It is a brilliant example of a simple rule creating clever-looking behaviour.
Touch, tilt and cameras
Robots have lots of other ways to sense the world:
- Bump sensors are little switches. When the robot crashes into something, the switch is pressed and the code knows to stop or back away.
- Accelerometers sense movement and tilt. Your phone has one, which is how the screen knows to turn sideways. The BBC micro:bit has one too, so it can tell if you shake it.
- Cameras are the closest thing to eyes. A camera gives the robot a picture made of thousands of tiny dots called pixels. On its own, that is just a huge grid of numbers. The robot needs code, and sometimes artificial intelligence, to spot shapes, colours and objects in all those numbers.
Most real robots use several sensors together. A robot vacuum cleaner, for example, may use bump sensors, sensors that spot the top of the stairs, and distance sensors, all at once. Using more than one sense makes a robot safer and less likely to get confused.
Try it at home: be a light sensor
You can test the line-following idea with things you probably already have.
You will need: a torch (or a phone torch, with a grown-up's help), a sheet of white paper, something black such as a dark sock, a book cover or black card, and a dark-ish room.
- Hold the torch close to the white paper, pointing down at an angle.
- Look at how bright the paper looks around the beam. Notice how the light seems to glow and spread.
- Now shine it on the black object in exactly the same way. What do you notice?
- Try other colours: red, yellow, blue, a page from a magazine. Line them up from "bounces back lots of light" to "soaks it up".
You have just done what a line-following robot's sensor does: compared how much light comes back from different surfaces.
Try this at home: turn it into a game of "human robot". One person is the robot and closes their eyes. The other person is the sensor and can only say "dark" or "light" as the robot walks along a path of paper on the floor. Can the robot stay on the path using just those two words?
Want to go further?
If your family has a BBC micro:bit, it has a built-in light sensor (it cleverly uses its own LED lights to measure brightness). You can write a tiny program at microbit.org that shows a sun when the room is bright and a moon when it is dark. There is also a free simulator on the website, so you can try the code on screen even without the device.
You can explore more ideas about how robots move and make decisions on our robotics page.
Next time you see an automatic door slide open or a robot vacuum turn away from the sofa, you will know its secret: it is sensing, thinking and acting, again and again.
