Most computers you meet are hidden inside other devices: washing machines, cars, watches, medical pumps. These are embedded systems. Here you learn what makes them different and how a microcontroller is programmed.

What is an embedded system?

An embedded system is a computer built into a larger device to perform a dedicated function. Compared with a general-purpose PC it typically has:

  • A single fixed purpose, with software that rarely changes.
  • Limited memory, processing power and energy, so efficiency matters.
  • Often real-time requirements: it must respond within a deadline.
  • Direct interaction with hardware through sensors and actuators.
  • Very high reliability expectations, since many have no keyboard or screen and cannot easily be restarted.

Microcontrollers

A microcontroller (MCU) puts a CPU, RAM, program memory (flash) and input/output hardware on one chip. Popular teaching boards include Arduino (AVR chips), the BBC micro:bit and Raspberry Pi Pico. Key parts:

  • GPIO pins: general-purpose pins set as input (read a button) or output (light an LED).
  • ADC / PWM: read analogue sensors and drive motors or LED brightness.
  • Timers and interrupts: timers count clock ticks; an interrupt pauses the main program so an urgent event (a button press) is handled immediately by an interrupt service routine.
  • Communication buses: UART, I2C and SPI connect sensors and other chips.

A microcontroller differs from a microprocessor (like a PC’s CPU), which needs external RAM and peripherals.

Programming one

Embedded programs usually run an endless loop: set up hardware once, then repeatedly read, decide and act. This Arduino-style example blinks an LED and reads a button:

const int LED = 13;
const int BUTTON = 2;

void setup() {
  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(BUTTON) == LOW) {   // pressed
    digitalWrite(LED, HIGH);
  } else {
    digitalWrite(LED, LOW);
  }
}

Good practice includes keeping code small and efficient, using interrupts instead of constantly polling when timing matters, and testing on the device itself. Firmware is stored in non-volatile flash so it survives power loss. Because updating deployed devices is hard, security and reliability must be designed in from the start.

Check your understanding

1. What distinguishes a microcontroller from a microprocessor?

  • It has no memory
  • It integrates CPU, memory and I/O on a single chip
  • It is always faster
  • It only works with Windows

Answer: It integrates CPU, memory and I/O on a single chip. A microprocessor needs external memory and peripherals.

2. What is an interrupt used for?

  • Permanently stopping the program
  • Pausing the main program to handle an urgent event
  • Erasing memory
  • Increasing clock speed

Answer: Pausing the main program to handle an urgent event. The CPU runs a service routine and then resumes.

3. Which is typical of an embedded system?

  • A single dedicated function with limited resources
  • Runs any application the user installs
  • Has unlimited memory
  • Needs a large monitor

Answer: A single dedicated function with limited resources. This is why efficiency and reliability matter.

4. In the Arduino example, what does pinMode(LED, OUTPUT) do?

  • Reads a sensor
  • Configures the pin so the program can drive it
  • Deletes the pin
  • Starts a timer

Answer: Configures the pin so the program can drive it. Pins must be set as input or output before use.