There is a moment, the first time you watch a small robot you built avoid a wall on its own, when something clicks. A few minutes earlier it was a heap of motors and wire. Now it is behaving β sensing the world, deciding, and acting on that decision without anyone touching it. Nothing magical happened. You simply closed a loop. And that loop, repeated millions of times a second in a billion devices, is the entire secret of robotics.
Strip away the gleaming humanoids and the marketing, and every robot ever built runs the same three-beat cycle: perceive, think, act. Sensors turn the physical world into electricity. A microcontroller turns that electricity into decisions. Actuators turn decisions back into motion. Round and round, faster than you can blink. Understanding that loop is understanding robotics, whether the machine is a $30 hobby rover or a one-tonne rover on Mars.
Perceive: electricity from the world
A robotβs senses are transducers β devices that convert some physical quantity into an electrical signal the rest of the system can read. The variety is staggering, but they all do the same essential job.
An ultrasonic distance sensor chirps a 40 kHz pulse and times the echo, computing distance from the speed of sound β the same trick a bat uses, accurate to a centimetre or two over a few metres. An infrared sensor watches reflected light to follow a line on the floor. An inertial measurement unit (IMU), the same MEMS gyroscope-and-accelerometer chip found in your phone, reports rotation and acceleration so the robot knows its own orientation. Encoders on the wheels count rotations, letting the robot estimate how far it has travelled. A camera delivers millions of pixels for the ambitious task of actually seeing.
The crucial subtlety is that most of these signals start out analogue β a smoothly varying voltage β while the brain that consumes them is digital, fluent only in discrete numbers. Bridging that gap is the analogue-to-digital converter (ADC), a circuit that samples a voltage many thousands of times a second and reports each as a number, perhaps between 0 and 1023 on a humble 10-bit converter. Every robotβs perception begins with this quiet translation from the continuous world into countable digits.
Think: the microcontroller in the middle
Between the senses and the muscles sits the brain, and for most robots it is not a powerful computer at all but a microcontroller β a complete tiny computer on a single chip, with a processor, memory and input/output pins all integrated. An 8-bit Arduino runs at 16 MHz with a couple of kilobytes of RAM; an ESP32 adds Wi-Fi and dual cores at 240 MHz; larger robots lean on the ARM-based brains inside a Raspberry Pi or a dedicated module. What unites them is that they read inputs, run a program, and drive outputs, endlessly.
The program is where perception becomes behaviour. In its simplest form it is a chain of plain rules: if the front sensor reads less than 20 cm, stop and turn. String enough such rules together and surprisingly lifelike behaviour emerges from utterly mechanical logic. More sophisticated robots layer on control theory β most famously the PID controller, which smoothly corrects error by weighing how big it is, how long it has persisted, and how fast it is changing β so that a robot arm glides to its target instead of overshooting and oscillating.
The art of robotics software is rarely raw intelligence. It is handling the messiness of reality: the sensor that occasionally lies, the motor that stalls, the floor that is slipperier than expected.
A real robot spends most of its code not on grand decisions but on coping. Sensors are noisy, so readings get averaged or filtered. Wheels slip, so position estimates drift and must be corrected. The famous Kalman filter exists precisely to fuse several imperfect sensors into one estimate that is better than any single source β the same mathematics that guided Apollo to the Moon now runs on chips costing a few dollars.
Act: decisions become motion
A decision that moves nothing is just a number in memory. Actuators are how the loop closes back onto the physical world, and they are where the robotβs electrical decisions become muscle.
A DC motor spins when current flows, but a microcontroller pin can only supply a few milliamps β nowhere near enough to turn a wheel. So between the brain and the motor sits a motor driver, typically an H-bridge: an arrangement of transistors that lets a tiny control signal switch a large current, and lets the robot drive the motor forwards or backwards by reversing which transistors conduct. To control speed rather than just on-or-off, the microcontroller uses pulse-width modulation (PWM) β flicking the power on and off thousands of times a second and varying the fraction of time it stays on. A motor fed power 70% of the time runs at roughly 70% effort, all without wasting energy as heat in a variable resistor.
Other actuators specialise. A servo motor contains its own feedback circuit and moves to a commanded angle, perfect for steering or a robotic joint. A stepper motor advances in precise fixed increments β often 1.8 degrees per step, 200 steps per revolution β which is why 3D printers and CNC machines, where exact position matters more than speed, are full of them. Each is a different way of spending electricity to produce controlled movement.
The loop in action
Watch these three stages cooperate in a line-following robot, the classic first build. The infrared sensors beneath it report how much light reflects from the floor β bright tile or dark line. The ADC turns those reflections into numbers. The microcontroller compares the left and right readings: if the line has drifted to the right, the robot must steer right to recapture it. It computes new speeds for each wheel β slowing the right motor, perhaps β and emits PWM signals to the motor driver, which pushes the current the wheels need. The robot turns. The sensors, now looking at slightly different floor, report fresh numbers, and the entire cycle repeats β perhaps a thousand times a second, smoothly enough that the machine appears to glide along the line as if it could see.
Scale that exact loop up and you get a Mars rover. Its cameras and laser rangefinders replace the IR sensors; onboard computers hardened against radiation replace the Arduino; the actuators are precision geared motors driving six aluminium wheels. But the rover perceiving a rock, planning a path around it, and commanding its wheels is running the same perceive-think-act cycle as the toy on your desk. The difference is degree, not kind β more sensors, more computing, more careful engineering, wrapped around an identical beating heart.
Why the loop matters
What makes robotics feel like a culmination of electronics is that it forces every other concept to earn its keep at once. The water-pipe fundamentals of voltage and current decide whether your motor turns. Transistors in the H-bridge let small signals command large power. Analogue sensors meet digital logic at the ADC. Control theory tames the chaos of the real world. None of it is optional, because a robot is a system that must work end to end or it simply sits there, inert.
And there is a quieter lesson hiding in the loop. Autonomous behaviour β the thing that feels almost alive when your little rover dodges a wall β is not a single brilliant component. It is the relentless repetition of a simple cycle, fast enough and reliably enough that intention seems to emerge from it. Sense the world. Decide. Move. Repeat. Do that quickly enough, and a heap of motors and wire starts to look, unmistakably, like it has a mind of its own.