A robot senses, thinks, and acts
What makes a machine a robot? People do not agree on one answer. But engineers often use a simple test with three parts. We will use it in this whole tutorial.
A robot is a machine that senses its surroundings, decides what to do with a computer program, and then acts on the physical world.
- 1 · SENSEA sensor is a part that measures something, like light, distance, or touch, and turns it into a number.
- 2 · THINKA controller is the small computer that reads the numbers and runs the program.
- 3 · ACTAn actuator is a part that makes something move or change, like a motor.
The three steps do not happen once. They repeat in a circle, over and over, many times each second. That circle is called a feedback loop: what the robot does changes what it senses next, and that changes what it does after that.
Picture riding a bike. Your eyes see that you are leaning left. Your brain decides to steer a little right. Your hands turn the handlebars. Now you lean differently, so your eyes see something new. You are a feedback loop on wheels.
NOTEThis is a useful test, not a law of nature. Some people say a robot must move around. Others include machines that only change things nearby, like a thermostat. You will meet those edge cases in the next section.
Is it a robot? You decide
Use the sense-think-act test on these seven machines. Pick Robot or Not a robot. Each card shows how the machine works, so read it first. Then check your answer.
Careful: the thermostat and the smart speaker are real arguments. Smart people put them on both sides. What matters is that you can explain which of the three steps is missing, or present.
The parts inside a robot
Most small robots have the same five kinds of parts. Pick a part, or tap a number on the drawing, to see what it does. The glowing wires show how information and power flow.
Sensors
Like your eyes and ears
Sensors measure the world and turn it into numbers the controller can use. A robot can only react to what it can sense. No sensor, no reaction.
- A robot vacuum uses bump switches and distance sensors to find walls.
- A self-driving car uses cameras and other sensors to see lanes and people.
- A line-following robot uses light sensors pointed at the floor.
Controller
Like your brain
The controller is a small computer, often called a microcontroller. It reads the sensor numbers, runs your program, and sends commands to the motors. Your if and else rules live here.
- Hobby robots often use a small board such as an Arduino or a micro:bit.
- Bigger robots may have several computers working together.
Actuators
Like your muscles
An actuator is any part that turns a command into movement or change. Most are motors. Some are pumps, speakers, or lights. They do the “act” in sense-think-act.
- Drive motors spin the wheels of a rover.
- A servo is a motor that can turn to an exact angle. Robot arms use them at their joints.
- A gripper opens and closes to pick things up.
Power
Like food and water
Everything needs energy. Most mobile robots carry a battery. Motors usually use the most power, so a robot that moves a lot runs out sooner. Battery life is one of the biggest limits in robotics.
- A robot vacuum heads back to its dock when its battery runs low.
- A factory arm is often plugged into the wall instead, since it stays in one place.
Body
Like your skeleton
The body, or chassis, holds everything together. Its shape depends on the job. Wheels are simple and fast on flat floors. Legs handle stairs and rocks. Wings and propellers lift a robot into the air.
- A warehouse robot is low and flat so it can slide under shelves.
- A robot arm has a fixed base and long, strong links.
Sensors turn the world into numbers
A robot does not see a wall the way you do. It gets a number. Try five common sensors below. Each one has a little test bench you can play with, using a slider or by dragging.
Ultrasonic distance sensor
Measures: how far away something is
It sends out a short burst of sound that people cannot hear, then listens for the echo. The longer the echo takes, the farther away the object is.
Sound travels about 343 meters per second in room-temperature air. So the robot works out distance = speed × time ÷ 2. It divides by two because the sound goes there and back.
Real examples: car parking sensors, some robot vacuums, and many classroom robot kits.
Weak spot: soft things like curtains, or surfaces at a steep angle, may not bounce the sound back well.
Light and line sensor
Measures: how much light bounces back
This sensor shines a small light at the floor and measures how much comes back. A pale floor reflects a lot. A dark line soaks light up. So the sensor gives a number: high for bright, low for dark.
Notice the edge of the line. The reading slides in between, because the sensor is looking at both at once.
Real examples: line-following robots, and “cliff” sensors that stop a robot from driving off a table.
Weak spot: shiny floors, very dark floors, and bright sunlight can all fool it.
Touch (bump) switch
Measures: yes or no, am I touching something
A touch sensor is a tiny switch. When something pushes it far enough, the switch closes and the controller reads a 1. Otherwise it reads 0. There is no in-between, only yes or no.
That is the point of a threshold: a line the reading must cross before the answer flips.
Real examples: robot vacuum bumpers, and end-stop switches that tell a machine part it has reached the edge of its track.
Weak spot: the robot has to already be touching something. It cannot warn you ahead of time.
Camera
Measures: a grid of brightness and color
A camera image is a grid of tiny squares called pixels. Each pixel is a number for how bright it is. A real camera has millions. This one has 126, so you can see the idea.
The camera does not know it is looking at a ball. The program has to find the bright blob and work out where it is. Then a rule can say “turn toward the ball.”
Real examples: self-driving cars, warehouse robots, and robots that sort fruit.
Weak spot: cameras make a lot of data, need decent light, and are harder to program. See how computer vision works.
Gyroscope (gyro)
Measures: how fast the robot is turning
A gyro reports turning speed, such as “10 degrees per second to the right.” Add up those speeds over time and the controller can work out the tilt angle.
Real examples: phones that rotate the screen, and drones and balancing robots that need to stay level.
Weak spot: tiny errors add up. Over time the angle slowly drifts, so robots often combine a gyro with other sensors to correct it.
Program a line-following robot
Now you are the programmer. Your robot has two light sensors at the front, one on the left and one on the right. Each one only knows one thing: is my spot on the dark line, or on the floor?
You write the rules with if/else blocks. The controller checks the rules from top to bottom many times a second, and the first rule that matches wins. If none match, the else rule runs.
Your goal: get around the whole track and cross the finish line without losing the line. Start with the preset buttons, then change the rules to see what happens.
Pick a preset or build your own rules, then press Run.
Your rules
You can change rules while the robot runs. Faster is not always better. Slow robots have more time to react.
In code
Challenges
- Finish a lap. Cross the finish line without losing the line.DONE
- Bonus: under 10 seconds. Hint: turn the speed up, but keep the robot on the line.DONE
WHY THE BAD RULES FAILIf the line is on the left, the robot should turn left, toward it. The bad preset does the opposite, so every correction makes things worse. Try swapping one rule and watch what changes.
Hint for building rules: left sensor sees the line means the robot has drifted to the right of the line, so it should steer left to get back. Same for the right side, in reverse.
Why smoother steering wins
You may have noticed your good robot wiggles. Its rules are on/off: either steer hard or go straight. There is nothing in between.
A smarter way is proportional steering. The robot reads how far off the line it is, and steers by an amount to match. A tiny mistake gets a tiny correction. A big mistake gets a big one. This works because the sensors give a range of numbers instead of only yes or no.
Watch both robots run the same track at the same speed. The orange solid path is on/off. The blue dashed path is proportional.
On / off steering
Proportional steering
Press Run both. “Avg off-center” is how far the robot's middle stayed from the line, on average. Smaller is better.
That idea, using the size of the mistake to decide the size of the fix, is the heart of a feedback loop. Real robots use fancier versions to hold a drone steady or keep a car in its lane. If you want to look one up later, the famous one is called PID control. You do not need it yet.
What robots are good and bad at
Robots are amazing at some jobs and clumsy at others. Knowing the difference helps engineers decide where to use them.
Robots are good at
- Repeating the same task thousands of times without getting bored or tired.
- Precision, like placing a tiny part in exactly the right spot.
- Dangerous places, such as bomb disposal, deep sea, space, or hot factories.
- Strength and speed for lifting heavy things or moving fast.
Robots find it hard to
- Handle surprises. A rule that works in the lab can fail when the floor is wet or the light changes.
- Use common sense. A robot does not know why something matters unless a person told it.
- Grab soft or odd objects. Picking up a grape without squishing it is surprisingly hard.
- Run for long. Batteries run out, and parts wear down.
A good rule of thumb: robots shine when the job is clear and repeatable. People shine when the job is messy and needs judgment. Often the best answer is a team of both.
Robots, AI, and careers
Does a robot need AI? No. Your line follower used a few rules that a person wrote, with no AI at all. Plenty of useful robots work this way.
AI helps with the “think” step when the world is messy. For example, a robot may use a camera and a trained model to tell a person from a box, or a ripe strawberry from a green one. Read What Is AI? and How Does Computer Vision Work? to see how that part works. AI can also make mistakes, so many robots keep simple safety rules, like “stop if something is too close,” running alongside it.
People who build robots
- Robotics engineerDesigns the robot and makes the parts work together.
- Software developerWrites the programs that read sensors and choose actions.
- Mechanical engineerDesigns the body, joints, and motors.
- Electrical engineerDesigns the circuits and power that connect everything.
- Controls engineerTunes feedback loops so robots move smoothly and safely.
- TechnicianBuilds, tests, and repairs robots in factories, labs, and farms.
Quick answers
What is a robot?
A common working definition is a machine that senses its surroundings, decides what to do using a computer program, and acts on the physical world, all in a repeating loop. People disagree about edge cases such as thermostats and smart speakers, so treat it as a useful test and not a law of nature.
Is a remote-control car a robot?
Usually not. A person does the sensing and thinking and the car only follows commands. If you add sensors and a program that steers the car without a person, such as a car that stops before it hits a wall, it starts to count as a robot.
How do robots sense the world?
Robots use sensors that turn the world into numbers. Common ones are ultrasonic distance sensors, light and line sensors, touch switches, cameras, and gyroscopes that measure turning. The robot's program reads those numbers many times a second.
Do robots need AI?
No. Many robots follow simple rules that a person wrote, like the line-following robot in this tutorial. AI can help with messy jobs, such as recognizing objects in a camera image, but a robot can work well without it.
What is a line-following robot?
A line-following robot uses light sensors to find a dark line on the floor and steers to stay on it. Its program is usually a few if/else rules, such as turning left when the left sensor sees the line. Line followers are a popular first robotics project.
How can I start learning robotics?
Start with programming basics, especially if/else statements and loops. Then try a simulator or a small kit with a microcontroller, a few sensors, and two motors. Build something simple like a line follower first, and make it smoother step by step.
Quick quiz
1. Which list shows the three steps in a robot's loop?
2. In the simulator, the robot's left sensor sees the line. What should it do?
3. Why does proportional steering usually work better than on/off steering?
Keep learning
You now know the loop behind every robot, and you have programmed one. Next, sharpen the if/else skills your robot used, or see how AI helps robots understand what they see.
Related: How to Give Instructions