Skip to content
Home » Embedded Systems » Sensors » Sensors and Actuators in Embedded Systems: Types, Examples, Applications

Sensors and Actuators in Embedded Systems: Types, Examples, Applications

Controller block diagram showing sensors input, processing, and actuators output in embedded systems architecture
Embedded Systems Learning Path
Part 43 of 129View Full Path →

KEY TAKEAWAYS

  • Sensors convert physical quantities (temperature, light, motion, pressure) into electrical signals the MCU can read.
  • Actuators convert electrical signals into physical actions — motors, solenoids, relays, and speakers are the most common types.
  • Sensors are classified as active vs passive, analog vs digital, and contact vs non-contact depending on their operating principle.
  • The signal chain (sensor → conditioning → ADC → MCU → DAC/PWM → driver → actuator) is the fundamental architecture of every embedded control system.
  • PWM-based motor control and servo positioning are essential actuator skills for embedded engineers.

Sensor and actuator systems form the backbone of embedded control, converting physical measurements into intelligent automated responses.

Sensor actuators form the backbone of modern embedded systems, enabling intelligent interaction between digital devices and the physical world.

In the world of automation and smart systems, two key components play pivotal roles: sensors and actuators. These devices form the input-output interface between embedded systems and the physical world. This guide explains sensor classification, actuator types, the complete signal chain, and provides working code examples for motor control and a real-world temperature-controlled fan project.

What Are Sensors?

Sensors are devices that detect or measure physical properties and convert them into electrical signals that a microcontroller can read. They serve as the “eyes and ears” of an embedded system, monitoring the environment and providing the data needed for decision-making. Common sensor types include temperature sensors, proximity sensors, pressure sensors, light sensors, humidity sensors, and accelerometers.

Sensor Classification

Sensors can be classified along several dimensions, and understanding these categories helps you choose the right sensor for your application.

Active vs passive sensors: Active sensors require an external power source to operate and generate an output signal. Examples include ultrasonic rangefinders (which emit and receive sound pulses), RTDs (which require excitation current), and photodiodes in photoconductive mode. Passive sensors generate their own electrical signal from the measured quantity without external power. Examples include thermocouples (which generate voltage from temperature difference), piezoelectric sensors (which generate charge from pressure), and photovoltaic cells.

Analog vs digital sensors: Analog sensors produce a continuous voltage or current proportional to the measured quantity — a thermistor’s resistance changes continuously with temperature, and an LM35 outputs 10mV per degree Celsius. These require an ADC to convert to digital values. Digital sensors include their own ADC and output data over a digital protocol (I2C, SPI, UART, or single-wire). The DHT22, BMP280, and MPU6050 are digital sensors. Digital sensors are generally easier to interface but less flexible in terms of sampling rate and resolution.

Contact vs non-contact sensors: Contact sensors must physically touch the measured object — a thermocouple touching a pipe, a strain gauge bonded to a beam, or a limit switch pressed by a moving part. Non-contact sensors measure at a distance — an infrared thermometer, an ultrasonic distance sensor, a PIR motion detector, or a Hall effect current sensor. Non-contact sensors are preferred when the measurement target is moving, hazardous, or inaccessible.

What Are Actuators?

Actuators convert electrical signals into physical actions. They are the “muscles” of an embedded system, enabling it to affect the physical world based on the decisions made by the microcontroller. The main actuator types used in embedded systems are:

DC motors: Convert electrical energy into continuous rotational motion. Speed is controlled by varying the supply voltage, most commonly using PWM (pulse width modulation). Direction is controlled using an H-bridge driver circuit (L298N, DRV8833). Used in fans, pumps, conveyor belts, and wheels for mobile robots.

Servo motors: Contain a DC motor, gearbox, and position feedback circuit in a single package. They rotate to a specific angle (typically 0-180°) based on the width of a PWM pulse. A 1ms pulse corresponds to 0°, 1.5ms to 90°, and 2ms to 180°, with a 20ms period (50Hz). Used in robotic arms, camera gimbals, RC vehicles, and any application requiring precise angular positioning.

Stepper motors: Rotate in precise discrete steps (typically 1.8° per step, giving 200 steps per revolution). They do not require position feedback because each step moves by a known, repeatable angle. Driven by specialized driver ICs (A4988, DRV8825) that handle the complex coil switching sequence. Used in 3D printers, CNC machines, and precision positioning systems.

Solenoids: Electromagnetic devices that convert electrical energy into linear push or pull motion. When current flows through the coil, a magnetic field pulls the plunger. Used in door locks, valves, vending machines, and pinball machines. Require a flyback diode across the coil to protect the driving transistor from the voltage spike when current is switched off.

Relays: Electrically operated switches that use a small control signal to switch a much larger load. An MCU GPIO pin driving a relay through a transistor can control 120V/240V AC appliances. Solid-state relays (SSRs) have no moving parts and switch faster but dissipate more heat. Mechanical relays provide galvanic isolation between the control and load circuits.

The Sensor-Actuator Signal Chain

Every embedded control system follows a fundamental signal chain architecture:

Sensor → Signal Conditioning → ADC → MCU (processing) → DAC/PWM → Driver → Actuator

The sensor converts a physical quantity into an electrical signal. Signal conditioning (amplification, filtering, level shifting) prepares the signal for the ADC. The ADC converts the analog signal to a digital value the MCU can process. The MCU runs the control algorithm (PID controller, state machine, threshold comparison) and generates a control output. The output (PWM or DAC) drives a power stage (H-bridge, MOSFET, relay driver) that controls the actuator. The actuator affects the physical world, which the sensor then measures again — closing the control loop.

Understanding this signal chain is crucial because problems can occur at any stage. A noisy sensor signal corrupts the ADC reading. Insufficient amplification wastes ADC resolution. A slow control loop causes oscillation. An undersized driver cannot supply enough current to the actuator.

PWM Motor Speed Control: C Code Example

PWM (Pulse Width Modulation) is the standard method for controlling DC motor speed. The MCU generates a square wave at a fixed frequency (typically 1-25 kHz for DC motors). The duty cycle (percentage of time the signal is high) determines the average voltage applied to the motor, and thus its speed. 0% duty cycle = motor off, 100% = full speed.

/* Timer-based PWM motor control on STM32 */
#include "stm32f4xx_hal.h"

#define MOTOR_PWM_FREQ   20000  /* 20 kHz - above audible range */

static TIM_HandleTypeDef htim_motor;

/**
 * Initialize Timer 3 Channel 1 for PWM output.
 * Motor connected via H-bridge (L298N) to PA6 (TIM3_CH1).
 */
void motor_pwm_init(void) {
    __HAL_RCC_TIM3_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();

    /* Configure PA6 as TIM3_CH1 alternate function */
    GPIO_InitTypeDef gpio = {0};
    gpio.Pin = GPIO_PIN_6;
    gpio.Mode = GPIO_MODE_AF_PP;
    gpio.Alternate = GPIO_AF2_TIM3;
    gpio.Speed = GPIO_SPEED_FREQ_HIGH;
    HAL_GPIO_Init(GPIOA, &gpio);

    /* Timer configuration */
    htim_motor.Instance = TIM3;
    htim_motor.Init.Prescaler = 0;
    htim_motor.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim_motor.Init.Period = (SystemCoreClock / MOTOR_PWM_FREQ) - 1;
    htim_motor.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
    HAL_TIM_PWM_Init(&htim_motor);

    /* PWM channel configuration */
    TIM_OC_InitTypeDef oc = {0};
    oc.OCMode = TIM_OCMODE_PWM1;
    oc.Pulse = 0;  /* Start with motor off */
    oc.OCPolarity = TIM_OCPOLARITY_HIGH;
    HAL_TIM_PWM_ConfigChannel(&htim_motor, &oc, TIM_CHANNEL_1);
    HAL_TIM_PWM_Start(&htim_motor, TIM_CHANNEL_1);
}

/**
 * Set motor speed as a percentage (0-100).
 */
void motor_set_speed(uint8_t percent) {
    if (percent > 100) percent = 100;
    uint32_t period = __HAL_TIM_GET_AUTORELOAD(&htim_motor);
    uint32_t pulse = (period * percent) / 100;
    __HAL_TIM_SET_COMPARE(&htim_motor, TIM_CHANNEL_1, pulse);
}

Servo Motor Control: C Code Example

Standard hobby servos expect a 50Hz PWM signal (20ms period). The pulse width determines the angle: 1.0ms = 0°, 1.5ms = 90° (center), 2.0ms = 180°. The relationship is linear, so the formula to convert angle to pulse width is: pulse_ms = 1.0 + (angle / 180.0) × 1.0.

/* Servo motor control - angle to PWM pulse width */
#include "stm32f4xx_hal.h"

#define SERVO_PWM_FREQ   50     /* 50 Hz = 20ms period */
#define SERVO_MIN_US     1000   /* 1.0 ms = 0 degrees */
#define SERVO_MAX_US     2000   /* 2.0 ms = 180 degrees */

static TIM_HandleTypeDef htim_servo;

void servo_init(void) {
    __HAL_RCC_TIM2_CLK_ENABLE();
    __HAL_RCC_GPIOA_CLK_ENABLE();

    GPIO_InitTypeDef gpio = {0};
    gpio.Pin = GPIO_PIN_0;  /* PA0 = TIM2_CH1 */
    gpio.Mode = GPIO_MODE_AF_PP;
    gpio.Alternate = GPIO_AF1_TIM2;
    gpio.Speed = GPIO_SPEED_FREQ_LOW;
    HAL_GPIO_Init(GPIOA, &gpio);

    /* Prescale to 1 MHz tick (1 us resolution) */
    htim_servo.Instance = TIM2;
    htim_servo.Init.Prescaler = (SystemCoreClock / 1000000) - 1;
    htim_servo.Init.CounterMode = TIM_COUNTERMODE_UP;
    htim_servo.Init.Period = 20000 - 1;  /* 20ms period */
    HAL_TIM_PWM_Init(&htim_servo);

    TIM_OC_InitTypeDef oc = {0};
    oc.OCMode = TIM_OCMODE_PWM1;
    oc.Pulse = 1500;  /* Start at center (90 degrees) */
    oc.OCPolarity = TIM_OCPOLARITY_HIGH;
    HAL_TIM_PWM_ConfigChannel(&htim_servo, &oc, TIM_CHANNEL_1);
    HAL_TIM_PWM_Start(&htim_servo, TIM_CHANNEL_1);
}

/**
 * Set servo angle (0-180 degrees).
 * Converts angle to pulse width: 0° = 1000us, 180° = 2000us.
 */
void servo_set_angle(uint16_t angle_deg) {
    if (angle_deg > 180) angle_deg = 180;
    uint32_t pulse_us = SERVO_MIN_US +
                        ((uint32_t)(SERVO_MAX_US - SERVO_MIN_US) * angle_deg) / 180;
    __HAL_TIM_SET_COMPARE(&htim_servo, TIM_CHANNEL_1, pulse_us);
}

Real-World Project: Temperature-Controlled Fan

This project demonstrates a complete sensor-actuator system. An analog temperature sensor (LM35) is read by the ADC, and the MCU adjusts a cooling fan speed via PWM based on the temperature. Below 30°C the fan is off, above 60°C the fan runs at full speed, and between these thresholds the speed scales linearly.

/* Temperature-controlled fan: LM35 sensor + PWM DC fan */
#include "stm32f4xx_hal.h"

#define TEMP_FAN_OFF    30.0f   /* Fan off below 30°C */
#define TEMP_FAN_MAX    60.0f   /* Fan full speed at 60°C */
#define ADC_VREF        3.3f
#define ADC_RESOLUTION  4096.0f
#define LM35_MV_PER_C   10.0f  /* LM35 outputs 10mV per °C */

extern ADC_HandleTypeDef hadc1;  /* ADC configured for LM35 on PA1 */

/**
 * Read LM35 temperature sensor via ADC.
 * LM35 output: 10mV per °C, 0V at 0°C.
 */
float read_temperature(void) {
    HAL_ADC_Start(&hadc1);
    HAL_ADC_PollForConversion(&hadc1, 10);
    uint16_t adc_val = HAL_ADC_GetValue(&hadc1);

    float voltage_mv = (adc_val / ADC_RESOLUTION) * ADC_VREF * 1000.0f;
    return voltage_mv / LM35_MV_PER_C;
}

/**
 * Map temperature to fan speed percentage.
 * Linear ramp from 0% at TEMP_FAN_OFF to 100% at TEMP_FAN_MAX.
 */
uint8_t temp_to_fan_speed(float temp_c) {
    if (temp_c <= TEMP_FAN_OFF) return 0;
    if (temp_c >= TEMP_FAN_MAX) return 100;
    return (uint8_t)(((temp_c - TEMP_FAN_OFF) /
                      (TEMP_FAN_MAX - TEMP_FAN_OFF)) * 100.0f);
}

/**
 * Main control loop - reads temperature, adjusts fan speed.
 * Call motor_pwm_init() before entering this loop.
 */
void fan_control_task(void) {
    while (1) {
        float temperature = read_temperature();
        uint8_t speed = temp_to_fan_speed(temperature);
        motor_set_speed(speed);

        /* Optional: add hysteresis to prevent rapid on/off cycling */
        /* Optional: add moving average filter for stable readings */

        HAL_Delay(1000);  /* Update every second */
    }
}

Selection Criteria for Sensors and Actuators

Choosing the right sensor or actuator for your project requires evaluating several key parameters:

  • Measurement range: Does the sensor cover your expected range with margin? A temperature sensor rated 0-100°C is insufficient for an oven controller that reaches 250°C.
  • Accuracy and resolution: Accuracy is how close the reading is to the true value. Resolution is the smallest change the sensor can detect. A sensor can have high resolution but poor accuracy (consistent offset). Both matter for your application.
  • Interface compatibility: Does the sensor output match your MCU’s capabilities? Analog sensors need an ADC. Digital sensors need a compatible bus (I2C, SPI, UART). Ensure voltage levels match.
  • Power consumption: Critical for battery-powered devices. Check both active and sleep current. A sensor drawing 1mA continuously drains a 500mAh battery in 20 days.
  • Environmental rating: Operating temperature range, IP rating for water/dust protection, vibration tolerance. Outdoor and industrial applications have much stricter requirements than indoor consumer products.
  • Cost and availability: For prototyping, a $10 breakout module is fine. For production of 10,000 units, the raw IC cost, second-source availability, and long-term supply chain reliability become critical factors.
  • Actuator sizing: Motors must provide sufficient torque at the required speed. Solenoids must generate enough force. Relays must handle the load current with margin. Always check the datasheet maximum ratings and derate by 20-30% for reliability.

Read – Need a Sensor? Selection Criteria for Sensors – NerdyElectronics

📖 Related: Analog vs Digital Sensors in Embedded SystemsLM35 Temperature Sensor: Working, Circuit, and Arduino Code

Related on this site

Leave a Reply

Your email address will not be published. Required fields are marked *