Embedded SystemUnit 69 min read

Sensors & Actuators: Types, Working, Interfacing & Applications

Unit 6 of Embedded System covers the principles of sensors (input devices) and actuators (output devices) in embedded systems, their classifications, working mechanisms, interfacing techniques, and real-world applications in IoT, automation, and industrial control.

1. Introduction to Sensors and Actuators

Sensors and actuators are the eyes and hands of embedded systems, enabling interaction with the physical world.

  • Sensors detect physical quantities (light, temperature, motion) and convert them into electrical signals.
  • Actuators convert electrical signals into physical actions (movement, sound, heat).

Why are they essential?

Embedded systems rely on sensors to monitor environments (e.g., temperature in a fridge) and actuators to control devices (e.g., turning on a fan). Without them, systems would be "blind and deaf."


2. Classification of Sensors

Sensors can be categorized based on:

  1. Input Quantity Measured (Physical vs. Chemical)
  2. Output Signal Type (Analog vs. Digital)
  3. Sensing Mechanism (Active vs. Passive)

Comparison Table: Sensor Types

Type Examples Working Principle Applications
Analog Thermistor, Photodiode Output varies continuously (voltage/current) Temperature control, light detection
Digital DHT11, Ultrasonic Sensor Discrete output (0/1 or binary data) Distance measurement, humidity sensing
Active Piezoelectric Sensor Requires external power to generate signal Vibration sensing, pressure measurement
Passive RTD (Resistance Temp. Det.) No external power; relies on physical change Industrial temperature monitoring
Physical Accelerometer, Gyroscope Measures motion, force, or position Robotics, wearable fitness trackers
Chemical Gas Sensor (MQ-2) Detects gas concentration (e.g., CO₂, smoke) Air quality monitors, fire alarms

3. How Sensors Work: A Deep Dive

A. Analog Sensors

  • Output: Continuous voltage/current proportional to input.
  • Example: Thermistor (temperature sensor)
    • Working: Resistance changes with temperature (NTC: resistance decreases with heat; PTC: increases).
    • Equation: Where:
      • = Resistance at temperature ,
      • = Resistance at reference temperature ,
      • = Material constant.

Worked Example: Fridge Temperature Control A fridge uses an NTC thermistor to monitor temperature. At 25°C, , . If the fridge cools to 5°C, calculate the new resistance. Solution: The microcontroller reads this change and adjusts the compressor.

B. Digital Sensors

  • Output: Binary data (e.g., SPI/I2C protocol).
  • Example: Ultrasonic Sensor (HC-SR04)
    • Working: Emits sound waves and measures echo time to calculate distance.
    • Formula: (Divide by 2 because the sound travels to the object and back.)

4. Actuators: Converting Signals to Action

Actuators execute commands from the microcontroller. Types include:

  1. Mechanical (Servo motors, Stepper motors)
  2. Electrical (Relays, Solenoids)
  3. Thermal (Heaters, Coolers)
  4. Pneumatic/Hydraulic (Air pressure, fluid flow)

Comparison Table: Actuator Types

Type Examples Working Principle Applications
Servo Motor MG996R Rotates to a precise angle via PWM signals Robotics, RC cars, camera gimbals
Stepper Motor NEMA 17 Moves in discrete steps (full control) 3D printers, CNC machines
Relay SPDT Relay Electrically switches circuits (high power) Home automation, industrial control
Solenoid Linear Actuator Converts electrical energy to linear motion Door locks, valves
LCD/LED 16x2 LCD, WS2812B Displays data or indicates status Dashboards, status indicators

5. Interfacing Sensors and Actuators with Microcontrollers

A. Analog Sensor Interfacing (ADC)

  • Analog sensors (e.g., thermistor, potentiometer) require an Analog-to-Digital Converter (ADC).
  • Steps:
    1. Connect sensor output to microcontroller’s ADC pin.
    2. Configure ADC settings (resolution, reference voltage).
    3. Read digital value using ADC_Read() (e.g., in AVR or Arduino).

Example Code (Arduino):

int sensorPin = A0;  // Analog pin connected to thermistor
int sensorValue = 0;

void setup() {
  Serial.begin(9600);
}

void loop() {
  sensorValue = analogRead(sensorPin);  // Reads 0-1023
  float voltage = sensorValue * (5.0 / 1023.0);  // Convert to voltage
  Serial.println(voltage);
  delay(1000);
}

B. Digital Sensor Interfacing (SPI/I2C/UART)

  • SPI (Serial Peripheral Interface): Fast, full-duplex (e.g., MPU6050 accelerometer).
  • I2C (Inter-Integrated Circuit): Two-wire (SDA, SCL), multiple devices (e.g., DHT11).
  • UART: Asynchronous, simple (e.g., GPS modules).

Mermaid Diagram: SPI Communication

Fast, full-duplex (e.g., MPU6050)4 wires: MOSI, MISO, SCLK, SSSPI (Serial Peripheral Interface)Two-wire (SDA, SCL)Multiple devices (e.g., DHT11)I2C (Inter-Integrated Circuit)Simple (e.g., GPS modules)2 wires: TX, RXUART (Asynchronous)Digital Sensor Interfacing
Comparison of SPI, I2C, and UART protocols for digital sensor interfacing

C. Actuator Control

  • Servo Motors: Controlled via Pulse Width Modulation (PWM).
    • Example: Move servo to 90° (1.5ms pulse).
    #include <Servo.h>
    Servo myServo;
    void setup() { myServo.attach(9); }
    void loop() { myServo.write(90); delay(1000); }
    
  • Relays: Controlled via GPIO pins (high/low signal).

6. Real-World Applications in Nepal

011.2522.533.7545Smart Grid Monitoring45Traffic Management30Agricultural Sensors25
Estimated embedded system applications in Nepal (2023)

A. eSewa & Khalti (Digital Payments)

  • Sensors Used: NFC/RFID (for card swipes), Fingerprint sensors (security).
  • Actuators Used: Vibration motors (confirmation), LCD screens (transaction details).

B. Pathao (Ride-Hailing)

  • Sensors:
    • GPS (location tracking),
    • Accelerometer (detecting sharp turns for driver safety).
  • Actuators:
    • Electric motors (bike/scooter propulsion),
    • Horn (alert system).

C. NTC (Electricity Distribution)

  • Sensors:
    • Current sensors (overload detection),
    • Temperature sensors (transformer cooling).
  • Actuators:
    • Circuit breakers (automatic shutdown),
    • Relays (switching high-voltage lines).

Worked Example: Traffic Light Control System A traffic light system uses:

  • Sensors: Infrared sensors (detect vehicles),
  • Actuators: Relays (switch traffic lights),
  • Logic: If sensor detects a car → Activate green light for 30s, then switch to red.

Mermaid Diagram: Traffic Light Logic

Vehicle DetectedInfrared Sensor →Green Light (30s)30s ElapsedGreen → YellowLight (5s)5s ElapsedYellow → Red Light(Hold)Cycle RepeatsBack to Red
NTC Traffic Light Control Logic (Simplified)

7. Common Challenges & Solutions

Challenge Solution
Noise in analog signals Use filters (RC low-pass) or averaging.
Sensor drift (calibration) Periodic recalibration or software compensation.
Power supply issues Use voltage regulators (e.g., LM7805).
Actuator delay Optimize PWM frequency or use faster drivers.

8. Exam Tip

What to Focus On:

  1. Definitions: Clearly distinguish between analog vs. digital sensors and active vs. passive sensors.
  2. Calculations:
    • Thermistor resistance at a given temperature.
    • Ultrasonic sensor distance calculation.
  3. Interfacing:
    • How to connect a sensor to ADC/SPI/I2C.
    • PWM for servo motors.
  4. Applications:
    • Relate sensors/actuators to real systems (e.g., Khalti’s fingerprint sensor, Pathao’s GPS).
  5. Diagrams:
    • Always label sensor/actuator connections (VCC, GND, data pins).
    • Draw timing diagrams for SPI/I2C communication.

Common Mistakes to Avoid:

  • Forgetting to divide by 2 in ultrasonic distance formula.
  • Misconfiguring ADC reference voltage (e.g., using 3.3V instead of 5V).
  • Not pulling up/down I2C lines (SDA/SCL).

9. Summary Checklist

Before the exam, ensure you can: ✅ Explain the difference between a sensor and an actuator. ✅ Calculate resistance/temperature for a thermistor. ✅ Describe how an ultrasonic sensor measures distance. ✅ Interface a servo motor using PWM. ✅ List 3 sensors and 3 actuators used in eSewa/Khalti/Pathao. ✅ Draw a timing diagram for SPI communication.

Based on the PU BE Computer (PU) syllabus for Embedded System (ELX320), unit 6.

Discussion

Loading…