Decoupling capacitors
Every schematic has small capacitors scattered next to the chips and no explanation of what they do. They are there for the two milliseconds after something switches on — the ones your regulator sleeps through and your board reboots in.
Press the motor button with the capacitor out, then fit it and press again. The dashed line is where the ESP32 gives up and resets itself. The part being fitted is the bulk capacitor, not the 100 nF ceramic — see below for why a motor needs the big one.
What actually happens
A regulator is a feedback loop, and feedback takes time — tens of microseconds at best. A digital chip's demand changes in nanoseconds: a radio keys up, a motor stalls on startup, sixteen outputs switch at once. In the gap between those two speeds, the current has to come from somewhere, and if there is nowhere it comes out of the rail voltage.
Drop the rail under about 2.6 V and the ESP32's brown-out detector resets the chip. Your code did not crash. The chip was restarted underneath it, which is why the serial monitor shows a boot message and no stack trace.
The capacitor is a local battery
A capacitor stores a small amount of charge and can release it almost instantly. Put one right next to the chip and it supplies the first microseconds of any sudden demand, buying time for the regulator to notice and catch up.
Right next to the chip matters. Two centimetres of track is enough inductance to slow the delivery down. This is the one component whose position on the board is part of its value.
What to fit, and where
- 100 nF (0.1 µF) ceramic across the power pins of every IC. Small, fast, handles the sharp edges. This is the one that is on every schematic.
- 100 µF and up, electrolytic near where power enters the board, and beside anything with a motor or a relay in it. Slower and much larger, it handles the bulk sag — the figure above fits 470 µF, which is a normal size next to a motor.
- Both together is normal and not redundant: the ceramic covers microseconds, the electrolytic covers milliseconds.
Motors and servos deserve their own bulk capacitor next to them, and often their own supply — sharing a USB 5 V rail between an ESP32 and a servo under load is the single most common cause of "my board restarts randomly".
How to recognise it in the wild
If a board resets when a motor starts, a relay clicks, or Wi-Fi connects — and never when it is idle — this is your problem, not your code. Before rewriting anything, put a large capacitor across the supply at the noisy part and try again. Two components and a minute usually settles it.
Next: why "right next to the chip" is a number rather than a preference, and why a schematic carries three of these in parallel rather than one.
Edit this page — content/fundamentals/electricity/decoupling-capacitors.mdx
Discuss this article
Ask about this page. The answer stays here, on the page it belongs to, for whoever hits the same wall next.