What is a microcontroller?
A tiny computer on one chip, built to sense and control things.
A tiny computer on one chip
A microcontroller packs a processor, memory and input/output connections into a single chip. It is built to do one job, such as reading a sensor and deciding what to switch on, rather than to run many different programs.
How it differs from a computer
- Purpose: a computer is general purpose. A microcontroller runs one program built for one task.
- Operating system: a laptop runs an operating system. A microcontroller usually just runs your program, which starts as soon as power is applied.
- Size and power: microcontrollers are small, inexpensive and can run on very little power.
- Memory: they have far less memory than a laptop or phone.
- Connection to the world: they have pins that connect directly to electronic parts.
Inputs and outputs
Most of the pins on a board can be used as inputs or outputs. Your program reads inputs and decides what to do with outputs.
| Inputs (sensing) | Outputs (acting) |
|---|---|
| A push button | An LED |
| A temperature sensor | A buzzer |
| A light sensor | A small motor, through a suitable driver |
| A potentiometer (a turning knob) | A display |
Digital and analog
A digital pin is either on or off (high or low). An analog input can read a range of values, such as how far a knob is turned.