The Sensor–Actuator Loop
Every robotic system fundamentally performs a sense → think → act cycle. Sensors convert physical quantities (distance, temperature, force, angle) into electrical signals that a microcontroller can read. Actuators convert electrical signals back into physical motion or effects.
Understanding how to interface sensors and actuators correctly — choosing the right protocol, setting appropriate signal levels, handling timing — is one of the most practically important skills in robotics engineering.
Common Sensor Types in Robotics
| Sensor | Measured Quantity | Interface | Typical Range |
|---|---|---|---|
| HC-SR04 Ultrasonic | Distance | GPIO (trigger/echo) | 2 cm – 4 m |
| IR Distance (GP2Y0A) | Distance | Analog (ADC) | 10 – 80 cm |
| MPU-6050 IMU | Acceleration + Gyro | I²C (0x68) | ±2–16 g, ±250–2000 °/s |
| BMP280 Barometer | Pressure + Temperature | I²C or SPI | 300–1100 hPa |
| Encoder (incremental) | Angular position/speed | GPIO interrupt (A/B) | Application dependent |
| Force Sensitive Resistor | Contact force | Analog (ADC) | 0.1 N – 100 N |
| Hall Effect Sensor | Magnetic field / RPM | GPIO (digital) | Proximity / RPM |
| Lidar (RPLIDAR A1) | 2D distance scan | UART / USB | 0.15 – 12 m, 360° |
| Camera (OV5647) | Image / video | MIPI CSI / USB | Up to 5 MP |
Digital Interfaces: I²C, SPI, and UART
I²C (Inter-Integrated Circuit) uses two wires (SCL clock, SDA data) and supports up to 127 devices on the same bus, each with a unique 7-bit address. Data rates are 100 kHz (standard), 400 kHz (fast), or 1 MHz (fast+). Pull-up resistors (4.7 kΩ typical) are required on both lines. Good for sensors where speed is not critical: IMUs, barometers, EEPROMs.
SPI (Serial Peripheral Interface) uses four wires: SCLK (clock), MOSI (master-out), MISO (master-in), and CS (chip-select, one per device). SPI is full-duplex and typically faster than I²C (10–50 MHz). Used for displays, SD cards, high-speed ADCs/DACs, and fast sensors.
UART (Universal Asynchronous Receiver-Transmitter) is point-to-point (one TX to one RX). No clock wire — both sides agree on baud rate (9600, 115200, 1 Mbaud, etc.). Widely used for GPS modules, LIDAR sensors, Bluetooth/Wi-Fi modules, and host PC communication.
Analog Sensing: ADC Best Practices
- 01
The ADC resolution determines the smallest detectable change: a 10-bit ADC with 5 V reference has 5 V / 1024 ≈ 4.9 mV per step
- 02
Always decouple the analog power supply with 100 nF and 10 µF capacitors close to the ADC pin
- 03
Use averaging (e.g., 16-sample moving average) to reduce noise in slowly-changing signals
- 04
Never exceed the MCU's maximum analog input voltage — add a resistor divider for higher voltage signals
- 05
The ADC sample-and-hold capacitor needs settling time — wait after switching multiplexer channels
Actuators: Motors and Their Drivers
DC motors require an H-bridge driver to enable bidirectional control and current amplification. Common H-bridge ICs: L298N (up to 2 A per channel), DRV8833 (up to 1.5 A), TB6612FNG (1.2 A continuous). The PWM duty cycle sent to the enable pin controls speed; the direction pins select the polarity.
Servo motors (RC servos) accept a 50 Hz PWM signal where pulse width encodes position: 1 ms → 0°, 1.5 ms → 90°, 2 ms → 180°. They contain a built-in H-bridge, gearbox, and position feedback potentiometer. Servos are ideal for steering linkages, pan-tilt camera mounts, and simple gripper mechanisms.
Stepper motors move in discrete angular steps (typically 1.8°/step = 200 steps/revolution). Drivers like the A4988 or DRV8825 accept STEP and DIR signals; the step count is tracked in software to determine absolute position without a separate encoder. Used in 3D printers, CNC machines, and precision positioning stages.
Brushless DC (BLDC) motors are driven by an ESC (Electronic Speed Controller) which handles the three-phase commutation. The ESC accepts a servo-style PWM signal (1–2 ms). BLDC motors offer high efficiency and power-to-weight ratios — used in drone propulsion and high-performance wheeled robots.
Motor Type Comparison
| Type | Control Signal | Feedback Needed? | Best For |
|---|---|---|---|
| DC Motor (brushed) | PWM via H-bridge | Encoder for position/speed | Wheels, conveyor, simple mechanisms |
| RC Servo | 50 Hz PWM (1–2 ms) | Built-in (pot) | Pan-tilt, steering, grippers |
| Stepper Motor | STEP/DIR pulses | Open-loop (count steps) | CNC, 3D printers, precise positioning |
| BLDC / PMSM | PWM to ESC or FOC driver | Encoder or Hall sensors | Drones, high-speed wheels, actuators |
| Linear Actuator | PWM via H-bridge | Optional limit switches | Lifting, clamping, pressing |