The short answer
An embedded program is software that runs inside a device that isn’t a general-purpose computer, and it exists to make that device do one specific job. The program in a microwave reads the keypad, runs the magnetron and turns the turntable. The program in a thermostat reads a temperature sensor and switches the heating on and off. Nobody installs or launches it. It’s stored in the device’s own memory, usually flash, and starts running as soon as power is applied.
Embedded programs are often called firmware, especially when they run directly on a microcontroller without an operating system. Writing them is called embedded programming.
What makes a program “embedded”
Embedded programs vary enormously, from a few hundred bytes in a toy to millions of lines in a car. Most of them share a few traits:
- A dedicated purpose. The device does one job or a small set of related jobs, and the program is written for exactly that.
- A specific piece of hardware. The code targets a particular microcontroller or processor on a particular circuit board. It can’t simply be copied to another device.
- Direct hardware control. The program reads sensors, drives motors, LEDs and displays, and talks to other chips over buses such as I2C, SPI and UART. Often it does this by writing straight to hardware registers.
- Tight resources. Many microcontrollers have kilobytes of memory, not gigabytes. The ATmega328P on an Arduino Uno, for example, has 32 KB of flash for the program and 2 KB of RAM.
- Timing requirements. Many embedded programs must react within a fixed time: firing an airbag, sampling audio, or stepping a motor at the right moment.
- Long, unattended operation. The program may run for years without a reboot, and nobody may be watching when something goes wrong.
Embedded program vs. a desktop or phone app
| Desktop or phone app | Embedded program | |
|---|---|---|
| Runs on | General-purpose computer with an OS | Microcontroller or embedded processor, often with no OS |
| Started by | The user or the OS | Power-on or reset |
| Ends | When the user closes it | Usually never; it loops forever |
| Memory | Gigabytes, managed by the OS | Kilobytes to megabytes, managed by the programmer |
| Talks to hardware | Through OS drivers and APIs | Often directly, through registers |
| Updated by | App store or installer | Reflashing, or an over-the-air update if the device supports it |
| A crash means | The app closes | The device can hang or misbehave until it’s reset |
How an embedded program runs
From power-on to main()
When a microcontroller powers up or resets, the CPU reads a fixed location in memory called the reset vector. That location holds the address of the first code to run. That first code is the startup code, often supplied by the chip vendor and written in assembly or C. It usually:
- Sets up the stack pointer (some cores, including Arm Cortex-M, do this in hardware from the vector table).
- Copies initial values of global variables from flash into RAM.
- Zeros the remaining global variables.
- Optionally configures clocks and memory.
- Calls
main().
From then on, the program is in charge. Nothing sits underneath it to load files, allocate memory or catch errors unless the program supplies those things itself.
The super loop
The simplest and most common structure is an infinite loop in main(), often called a super loop:
int main(void)
{
hardware_init();
for (;;) {
read_inputs();
update_logic();
write_outputs();
}
}
main() never returns, because there’s nothing to return to.
Interrupts
Polling everything in a loop is slow to react and wastes power, so microcontrollers provide interrupts. When a timer expires, a byte arrives on a serial port or a button is pressed, the hardware pauses the main loop and runs a short function called an interrupt service routine (ISR). When the ISR finishes, the loop picks up where it left off. Our guide to writing an interrupt service routine in C shows how this works in practice.
Programs that use an RTOS
Larger embedded programs often run on a small real-time operating system (RTOS) such as FreeRTOS or Zephyr. Instead of one big loop, the program is split into tasks that the RTOS schedules by priority. The program is still embedded: it’s linked together with the RTOS into a single image built for that one device.
The most capable devices, such as routers, smart TVs and infotainment units, often run embedded Linux or Android. Software there looks more like ordinary application code, but it’s still built and shipped for one product.
A minimal example
Here is a complete embedded program for an Arduino Uno’s ATmega328P, written in plain C. It blinks the on-board LED:
#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRB |= (1 << DDB5); /* make pin PB5 an output */
for (;;) {
PORTB ^= (1 << PORTB5); /* flip the LED */
_delay_ms(500);
}
}
There is no printf, no file and no window. The program writes to two hardware registers (DDRB and PORTB) and loops forever. The |= and ^= operators are standard bit manipulation idioms, explained in setting, clearing and toggling register bits.
Firmware, embedded software and embedded systems
These terms overlap, and people use them loosely:
- Embedded system: the whole product, meaning hardware plus software, built to do a dedicated job. A washing machine controller is an embedded system.
- Embedded software: the code running on that system, at any level from drivers to application logic.
- Firmware: embedded software stored in non-volatile memory and closely tied to the hardware. On small microcontrollers, the firmware is usually the entire program.
- Embedded program: an everyday term for any of the above software. Most people use it to mean the firmware.
For a deeper look at how firmware is structured and built, see our embedded firmware development overview.
Examples of embedded programs
- Home: microwave ovens, washing machines, thermostats, smart plugs, remote controls, electric toothbrushes
- Personal electronics: fitness trackers, wireless earbuds, digital cameras, keyboards and mice
- Automotive: engine control units, anti-lock braking, airbag controllers, tire pressure monitors, infotainment systems
- Industrial: programmable logic controllers, motor drives, sensors, robots, smart meters
- Medical: infusion pumps, patient monitors, hearing aids, blood glucose meters
- Networking: routers, switches, modems, Wi-Fi access points
A modern car can contain dozens of separate processors, each running its own embedded program.
What languages are embedded programs written in?
- C is still the most common language for microcontroller firmware. Compilers exist for almost every chip, and most vendor code is written in it. When people say “Embedded C”, they usually mean standard C plus vendor headers and some compiler extensions. Our Embedded C programming guide covers this in detail.
- C++ is widely used in larger firmware projects, and the Arduino environment is built on it.
- Assembly appears in startup code, low-level routines and very small chips. See assembly language for embedded systems.
- Rust is gaining ground, mainly because it makes many memory bugs impossible at compile time.
- MicroPython and CircuitPython run on more capable microcontrollers such as the Raspberry Pi Pico and ESP32. They’re popular for learning and prototyping.
- Go, through the TinyGo compiler, can target some microcontroller boards. We cover it in Go and functional programming for embedded systems.
The four types of embedded systems
Textbooks often sort embedded systems into four groups by how they work. The lines between the groups are blurry, and other classifications exist.
- Standalone: works on its own without a network or host computer, such as a microwave or a digital watch.
- Real-time: must respond within guaranteed time limits. Hard real-time systems (airbags, flight controls) can’t miss a deadline. In soft real-time systems (video streaming), an occasional late result is tolerable.
- Networked: connected to other devices or the internet, such as smart home devices, network cameras and industrial sensors.
- Mobile: portable and usually battery-powered, such as fitness trackers and handheld scanners.
Another common split is by scale: small-scale systems on 8- or 16-bit microcontrollers, medium-scale systems on 16- or 32-bit chips, often with an RTOS, and sophisticated systems on powerful processors, often running Linux.
How an embedded program gets onto a device
You don’t write embedded programs on the device itself. The usual workflow is:
- Write and compile on a PC. A cross-compiler produces machine code for the target chip instead of your PC’s processor. The guide to embedded IDEs, toolchains and simulators covers the software involved.
- Optionally simulate. Some tools can run firmware on a virtual microcontroller before hardware exists. See which simulation software fits which job.
- Flash it. A USB bootloader or a debug probe writes the program into the chip’s flash memory.
- Debug on the hardware. A debug probe lets you pause the chip, step through code and inspect memory. Our article on debugging with JTAG, SWD and GDB shows how.
Getting started
The easiest way to understand embedded programs is to write one. Inexpensive development boards come with a USB connection for both power and programming:
- Arduino Uno or Nano: the friendliest start, with a huge amount of beginner material.
- Raspberry Pi Pico: cheap and well documented, and it supports C/C++ and MicroPython.
- ESP32 development boards: built-in Wi-Fi and Bluetooth for connected projects.
- STM32 Nucleo boards: an industry-standard Arm Cortex-M family with an on-board debug probe.
Start by blinking an LED, then read a button, then add a timer interrupt. Those three steps cover the core of how nearly every embedded program works.