Microcontrollers
A tiny computer on a chip that you can program to do almost anything.
The question
What’s inside a microwave, a thermostat or a weather station that lets it follow instructions?
What you’ll discover: what a microcontroller is, how its pins work as inputs and outputs, and how to get started with a Raspberry Pi Pico.
In simple terms
BeginnerA computer you can hold on your fingertip
A microcontroller is a small, complete computer on a single chip: a processor, memory, and pins that can switch things on and off or sense the world. Unlike a laptop, it runs just one program, over and over, and it’s built into the thing it controls.
Microcontrollers are everywhere: microwaves, washing machines, car dashboards, thermostats, toys, and weather station consoles.
Each pin can be set as an output (to switch an LED, buzzer or transistor) or an input (to read a button, switch or sensor). Some pins can also measure voltages, which lets a microcontroller read sensors like the thermistor and LDR from Lesson 12.
Meet the Raspberry Pi Pico
Electronics School uses the Raspberry Pi Pico for its microcontroller projects: it’s inexpensive, widely available in Canada, and programmable in MicroPython, a beginner-friendly version of the Python language. (Arduino boards are another popular choice, and the ideas carry over.)
- Its pins work at 3.3 V.
- The edge pins are named GP0 to GP22 and GP26 to GP28 on Raspberry Pi’s pinout diagram (printed on the underside of the board); that’s the number you use in code. Several pins are GND (ground, −).
- It’s powered and programmed through a USB cable from a computer.
Go deeper
IntermediateDriving things from a pin
A Pico output pin can safely supply only a few milliamps, and all the pins together should stay under about 50 mA. An LED with a 220 Ω resistor draws about (3.3 − 2.0) ÷ 220 ≈ 6 mA, which is fine. Anything bigger, like a motor or a relay coil, needs a transistor switch (Lesson 10) between the pin and the load, plus a flyback diode for coils.
Inputs need a defined state. A button connected between a pin and GND needs a pull-up resistor so the pin reads 1 when the button isn’t pressed. The Pico has built-in pull-ups you can switch on in code, so the button reads 1 when released and 0 when pressed.
AdvancedAnalog inputs and PWM
The Pico has an analog-to-digital converter (ADC) on three pins (GP26 to GP28), which turns a voltage between 0 and 3.3 V into a number. Feed it a thermistor voltage divider and you have a digital thermometer.
It can’t output a true in-between voltage, but it can fake one with PWM (pulse-width modulation): switching a pin on and off thousands of times a second and varying the fraction of time it’s on. An LED driven at 25% on looks dimmer. PWM also controls motor speed and, through a passive buzzer, plays notes.
Quick check
What makes a microcontroller different from a laptop?
It’s a complete small computer on one chip, built into a device, running one program over and over.
What voltage do the Raspberry Pi Pico’s pins use?
3.3 V.
Why does a button input need a pull-up resistor?
So the pin reads a definite 1 when the button isn’t pressed, instead of floating unpredictably.
Words to know
- Microcontroller
- A small computer on a single chip that controls a device.
- GPIO
- General-purpose input/output: a pin you can program as an input or output.
- Pull-up resistor
- A resistor that holds an input at 1 until something pulls it to 0.
- PWM
- Pulse-width modulation: fast on-off switching that acts like an in-between level.
Learn more
- Raspberry Pi: Pico documentation: official getting-started guides
- Next: Introduction to programming
Electronics School is part of the Discovery Zone. Every activity here runs on small batteries or a USB cable: never wall outlets. The one plug-in tool is the optional soldering iron, set up by an adult.