An embedded system is a small computer built into a device to perform a dedicated task, usually in real time, with limited memory and power. A washing machine controller, a car engine unit and an IoT sensor node are embedded systems.

Sensors

A sensor converts a physical quantity into an electrical signal. Examples: temperature (LM35, DHT11, thermistor), humidity, light (LDR), motion (PIR), distance (ultrasonic), gas, pressure, accelerometer. Sensors are analog (continuous voltage) or digital (a digital value or protocol). An analog-to-digital converter (ADC) turns the voltage into a number: for an n-bit ADC with reference voltage Vref, the number of levels is 2ⁿ and the resolution is Vref / 2ⁿ per step. Important sensor properties are range, accuracy, resolution, response time and power use.

Actuators

An actuator converts an electrical command into physical action: LED, buzzer, relay, DC motor, servo motor, stepper motor, solenoid valve and heater. Actuators with larger current need a driver circuit (transistor or relay) because a microcontroller pin supplies only a few milliamperes. A servo rotates to a given angle; a stepper rotates in fixed steps.

Microcontrollers

A microcontroller (MCU) is a single chip containing a processor, memory (flash and RAM), input/output pins and peripherals (timers, ADC, UART, I2C, SPI, PWM). Arduino Uno (ATmega328P, 8-bit, 5 V, 32 KB flash, 2 KB RAM) is easy for learning. ESP32 (32-bit, built-in Wi-Fi and Bluetooth) suits connected devices. A Raspberry Pi is a small single-board computer that runs Linux and is used as a gateway or edge device. The usual embedded program runs a loop: read sensors, decide, act, repeat.

Definition: Microcontroller. A single chip that holds a processor, memory and input and output peripherals, designed to control a device by reading sensors and driving actuators.

Table 1.4: Common boards

Board Type Features Best for
Arduino Uno 8-bit MCU 5 V, 14 digital pins, 6 analog inputs Learning, simple control
ESP32 32-bit MCU Wi-Fi, Bluetooth, low power modes Connected devices
Raspberry Pi 4 Single-board computer Linux, USB, network Gateway, edge, vision

Example 1.4: Reading an analog temperature sensor

Problem: An LM35 gives 10 mV per degree Celsius. An Arduino with a 10-bit ADC and 5 V reference reads the value 77. Find the resolution, the voltage and the temperature.

Solution:

  1. Levels = 2¹⁰ = 1,024, so the resolution = 5 / 1,024 = 0.00488 V (4.88 mV).
  2. Voltage = 77 × 0.00488 = 0.376 V.
  3. Temperature = 0.376 V / 0.010 V per °C = 37.6 °C.

Result: The reading 77 means about 37.6 °C; each ADC step represents about 0.49 °C.

bits, vref, raw = 10, 5.0, 77
step = vref / 2 ** bits
volt = raw * step
print("Resolution (mV):", round(step * 1000, 2))
print("Voltage (V):", round(volt, 3))
print("Temperature (C):", round(volt / 0.010, 1))

Output

Resolution (mV): 4.88
Voltage (V): 0.376
Temperature (C): 37.6

Common mistakes

  • Driving a motor or relay directly from a microcontroller pin.
  • Forgetting the ADC resolution when reading sensors.
  • Confusing a microcontroller with a full computer.
  • Ignoring power limits of the board.

Key takeaways

  • Embedded system: dedicated, real-time, limited resources.
  • Sensor in, actuator out; ADC converts analog to digital.
  • Resolution = Vref / 2^n.
  • MCU: processor, memory, I/O; Raspberry Pi is a Linux computer.

Practice questions

  1. What is a microcontroller?
  2. What does an ADC do?
  3. Why use a driver for a motor?

Answers to the practice questions

  1. A single chip with processor, memory and I/O peripherals that controls a device.
  2. It converts an analog voltage into a digital number.
  3. A microcontroller pin supplies too little current.

Sources

  • Official BCA syllabus Internet of Things, course code 25BCA406DS01, Unit I