A microcontroller is a very small computer on a single chip: it has a processor, memory, inputs and outputs. You write a program for it, and it reads sensors, makes decisions and switches things on. It's found in remote controls, washing machines, microwaves, cars and most electronics projects.
What's inside?
- The processor (CPU): runs the program.
- Flash memory: the program is stored here and isn't erased when the power goes off.
- RAM: for variables while running.
- Peripherals: timers, an ADC, UART, I2C, SPI, and sometimes WiFi and Bluetooth.
A microcontroller, a processor or a Raspberry Pi?
| Microcontroller | Computer processor | Raspberry Pi | |
|---|---|---|---|
| Memory | Inside the chip | External | External (gigabytes) |
| Operating system | None, just your program | Windows or Linux | Linux |
| Starts in | Fractions of a second | Seconds to minutes | Seconds |
| Consumption | Milliamps or less | Many watts | 2–5 W |
| Timing | Precise and predictable | Not guaranteed | Not guaranteed |
So a microcontroller isn't a weak computer; it's a different tool: it does one thing precisely, and runs on a battery for months. A Raspberry Pi suits cases where you need a screen, a camera or large programs. And many projects use both: the Pi as the big brain, and the microcontroller for the sensors and motors.
How does the program run?
On the Arduino, the program has two parts:
void setup() {
pinMode(13, OUTPUT); // runs once at power-up
}
void loop() { // repeats until the power goes off
digitalWrite(13, HIGH);
delay(500);
digitalWrite(13, LOW);
delay(500);
}
- setup: the settings, once.
- loop: the real work, looping forever. There's no "exiting" the program as on a computer.
delaystops everything. When the project grows, use millis instead of delay to do several things at once, and interrupts for fast events.
If you haven't tried it yet, start with a first Arduino project.
Pin types
- Digital: either 0 or 1. Read a button or turn on an LED.
- Analogue input: the ADC converts the voltage to a number, such as reading a potentiometer or a temperature sensor.
- PWM: fast switching on and off in different proportions, to control the brightness of an LED or the speed of a motor.
- Communications: UART, I2C and SPI for talking to sensors, displays and modules. The differences are in the protocols article.
Memory in numbers
| Arduino Uno | ESP32 | |
|---|---|---|
| Flash (the program) | 32 KB | Usually 4 MB |
| RAM (variables) | Only 2 KB | About 320 KB |
| EEPROM | 1 KB | Emulated in flash |
The Uno's 2 KB runs out quickly: strings in Serial.print eat RAM. Use F("text") so the string is stored in flash instead of RAM. And when RAM runs out, the program hangs in strange ways with no error message.
A quick comparison
| Arduino Uno | ESP32 | Raspberry Pi Pico | |
|---|---|---|---|
| Voltage | 5 V | 3.3 V | 3.3 V |
| Speed | 16 MHz | Up to 240 MHz | 133 MHz |
| WiFi / Bluetooth | No | Yes, both | Only on the Pico W |
| Suited to | Starting out and learning | IoT and the smart home | Fast, cheaper projects |
Our advice: if you're just starting, the Uno is easier at first and its projects are widespread. And if you want the project to connect to the internet or a phone, go straight to the ESP32. Getting started with it is in first steps with the ESP32.
Things to know from the start
- Voltage: the ESP32 runs on 3.3 V. If you connect a 5 V signal to its pin it may be damaged. Use a voltage divider or a level shifter.
- Current: a pin can only supply a small current (milliamps). For a relay or motor use a transistor. The figures in detail are in Arduino pin limits.
- The crystal: the chip's speed and timing accuracy come from a crystal or oscillator.
- The battery: if the project runs on a battery, use sleep mode. The calculation is in the battery life article.
- Power: each way of powering it has limits. See powering the Arduino.
When something doesn't work
- Start with Serial: print values as you go. See the Serial Monitor.
- Test each part on its own: the sensor in a program by itself, the motor in a program by itself, then combine them.
- Ground: any external module must share ground with the microcontroller.
- The wrong pin: some pins have special functions at boot (especially on the ESP32), so check the pinout.
From the board to the product
A development board (such as an Arduino) has extra things: a regulator, a USB chip and LEDs. When the project is finished, you can design a PCB with only the chip and the parts you need, so it's smaller, cheaper and uses less power.
FAQ
Which language should I learn? Most projects use C/C++ in the Arduino IDE. The ESP32 and the Pico also support MicroPython, which is easier if you know Python, but slower and uses more memory.
Is the Arduino a "microcontroller"? Arduino is the name of the board and the software. The microcontroller itself is the chip on it: on the Uno it's called the ATmega328P.