Where embedded systems live and what limits them
About this lesson
An embedded system is a small computer hidden inside a device to do one job: a thermostat, a washing machine, a car, a watch. Open a room thermostat built on an Arduino Uno R3 and follow its firmware as it senses the temperature, decides, and switches a heater, once a second, forever. Then meet the limits every embedded designer works inside: 32 KB of flash, 2 KB of SRAM, a 16 MHz clock and a battery. The Hardware lesson “Microcontrollers: a whole computer on one chip” explains what is inside the chip; here we stay with what it does in a device.
Computers hidden inside things
An embedded system is a computer built into a device to do one job. Thermostats, washing machines, cars and watches all have one. You never see it or install apps on it: it just runs the device.
embedded system a computer hidden inside a device,
built for one dedicated job
thermostat
washer
car
watch
no screen of apps, no keyboard: it just runs the deviceRead the lesson step by step
Computers hidden inside things
An embedded system is a computer built into a device to do one job. Thermostats, washing machines, cars and watches all have one. You never see it or install apps on it: it just runs the device.
embedded system a computer hidden inside a device, built for one dedicated job thermostat washer car watch no screen of apps, no keyboard: it just runs the deviceA computer on one chip
Open our thermostat and you find a microcontroller, or MCU: processor, memory and input/output pins on a single chip. Ours is the ATmega328P on an Arduino Uno R3 board, a common one to learn on.
MCU ATmega328P (board: Arduino Uno R3) processor carries out instructions flash 32 KB, keeps the program with the power off SRAM 2 KB, the working values, lost at power off pins wires to sensors and switches all of it on one chipOne program, forever
The chip runs just one program, called firmware. It is copied into flash memory, which keeps it with the power off. At power on the chip starts it, and loop() repeats until the power goes.
firmware the one program on the chip flash 32 KB, survives power off power on -> setup() once -> loop() again and again // Arduino Uno R3: TMP36 sensor on A0, heater relay on pin 8 const int HEAT = 8; int readTemp() { // degrees C from a TMP36 int raw = analogRead(A0); // 0..1023 for 0..5 V return raw * 500L / 1024 - 50; // 10 mV per degree, 0.5 V at 0 C } void setup() { pinMode(HEAT, OUTPUT); } void loop() { int t = readTemp(); digitalWrite(HEAT, t < 20); delay(1000); }Sense: read the temperature
The sensor puts out about 0.69 volts. analogRead turns that into a number from 0 to 1023: 141. readTemp turns 141 into 18 degrees and keeps it in t, a variable in SRAM.
line 2 int t = readTemp(); sensor TMP36 says about 688 mV (18.8 C) ADC 688 mV of 5000 mV, 10 bits -> raw 141 readTemp 141 * 500 / 1024 - 50 = 18 SRAM t = 18Decide: is 18 below 20?
Next line: compare t with 20 degrees. 18 < 20 is true, so the room is too cold. In Arduino code true counts as 1, and 1 is HIGH: the pin should turn on.
line 3 digitalWrite(HEAT, t < 20); compare 18 < 20 -> true true = 1 = HIGH false = 0 = LOWAct: switch the heater on
digitalWrite sets pin 8 HIGH: 5 volts. That small signal closes a relay, a switch for bigger currents, and the heater turns on. Sense, decide, act: that is the whole job.
line 3 digitalWrite(HEAT, 1) pin 8 HIGH = 5 V relay closes -> heater on sense -> decide -> actWait, then do it again
delay(1000) waits one second, then loop() runs again. Now it reads 21, not below 20, so the heater turns off. Some answers must also come on time: an airbag that fires late fails. Systems with deadlines are called real-time.
line 4 delay(1000); one second loop again: raw 146 -> t = 21 compare 21 < 20 -> false -> pin 8 LOW, heater off real-time: a late answer is a wrong answerLimit: 32 KB and 2 KB
The whole program must fit in 32 KB of flash, and every variable in 2 KB of SRAM. An int takes 2 bytes, so 2,048 bytes hold at most 1,024 of them. Bigger chips have more: an ESP32 has 520 KB of SRAM.
flash 32 KB the program SRAM 2 KB = 2,048 bytes, the variables int 2 bytes on the Uno -> at most 1,024 ints ESP32 520 KB SRAM, for comparisonLimit: 16 MHz
A clock ticks 16 million times a second, and most instructions take one tick: up to 16 million simple steps a second. Plenty for a thermostat, but heavy jobs, like video, need a much faster chip.
clock 16 MHz = 16 million ticks per second most instructions: 1 tick so up to 16 MIPS (million instructions per second) ESP32 up to 240 MHz, for comparisonLimit: the battery
At 1 MHz and 1.8 V the chip draws about 0.2 mA awake and 0.1 µA asleep: 2,000 times less. Battery devices sleep between readings. Our delay() keeps the chip awake, so a later lesson replaces it.
awake 0.2 mA (1.8 V, 1 MHz) asleep 0.1 µA (power-down, 1.8 V) ratio 2,000 times less while asleep delay() waits awake: no energy saved
5 quick questions
Choose one answer per question. You can change your choices before checking them.
01Which of these is the best description of an embedded system?
An embedded system is hidden inside a device, such as a thermostat or a washing machine, and does that device's one job.
02What is firmware?
Firmware is the program on the chip. It sits in flash, which keeps it when the power is off, and starts again at every power on.
03The thermostat reads t = 18. What does digitalWrite(HEAT, t < 20) do?
18 < 20 is true, which counts as 1, and 1 is HIGH: pin 8 goes to 5 V and the relay switches the heater on.
04The ATmega328P has 2 KB of SRAM and an int takes 2 bytes on the Uno. At most how many int variables fit?
2 KB is 2,048 bytes, and 2,048 ÷ 2 = 1,024. In practice fewer fit, because the stack and library code share the same SRAM.
05Why do battery-powered embedded devices sleep between readings?
The commercial ATmega328P datasheet gives about 0.2 mA awake and 0.1 µA in power-down mode (both at 1 MHz and 1.8 V): 2,000 times less. Energy is the battery's hard limit, so sleeping most of the time pays off. delay() does not sleep: it waits awake.
Glossary
- Embedded system
- A computer built into a device to do one dedicated job, such as running a thermostat or a washing machine.
- Microcontroller (MCU)
- A whole small computer on one chip: a processor, flash and SRAM memory, and input/output pins.
- Firmware
- The program stored on a microcontroller. It starts at power on and runs until the power goes.
- Flash memory
- Memory that keeps its contents with the power off. It holds the firmware.
- SRAM
- Fast working memory for variables while the program runs. Its contents are lost at power off.
- Clock (MHz)
- A steady tick that paces the processor. 16 MHz is 16 million ticks a second.
- Sensor and actuator
- A sensor turns something physical, like temperature, into a voltage the chip can read; an actuator, like a heater or motor, changes the world when the chip tells it to.
- Real-time
- A system whose answers must arrive on time to be correct: a late answer counts as a wrong one.
Notes and sources
- The card shows only loop(). The whole sketch also defines HEAT = 8, sets the pin as an output in setup(), and defines readTemp(), which turns the ADC number into degrees with whole-number maths (so 141 becomes 18, not 18.8).
- digitalWrite takes HIGH or LOW. In the Arduino core HIGH is defined as 1 and LOW as 0, and a true comparison becomes 1, so t < 20 picks HIGH when it is cold.
- An MCU pin can only supply a small current, so a real heater is switched through a relay or a transistor. A later lesson on pin current limits shows how.
- The current figures are the headline numbers of the commercial ATmega328P datasheet (DS40002061B): active and power-down mode at 1 MHz, 1.8 V and 25 °C. At 5 V and 16 MHz the chip draws more, and an Uno board also powers its USB chip, regulator and LED.
- The chip also has 1 KB of EEPROM for settings that must survive power off. Not all 2 KB of SRAM is free for your variables: the stack and library code share it. On the Uno, 512 bytes (0.5 KB) of flash hold the bootloader, a small program that runs first at power on and then starts setup().
- J. W. Valvano, Embedded Systems: Shape the World, ch. 1 (UT Austin)
- E. A. Lee and S. A. Seshia, Introduction to Embedded Systems, 2nd ed. (MIT Press, 2017)
- UC Berkeley EECS 149/249A: Introduction to Embedded Systems (course page)
- Microchip ATmega328P datasheet (DS40002061B, commercial part), Features
- Arduino AVR core: boards.txt (Uno flash size and bootloader)
- Arduino UNO R3 product datasheet (A000066)
- Arduino language reference: analogRead() (source)
- Arduino language reference: digitalWrite() (source)
- Arduino language reference: delay() (source)
- Arduino language reference: int (source)
- Arduino AVR core: Arduino.h (HIGH and LOW)
- Analog Devices TMP35/TMP36/TMP37 datasheet
- Espressif ESP32 Series datasheet
Quiz Unlocks after the last step.