Component guide · Intermediate · 3 min read
Crystals and Oscillators
How Microcontrollers Keep Time
By Geekobot Learning Team · Updated 24 Oct 2026
On this page
A quartz crystal vibrates at a precise frequency and, with the microcontroller's built-in oscillator circuit and two small load capacitors, sets its clock. A 16 MHz crystal with two 22 pF capacitors runs an ATmega328P, and a 32.768 kHz watch crystal keeps real-time clocks accurate. Ceramic resonators are cheaper but less accurate; oscillator modules contain the whole circuit and output a ready clock signal.
Key specs at a glance
- Common values
- 8, 12, 16, 20, 25 MHz; 32.768 kHz for clocks
- Accuracy
- Crystal ±10 to 50 ppm; ceramic resonator about ±0.5%
- Load capacitance
- Specified per crystal, often 12 to 20 pF
- Load capacitors
- About 2 x (CL - stray), typically 18 to 22 pF for 16 MHz
- Packages
- HC-49 (through hole), SMD 3225/2520, cylinder (32.768 kHz)
- Oscillator module
- 4 pins: VCC, GND, OUT, enable
Crystal, resonator or oscillator?
| Part | Pins | Accuracy | Needs | Use |
|---|---|---|---|---|
| Quartz crystal | 2 | ±10 to 50 ppm | Two load capacitors + chip's oscillator | Most microcontroller clocks, USB |
| Ceramic resonator | 3 (built-in caps) or 2 | About ±0.5% | Nothing else (3-pin types) | Cheap Arduino clones, non-critical timing |
| Oscillator module (XO) | 4 | ±25 to 100 ppm | Power | FPGAs, clock for several chips |
| TCXO | 4 | ±0.5 to 2 ppm | Power | GPS, RF, precision timekeeping (DS3231 has one built in) |
- Quartz crystal
- Pins:
- 2
- Accuracy:
- ±10 to 50 ppm
- Needs:
- Two load capacitors + chip's oscillator
- Use:
- Most microcontroller clocks, USB
- Ceramic resonator
- Pins:
- 3 (built-in caps) or 2
- Accuracy:
- About ±0.5%
- Needs:
- Nothing else (3-pin types)
- Use:
- Cheap Arduino clones, non-critical timing
- Oscillator module (XO)
- Pins:
- 4
- Accuracy:
- ±25 to 100 ppm
- Needs:
- Power
- Use:
- FPGAs, clock for several chips
- TCXO
- Pins:
- 4
- Accuracy:
- ±0.5 to 2 ppm
- Needs:
- Power
- Use:
- GPS, RF, precision timekeeping (DS3231 has one built in)
Choosing load capacitors
The crystal datasheet gives its load capacitance (CL). The two capacitors in series, plus stray board capacitance (about 2 to 5 pF), must equal it: C1 = C2 ≈ 2 x (CL - Cstray). For a 16 MHz crystal with CL = 18 pF and 4 pF stray, that is 2 x 14 = 28 pF; designs often use 22 pF, which runs slightly fast but well within tolerance for most uses. Wrong values shift frequency slightly or, if far off, stop the oscillator starting.
Wiring and layout tips
- Place the crystal and capacitors as close to the chip's XTAL pins as possible, with short traces.
- Connect the capacitors' ground ends to a solid ground right next to the chip.
- Keep fast digital signals and switching regulators away from the crystal.
- On a breadboard, a bare ATmega328P with a 16 MHz crystal and 22 pF capacitors usually works, but the extra capacitance can make high-frequency crystals unreliable; keep leads short.
- 32.768 kHz crystals are delicate and low power: never probe them with a normal oscilloscope probe, which stops or shifts the oscillation.
Why accuracy matters
Serial communication tolerates about ±2% clock error, so a ceramic resonator is fine for UART. USB needs ±0.25% or better, so USB chips need crystals. Real-time clocks need parts-per-million accuracy: 20 ppm is about 52 seconds a month, which is why the DS3231, with a temperature-compensated oscillator, keeps much better time than a DS1307 with a plain crystal. Wi-Fi and Bluetooth chips also depend on accurate crystals.
Try it: Capacitor code calculator
Change the values and the diagram and results update as you type.
Common mistakes to avoid
- Leaving out the load capacitors.
- Using capacitors far from the crystal's specified load.
- Long breadboard leads on a 16 MHz or faster crystal.
- Probing a 32.768 kHz crystal and stopping it.
- Expecting a resonator-clocked board to keep accurate time.
Frequently asked questions
Why does Arduino use a 16 MHz crystal?
The ATmega328P is rated up to 20 MHz at 5 V, and 16 MHz gives exact timing for common baud rates and Arduino's timing functions. Many clones use a cheaper 16 MHz ceramic resonator instead.
What capacitors go with a 16 MHz crystal?
Usually two 22 pF ceramic capacitors from each crystal pin to ground. Check the crystal's load capacitance for the exact value.
What is a 32.768 kHz crystal used for?
Timekeeping. 32,768 is 2 to the 15th power, so a simple counter divides it to exactly one pulse per second.
What is the difference between a crystal and an oscillator?
A crystal is a passive resonator that needs an oscillator circuit (usually inside the microcontroller). An oscillator module contains the crystal and circuit and outputs a clock signal.
Can I run an ATmega328P without a crystal?
Yes, on its internal 8 MHz oscillator, which is less accurate (about ±1 to 10%) but fine for many tasks. Set the fuses and use a matching board definition.
Parts for this guide
Calculators
Terms in this guide
Projects that use it
Put this into practice: 1 step-by-step build in our project library uses parts from this guide.
Keep learning
Sources
- Microchip ATmega328P datasheet, clock sources chapter
- Crystal manufacturer application notes on load capacitance (Abracon, ECS)
Written by the Geekobot team from manufacturer datasheets. Always check the datasheet for the exact part and variant you buy.



