The chip
A microcontroller is a whole small computer on one chip: a processor, memory for the program and its data, timers, and pins that reach the outside world. Boards like the Arduino Uno are built around one.
The CPU core runs the program one instruction at a time, in step with a clock. The ATmega328P chip on the Arduino Uno runs at 16 MHz: 16 million clock ticks every second.
Memory
Flash memory holds the program and keeps it when the power is off. The CPU fetches each instruction from flash before it runs it. The ATmega328P has 32 KB of flash: small, but plenty for many small jobs.
SRAM is the working memory. The program keeps its variables here while it runs. SRAM is fast, but it forgets everything when the power goes. The ATmega328P has just 2 KB; a laptop has millions of times more.
Running a program
Many microcontrollers run without an operating system. After power-up the chip runs one program, and it ends in a loop that never stops. Ours is MicroPython, a small Python for chips such as the RP2040.
led.toggle() makes the CPU write a 1 into bit 5 of the GPIO output register. GPIO means general-purpose input/output; a register is a tiny memory cell wired to hardware. Pin 5 goes high and the LED lights.
sleep_ms(500) waits half a second while a hardware timer counts clock ticks. Then the loop runs again: toggle flips bit 5 back to 0 and the LED goes dark. Half a second later it lights again: a blink.
Inputs and helpers
Pin 2 is an input. A pull-up resistor inside the chip holds it at 1. Pressing the button connects the pin to ground, so bit 2 of the input register reads 0. print(btn.value()) reads that bit and prints it.
More helpers sit beside the pins. The ADC (analog-to-digital converter) turns a voltage, here from a dial, into a number: 10 bits on the ATmega328P, so 0 to 1023. A serial port (UART) sends bytes to other chips, one bit at a time.
Power and real chips
Most of the time there is nothing to do, so the chip sleeps: it stops its clocks and draws almost no current. In power-down mode the ATmega328P needs about 0.1 µA. A button press can wake it.
Microcontrollers hide in keyboards, washing machines and cars. Popular ones include the AVR chip on the Arduino Uno, the RP2040 on the Raspberry Pi Pico (two Arm Cortex-M0+ cores at 133 MHz), and many other Arm Cortex-M chips.
In detail
;; step 1/11 · whole Inside one package (ATmega328P, the Arduino Uno's chip): CPU core runs the program flash 32 KB the program (kept without power) SRAM 2 KB variables while it runs EEPROM 1 KB small settings that survive power-off timers two 8-bit, one 16-bit 23 I/O pins, a 10-bit ADC, USART, SPI and I2C serial ports A laptop spreads these over many chips; a microcontroller has them all in one.
The figure is a generic microcontroller drawn as a teaching model: one chip with a CPU core, flash, SRAM, a timer, GPIO, an ADC and a UART, wired to an LED, a button and a dial. Real chips have more of each. Sizes, speeds and currents are the ATmega328P's (the Arduino Uno's chip) from the Microchip datasheet; the currents are measured at 1 MHz, 1.8 V and 25 °C, and grow with clock speed and supply voltage. The code card is MicroPython (machine.Pin and time.sleep_ms). It runs on larger chips such as the RP2040; on an Arduino Uno the same loop is usually written in C++.