Lessons · Lesson C1 · Components · 25 min
Capacitors
Learn what a capacitor stores, how to read its value and its marks, and why a 470 µF one across a servo's power wires helps when the supply dips as the servo moves. About 25 minutes, with a tank you can fill.
The thirsty town
Picture a town that gets its water through one narrow pipe from the pump. Most of the day, a trickle is enough. Then, at 7 in the morning, everybody takes a shower at once. The pipe cannot deliver that much, so the pressure drops and the taps sputter.
Now add a water tower on a hill. All night it fills slowly from the same narrow pipe. At 7 a.m. it lends its stored water to the town, and the pressure stays steady. When the rush is over, it fills up again.
A small robot has the same problem. A servo is quiet most of the time, then it moves and suddenly asks for a burst of current. Your supply might not keep up for a split second, and its voltage sags. The servo jerks, and if your board shares that supply, the ESP32 notices and can restart your program in the middle of a move.
A capacitor is the water tower.
In this lesson you will:
- learn what a capacitor stores and how to read its value,
- learn the two marks that matter for safety: polarity and voltage rating,
- add a 470 µF capacitor to a servo supply and understand why it helps.
What it stores, and how much
A capacitor is two conductors separated by an insulator [5]. When you connect it to a supply, it collects electric charge, a bit like a tank filling up. If you then give the charge another path, it flows out again: the capacitor discharges [1].
In the picture:
- the water level in the tank is the voltage across the capacitor,
- the width of the tank is its capacitance: a wider tank takes more water to rise by the same amount,
- the narrow pipe is the supply that refills it.
Capacitance is measured in farads (F). One farad is a lot, so you will usually see much smaller units [1]:
| Unit | Symbol | In farads |
|---|---|---|
| microfarad | µF | 0.000001 F |
| nanofarad | nF | 0.000000001 F |
| picofarad | pF | 0.000000000001 F |
So 470 µF is a small fraction of a farad, yet it is a “big” capacitor in the electronics of a board like yours. A tiny 100 nF capacitor is the same as 0.1 µF, because 1000 nF make 1 µF [1].
Where the picture stops. A water tower can hold water for days and lets it out slowly. A capacitor of this size holds its charge for a very short burst, a fraction of a second at best. It is a buffer for sudden demands, not a battery.
Simulation with made-up numbers, slowed down. Not a measurement.
Press Servo moves.
No single value fits every setup. 470 µF is a comfortable choice for one or two small servos.
This is the starting state: the controls need JavaScript.
Two marks that matter: polarity and rating
Look at the body of the 470 µF capacitor in your kit. It is probably a little metal can, an aluminium electrolytic. Electrolytic capacitors pack a lot of capacitance into a relatively small volume [1], so values like 470 µF come in this form. They come with two marks you must read.
1. Polarity. Most electrolytic capacitors are polarized: one leg is positive and the other negative. The negative leg is usually marked with a “-” sign and a coloured stripe on the case, and the positive leg may be a little longer [1]. The positive leg must always be at a higher voltage than the negative leg [1].
2. Voltage rating. Each capacitor has a maximum voltage written on it, such as “16V”. Exceeding it usually destroys the capacitor [1]. A “25V” rating, for example, means the capacitor can be used with any DC voltage up to 25 V [4]. SparkFun advises choosing a capacitor with a much higher rating than the highest voltage spike in your circuit [1]. The servo pack from the servo lesson is 4 NiMH cells, about 4.8 V; with alkaline cells a 4xAA pack gives about 6 V [3], and brand-new alkaline cells can read a little more. Rule for this course: 10 V minimum, 16 V gives a comfortable margin. A higher rating, such as 25 V, is fine too: the can is just a little bigger.
Safety. At these low voltages a capacitor is not dangerous when it is connected correctly. But connected backwards, an electrolytic capacitor can fail loudly: SparkFun describes it making a pop and bursting open, and it then behaves like a short circuit [1]. Over-voltage destroys it too [1]. So: stripe to
GND, rating clearly above your supply, check twice before you switch on, and keep your face away from it the first time. If a capacitor ever gets hot, bulges or smells, unplug the supply, let it cool, then take it out.
Why the board restarts
The ESP32 has a brownout detector, switched on by default. If the supply voltage drops below a safe level, it can reset the chip. When it does, it prints “Brownout detector was triggered” and the chip restarts [2]. It is a protection: the chip restarts instead of running on a supply that is too low.
For your robot it shows up as a mystery. The servo starts to move, the board restarts, the program begins again from setup(), the servo moves, and so on. Adafruit describes the same trouble with servos: electrical noise and brownouts from excess current can make a board act erratically, reset or overheat. They also advise against powering servos from the board’s own 5 V pin [3]. That is why the servo lesson gave the servo its own supply. With its own supply, the servo’s dips stay on the servo’s side, so your board will rarely restart. The dip then shows on the servo itself: it may jerk, slow down or stop for a moment.
A capacitor across the servo’s power wires adds a small reserve right where the sudden demand happens. Adafruit suggests a capacitor when the supply dips as the servos move, and offers a starting point of 100 µF per servo, which gives 470 µF or more for five servos. They also say there is no single magic value, because it depends on the servo, the load and the supply [3]. For one or two small servos, 470 µF is a comfortable choice.
A word on its small cousin. On many boards you will see tiny 100 nF capacitors next to the chips: these decoupling capacitors smooth out fast electrical noise on a supply line, and some can also give a brief boost when the voltage dips [1]. The big 470 µF one on the servo supply is the slow, strong version of the same idea.
Try it: the servo with a reserve
You need: the servo and the separate supply from the servo lesson, your servo sketch from that lesson, and one 470 µF electrolytic capacitor rated 10 V or more (16 V is ideal).
First, without the capacitor. Run your servo sketch with the Serial Monitor open at 115200 baud. Watch the servo: does it jerk, slow down or stop for a moment when a move starts? Also watch for the line “Brownout detector was triggered” and for the program restarting. With the servo on its own supply, a restart is unlikely, and your setup may not dip at all, especially with fresh batteries. That is a fine result: no dip, no problem. Do not power the servo from the board just to make a dip happen.
Then, with the capacitor. Unplug the supply first. Then:
- Find the stripe and “-” marks on the capacitor. That leg goes to the ground line of the servo supply.
- The other leg goes to the + line of the same supply.
- Place it as close to the servo’s power wires as the breadboard allows, in parallel: it shares the same two lines, it is not in the middle of one of them.
- Check the stripe side and the rating once more. Then plug the supply back in and run the same sketch.
What to expect: if the servo used to jerk, or the board used to restart during moves, it should now behave better. If nothing went wrong before, you will not see a difference, and that is normal. The capacitor only helps when there is a dip to cover.
Try your own changes
Change one thing, then observe.
- A smaller reserve. Unplug the supply, then swap in a 100 µF capacitor, if you have one (stripe to
GND, rated 10 V or more). Does it still help? Remember Adafruit’s remark: the right value depends on the servo and the supply [3]. - Move it away. With the supply unplugged, put the capacitor at the far end of the breadboard, away from the servo. Is the result the same? Write down what you see on your own setup.
- Read your kit. Look at every capacitor in your kit and write down its value, its voltage rating, and which ones are polarized. Which legs go to
GND?
When it does not work
- The board still restarts. Check that the servo has its own supply and that the supply’s
GNDis joined to aGNDpin of the ESP32. Fresh batteries help. A bigger servo or several servos may need a bigger capacitor [3]. - Nothing changed after adding the capacitor. Your supply may not have been dipping. If the servo moved smoothly and the Serial Monitor shows no “Brownout detector was triggered” message, there was nothing to fix.
- The capacitor gets warm, bulges or smells. Switch the power off at once and let it cool before you touch it. Check the stripe side, and check that its rating is above your supply voltage [1].
- The servo does not move at all. The capacitor does not carry the signal. Check the signal wire and the servo power, as in the servo lesson.
- The capacitor is a tiny disc, not a can. Then it is probably a ceramic one, and ceramic capacitors are hard to find much above 10 µF [1], far from 470 µF. Check what is printed on it.
Check yourself
Three short questions. Nothing is saved, take your time.
What does a capacitor do in a circuit?
- It stores a little electric charge and can give it back quickly
- It makes more voltage than the supply provides
- It limits the current, like a resistor
Show the answer
It stores a little electric charge and can give it back quickly. A capacitor stores charge, and its capacitance, measured in farads, tells you how much charge it stores for each volt across it [1][5]. That is why it can cover a short burst of demand. It does not create energy and it is not a resistor.
You have an electrolytic capacitor. What must you check before switching on?
- Nothing, a capacitor has no front or back
- The stripe side goes to GND, and the voltage rating is clearly higher than your supply
- That it is the same colour as your wires
Show the answer
The stripe side goes to GND, and the voltage rating is clearly higher than your supply. Electrolytic capacitors are usually polarized: the marked negative leg must be at the lower voltage [1]. Each capacitor also has a maximum voltage, and exceeding it usually destroys the part [1]. SparkFun warns that an electrolytic capacitor connected backwards can fail with a pop and burst open [1].
Why put a 470 µF capacitor across the servo's power wires?
- To make the servo turn faster
- To hold a small reserve that covers the servo's sudden demand, so the supply sags less when the servo moves
- To replace the common GND wire
Show the answer
To hold a small reserve that covers the servo's sudden demand, so the supply sags less when the servo moves. When a servo moves, the supply can dip. If the board shares that supply, the ESP32's brownout detector can reset the chip when its supply voltage goes below a safe level [2]. Adafruit also suggests a capacitor for servo supplies that dip when the servos move [3]. The capacitor does not replace the common GND wire.
In short
- A capacitor stores electric charge. Its capacitance is measured in farads, and in practice in µF, nF and pF [1].
- Think of a water tower: it fills slowly and gives its water back in a quick burst. It is not a battery.
- Electrolytic capacitors are polarized (stripe side to
GND) and have a maximum voltage that you must not exceed [1]. Wrong way round, they can fail with a pop [1]. - The ESP32 has a brownout detector: if its supply voltage goes below a safe level, it can reset the chip [2].
- A 470 µF capacitor across a servo’s power wires is a common remedy when the supply dips as the servo moves. No single value fits every setup [3].
- Tiny 100 nF capacitors next to chips, called decoupling capacitors, smooth fast noise [1].
Next steps: the transistor lesson (C2), where a small signal switches a big current.
Sources
Show the 5 sources
- SparkFun, “Capacitors” (capacitance in farads, usually pF to µF; maximum voltage rating, exceeding it usually destroys the capacitor, de-rate well above the highest spike; electrolytics are polarized, cathode marked with “-” and a stripe, reverse voltage makes them fail with a pop and burst open; ceramic caps rarely exceed about 10 µF; decoupling capacitors suppress high-frequency noise and can briefly supply power) — https://learn.sparkfun.com/tutorials/capacitors
- Espressif, ESP-IDF Programming Guide, “Fatal Errors”, section “Brownout” (the built-in brownout detector is enabled by default and can trigger a reset if the supply voltage goes below a safe level; message “Brownout detector was triggered”) — https://docs.espressif.com/projects/esp-idf/en/v5.5/esp32/api-guides/fatal-errors.html
- Adafruit, “Adafruit 16-Channel PWM/Servo Driver”, “Hooking it up” (do not power servos from the board’s 5 V pin: noise and brownouts can make it erratic, reset or overheat; a 4xAA holder gives 6 V with alkaline cells and 4.8 V with NiMH; capacitor when the supply dips as servos move, n x 100 µF, for example 470 µF or more for 5 servos; no single magic value) — https://learn.adafruit.com/16-channel-pwm-servo-driver/hooking-it-up
- Adafruit, “47uF 25V Electrolytic Capacitors” product page (a 25 V rating means the capacitor can be used with any DC voltage up to 25 V) — https://www.adafruit.com/product/2194
- All About Circuits, “Electric Fields and Capacitance”, Lessons in Electric Circuits, Volume 1 (a capacitor is two conductors separated by an insulator; capacitance unit is the farad, and large capacitances are often quoted in microfarads) — https://www.allaboutcircuits.com/textbook/direct-current/chpt-13/electric-fields-capacitance/