[Microcontrollers](https://www.ampheo.com/c/microcontrollers) (MCUs) are compact, self-contained computers on a chip that are designed to sense, process, and control electronics in embedded systems. They are the "brains" behind everything from microwave ovens and watches to robots and IoT devices.

**How Microcontrollers Work — Step by Step**
**1. Basic Components of a Microcontroller**

**2. Workflow Inside an MCU**
**1. Power On**
When powered, the microcontroller starts executing code from a reset vector, typically at address 0x00000000.
**2. Load Program from Flash**
The CPU fetches and executes instructions stored in Flash memory.
**3. Execute Instructions**
* Instructions can include reading [sensors](https://www.ampheo.com/c/sensors), turning on LEDs, or sending data.
* The CPU handles math, logic, branching, and memory operations.
**4. Interface with Peripherals**
* Built-in UART/SPI/I2C ports allow communication.
* Timers help manage delays or generate signals like PWM.
* ADC modules convert analog sensor signals to digital.
* Interrupts allow real-time reactions to events (e.g., button press).
**5. Loop Continuously**
Most embedded programs run inside an infinite loop:
```
c
while(1) {
read_sensor();
process_data();
control_output();
}
```
**3. Typical Application Example: Temperature-Controlled Fan**

**4. Programming a Microcontroller**
1. Write code in C/C++ or assembly
2. Compile into machine code
3. Upload to MCU via programmer/debugger (e.g., ST-Link, USB)
4. MCU executes this firmware repeatedly on power-up
**5. Low Power and Sleep Modes**
* [Microcontrollers](https://www.ampheoelec.de/c/microcontrollers) often support sleep modes to conserve energy.
* They can wake up on timers or interrupts—ideal for battery-powered systems.
**Summary**
A microcontroller reads inputs (like sensors), processes that data using its CPU, and controls outputs (like motors, [displays](https://www.onzuu.com/category/led-displays-accessories), LEDs)—all while running a small program stored in memory.