Please enable JavaScript to use CodeHS

STEM Lab 01 · Robotics

What Is a Robot? Sense, Think, Act

A robot is not just a machine with a face and metal arms. Every robot, from a vacuum that roams your floor to a rover on Mars, does the same three things over and over. Learn them, take a robot apart, then program one yourself.

Robotics ~20 min Beginner friendly
BRAIN 1 SENSE 2 THINK 3 ACT WALL
  1. SENSEread the world
  2. THINKpick a move
  3. ACTmove or change
§ 01 / The big idea

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.

Our definition

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. 1 · SENSEA sensor is a part that measures something, like light, distance, or touch, and turns it into a number.
  2. 2 · THINKA controller is the small computer that reads the numbers and runs the program.
  3. 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.


§ 02 / Sorting bench

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.

Fig. 01 · Sorting bench
Answered: 0 of 7

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.


§ 03 / Anatomy

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.

Fig. 02 · Cutaway, side view
+ BATTERY − CPU M M

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.

§ 04 / Sensor lab

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.

Fig. 03 · Sensor test bench
050 cm100150200

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.


§ 05 / The lab

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.

Fig. 04 · Line-follower simulator
Ready
Time0.0 s
Best lap--
Lap progress 0%

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.


§ 06 / Feedback loops

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.

Fig. 05 · Two steering styles

On / off steering

Time0.0 sAvg off-center--Result--

Proportional steering

Time0.0 sAvg off-center--Result--

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.


§ 07 / Strengths and limits

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.


§ 08 / Where AI fits

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.

§ 09 / FAQ

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.


§ 10 / Check yourself

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