Architecture and Hardware

Sensors, Actuators and Real-World Interfacing in Embedded Systems

How embedded systems connect to the physical world: reading sensors through ADCs and buses, driving motors and relays safely, and the circuits in between.

On this page
  1. Sensors vs actuators: the basic difference
  2. The sense–decide–act loop
  3. Interfacing sensors
  4. Interfacing actuators
  5. The four main types of actuators
  6. Voltage levels, isolation and protection
  7. Software side of interfacing
  8. Examples of sensor–actuator pairs

An embedded system is only useful if it can sense what’s happening and do something about it. Sensors bring information in, actuators push action out, and between them sits a layer of interface circuitry and code that’s easy to underestimate. This article covers how that layer works in practice: reading sensors reliably, driving loads safely, and connecting both to a microcontroller.

It’s part of our embedded system architecture series. For a catalogue of specific sensor types, see our companion article on sensors commonly used in embedded systems.

Sensors vs actuators: the basic difference

Sensor Actuator
Direction Physical world → electrical signal Electrical signal → physical world
Role in the system Input Output
What it produces A voltage, current, resistance change, pulse or digital reading Motion, force, light, sound or heat
Typical power Usually low Often much higher than the logic can supply
Examples Thermistor, accelerometer, light sensor, limit switch Motor, solenoid, relay, heater, buzzer, LED

Some devices blur the line. A piezo element can sense vibration or produce sound, and a motor can act as a generator. But in a given design, each component usually plays one role.

The sense–decide–act loop

Most embedded control follows the same cycle:

  1. Sense: read one or more sensors.
  2. Decide: process the readings, applying filtering, thresholds, a state machine or a control algorithm such as PID.
  3. Act: update the actuators.
  4. Repeat, at a rate that suits the physical process.

A thermostat might run this loop once every few seconds. A motor controller might run it thousands of times per second. The loop rate, and how consistent it is, often shapes the software architecture.

Interfacing sensors

Digital on/off inputs

The simplest sensors are switches: push buttons, limit switches, reed switches and many motion detectors that output a high/low signal. Two details matter:

  • Pull-up or pull-down resistors. An unconnected input “floats” and reads randomly. A resistor, often built into the microcontroller, holds the input at a known level when the switch is open.
  • Debouncing. Mechanical contacts bounce, producing several rapid transitions for one press. Debouncing in software (ignoring changes for a few milliseconds) or in hardware (an RC filter, sometimes with a Schmitt trigger) gives one clean event.

Analog sensors and the ADC

Many sensors produce a voltage that varies continuously: thermistors in a voltage divider, light-dependent resistors, potentiometers and analog temperature sensors. An analog-to-digital converter (ADC) turns that voltage into a number.

Key ADC terms:

  • Resolution: the number of bits. A 10-bit ADC gives 1024 steps and a 12-bit ADC gives 4096. With a 3.3 V reference, one step of a 12-bit ADC is roughly 0.8 mV.
  • Reference voltage: the voltage that corresponds to full scale. Readings are only as accurate as the reference. Using the supply rail as the reference makes readings drift with supply noise.
  • Sampling rate: how often readings are taken. It must be fast enough for the signal you care about.
  • Input impedance: high-impedance sources may need a buffer amplifier, or a slower sampling time, to read accurately.

Microcontroller datasheets often quote ADC resolution that is better than the effective accuracy, so averaging several readings is common practice.

Signal conditioning

Raw sensor signals often need work before an ADC can read them:

  • Amplification: thermocouples, strain gauges and load cells produce tiny signals (microvolts to millivolts) that need an amplifier, such as an instrumentation amplifier or a dedicated chip like the HX711 used with load cells.
  • Filtering: a low-pass filter removes noise and prevents aliasing (high-frequency content masquerading as low-frequency readings).
  • Level shifting and scaling: a voltage divider can bring a 0–10 V industrial signal down into the ADC’s range.
  • Protection: series resistors and clamping diodes protect inputs from transients and static.

Digital-bus sensors

Many modern sensors include their own ADC and signal conditioning and report calibrated values over a digital interface:

  • I2C: very common for environmental sensors, IMUs and light sensors.
  • SPI: used where higher data rates are needed, such as fast IMUs or high-resolution ADCs.
  • UART: GPS modules and some particulate or CO₂ sensors.
  • 1-Wire: the DS18B20 temperature sensor is the best-known example.

Digital sensors move the analog design problem into the chip, which is why they’re so popular. Our guide to embedded communication protocols explains how these buses work.

Pulse and timing-based sensors

Some sensors encode their reading in timing: ultrasonic rangefinders report distance as an echo pulse width, rotary encoders produce pulse trains, and some sensors output a frequency or PWM duty cycle. Microcontroller timer input-capture peripherals measure these accurately without tying up the CPU.

Interfacing actuators

Why GPIO pins can’t drive loads directly

A microcontroller GPIO pin can typically source or sink only a few milliamps to a few tens of milliamps. The exact limit is in the datasheet, and there’s often a total limit for the whole chip as well. That’s enough for an LED with a resistor or a logic input. It’s nowhere near enough for a motor, solenoid, relay coil or heater, and trying can damage the chip. Loads also create electrical noise and voltage spikes that can reset or destroy logic circuits.

The pattern is always the same: the microcontroller sends a low-power control signal, and a driver stage switches the real load.

Transistor and MOSFET switches

For on/off control of DC loads, a transistor is the simplest driver. A common choice is an N-channel logic-level MOSFET used as a low-side switch, with the load between the supply and the MOSFET and the MOSFET between the load and ground. Points to check:

  • The MOSFET must turn fully on at your logic voltage (3.3 V or 5 V). Look for gate-threshold and on-resistance figures specified at that voltage, not just “logic level” in the title.
  • A gate resistor and a pull-down resistor keep the switch behaving predictably, including during reset when the GPIO isn’t yet configured.
  • Inductive loads (motors, solenoids, relay coils) need a flyback diode across the load. When current is switched off, the collapsing magnetic field produces a voltage spike that can destroy the transistor otherwise.

Relays and solid-state relays

A relay uses a small coil to close electrically separate contacts, so a low-voltage circuit can switch a different, sometimes higher-voltage circuit. The coil usually needs a transistor driver and a flyback diode, which ready-made relay modules generally include. Solid-state relays switch electronically with no moving parts, but they have their own limits on load type and heat.

Safety note: switching mains voltage is hazardous. Mains wiring should follow local electrical codes and use parts rated for the voltage and current. If you aren’t qualified to work on mains circuits, use certified off-the-shelf switching products or have the work done by someone who is.

DC motors and H-bridges

To run a DC motor in both directions, you need an H-bridge: four switches arranged so current can flow through the motor either way. Integrated motor-driver ICs and modules package the H-bridge with protection features. Speed is controlled with PWM (pulse-width modulation): switching the motor on and off rapidly and varying the on-time fraction. Older bipolar driver chips waste noticeably more power as heat than modern MOSFET-based drivers, which matters for battery-powered designs.

Servos and stepper motors

  • Hobby servos contain their own motor, gearbox, position sensor and control circuit. They’re commanded by a pulse repeated about every 20 ms, where the pulse width (commonly around 1–2 ms) sets the position. They still need a power supply that can handle their current. Powering them from a microcontroller board’s regulator is a common cause of resets.
  • Stepper motors move in fixed steps and are used where you need repeatable positioning without a feedback sensor, as in 3D printers and CNC machines. A stepper driver IC handles the coil currents. The microcontroller usually just sends step and direction signals.

PWM and DACs

PWM isn’t only for motors. It dims LEDs, drives buzzers and, with a filter, approximates an analog voltage. Where a true analog output is needed, such as audio or setting a reference level, a DAC (digital-to-analog converter) produces it directly. Some microcontrollers include one, and external DAC chips are common.

The four main types of actuators

Actuators are often grouped by the energy they use:

  1. Electric: motors (DC, brushless, stepper, servo), solenoids and electric linear actuators. These are the most common in embedded systems because they connect most directly to electronics.
  2. Hydraulic: use pressurized fluid to produce large forces, as in heavy machinery and presses.
  3. Pneumatic: use compressed air, common in factory automation for fast, simple motions.
  4. Mechanical: convert one kind of motion into another, such as a screw drive, rack and pinion or cam. These are often combined with an electric motor.

Some lists add thermal actuators (shape-memory alloys, bimetallic strips) or piezoelectric actuators. In an embedded system, hydraulic and pneumatic actuators are usually controlled indirectly, with the microcontroller driving electrically operated valves.

Voltage levels, isolation and protection

  • 3.3 V vs 5 V logic. Many modern microcontrollers run at 3.3 V and aren’t 5 V-tolerant on every pin. Connecting a 5 V output directly to a 3.3 V input can cause damage, so use a level shifter or divider where needed, and check the datasheet.
  • Separate power for loads. Run motors and other noisy loads from their own supply. Share a ground with the logic, but route high-current return paths carefully.
  • Decoupling. Put capacitors near each chip’s power pins, plus bulk capacitance near motor drivers.
  • Optoisolation. Optocouplers or digital isolators electrically separate the microcontroller from noisy or high-voltage circuitry. They’re common in industrial I/O.
  • Transient protection. TVS diodes and series resistors help on inputs connected to long cables or the outside world.

Software side of interfacing

The circuitry is only half the job. The firmware also has to handle:

  • Sampling strategy: polling in a loop, timer-triggered sampling, or interrupts on pin changes. DMA can stream ADC readings into memory with little CPU involvement.
  • Filtering: moving averages, median filters (good for rejecting spikes) and simple low-pass filters.
  • Calibration: offsets and scale factors, sometimes stored per device in non-volatile memory.
  • Plausibility checks: rejecting impossible readings and detecting disconnected or failed sensors.
  • Safe defaults: actuators should go to a safe state at power-up, on reset and when a fault is detected. That’s one reason pull-down resistors on driver inputs and watchdog timers matter.

Examples of sensor–actuator pairs

Application Sensor Actuator
Thermostat Temperature sensor Relay switching a heater or boiler
Automatic plant watering Soil moisture sensor Small pump via a MOSFET
Line-following robot IR reflectance sensors DC motors via an H-bridge
Automatic door PIR or radar presence sensor Motor or solenoid lock
Camera gimbal IMU (accelerometer + gyroscope) Brushless motors
3D printer Thermistor, endstop switches Heater cartridge, stepper motors

In each case the pattern is the same: condition the signal coming in, protect the logic, drive the load through a suitable stage, and let the firmware close the loop.

The complete guide to architecture and hardware

Embedded System Architecture: Hardware and Software Components
Read the guide

Keep exploring

Guides from other topics

All topics →