Where they live
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.
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.
One job, 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.
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.
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.
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.
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.
What limits them
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.
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.
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.
What happens
;; step 1/10 · everywhere
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 device
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). 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.