Français

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:

  1. learn what a capacitor stores and how to read its value,
  2. learn the two marks that matter for safety: polarity and voltage rating,
  3. add a 470 µF capacitor to a servo supply and understand why it helps.
A capacitor is a water tower Top, a hill town drawn flat. Left, a pump feeds one narrow pipe. In the middle, a water tower on legs fills slowly from that pipe all night. Right, the town's houses. At 7 a.m. everybody showers at once. Two small gauges show the water pressure in town over the morning. Without the tower, the pressure drops deep at the rush. With the tower, it only dips a little: the tower lends its stored water, then fills up again. Bottom, the same picture as a circuit: the supply is the pump, its wires are the narrow pipe, the capacitor is the water tower, connected across the two supply lines, and the servo is the town with its sudden demand. FIG. 1 — THE THIRSTY TOWNa7 a.m.: everybody showers at oncePpumpnarrow pipewater towerfills slowlyall nighttown: showers, tapsMorning rush without towerWith towerdeep dropsmall dipbThe same picture as a circuit++Msupply= pumpsupply wires = narrow pipecapacitor= water towerservo= townWhere the picture stops: a capacitor this size covers a fraction of a second, not days.
Tap the diagram to open it full screen.

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.

Fill the tank (interactive)
Fill the tank (interactive) Interactive simulation with made-up numbers, not a measurement. Left, the supply, drawn as a pump, feeds a narrow pipe. In the middle, the capacitor drawn as a tank: its width is the capacitance, set by the slider from 10 to 1000 microfarads, and its water level is the voltage. Right, the servo. Press Servo moves: it draws a sudden burst of current, slowed down here. The graph below shows the voltage over 3 milliseconds. Without a capacitor the voltage dips deep, below the dashed brownout level, an example and not exact. With 470 microfarads it only dips a little. The other case stays drawn dashed for comparison. simulation, made-up numbersPsupplycapacitor = tankservowater level = voltage · width = capacitance

Simulation with made-up numbers, slowed down. Not a measurement.

lowest voltage: 5.0 Vvoltage now: 5.0 V

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.

Read the can: polarity and voltage rating Close-up of a 470 microfarad aluminium electrolytic capacitor, our own drawing. a, side view: a metal can with a light stripe of minus signs running down one side; the leg on the stripe side is the negative leg, to GND; the other leg is a little longer, the positive leg, to the plus of the supply. The can's print reads 470 µF and 16 V: 470 µF is the capacity, 16 V the maximum voltage. b, top view: the stripe shows on the rim, on the minus side; the cross on top is the vent. A warning badge: wrong way round, it can pop. For this course: 10 V or more, 16 V is comfortable. FIG. 2 — ELECTROLYTIC CAPACITOR, MARKSaSide view470 µF16 V105 °C−+stripe of − signsnegative:to GNDpositive, longer leg:to + supplycapacity470 µFmaximum voltage16 Vthis course: 10 V or more16 V is comfortablebTop viewthe cross is the ventstripe on the rim: − side!Wrong way round= can popStripe to GND, rating aboveyour supply, check twicebefore you switch on.
Tap the diagram to open it full screen.

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:

  1. Find the stripe and “-” marks on the capacitor. That leg goes to the ground line of the servo supply.
  2. The other leg goes to the + line of the same supply.
  3. 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.
  4. Check the stripe side and the rating once more. Then plug the supply back in and run the same sketch.
C1 wiring: 470 µF across the servo supply, next to the servo Breadboard view, the same build as lesson A2. The DevKitC sits off the breadboard, USB on the left, powered by its own USB cable: board and servo have separate supplies. GPIO 18 is on its bottom header, so female jumpers go straight on its pins. On the breadboard, the bottom rails are the servo supply; the top rails are not used. A pack of 4 NiMH AA cells, switched off while you wire: 1 red, pack plus to the bottom plus rail; 2 black, pack minus to the bottom minus rail. The servo's plug, brown minus, red plus, orange signal: 3 red, servo plus to the plus rail; 4 black, servo minus to the minus rail; 5 yellow, servo signal to GPIO 18. 6 black, a thick wire labelled common GND, from the minus rail to a GND pin of the DevKitC. Circled: the 470 microfarad capacitor straddles the plus and minus rails right next to the servo plug, in parallel, stripe side on the minus rail, rated 10 V or more. The button from the servo lesson straddles the gap in rows 10 and 12: 7 blue, GPIO 27 to row 10; 8 black, its opposite leg to the minus rail. Never power the servo from 3V3 or from any pin of the board. FIG. 3 — WIRING, SERVO ON ITS OWN SUPPLYaBreadboard viewENBOOT5VCLKCMDD0D3D1D215132GND0124141627172652518331932GND352134RXVNTXVP22EN233V3GND+−−+jihgfedcba1510121518top rails: not usedcommon GNDservoplug: brown −, red +, orange signal−++++ONOFF4 × NiMH AA, 4.8 Vswitched off while you wire470 µF,stripe on −10 V or morebottom rails:servo supplybutton3V3 → servo: neverGND2718GNDGNDUSB cable:powers theboard123456781red: pack + → bottom + rail2black: pack − → bottom − rail3red: servo red (+) → + rail4black: servo brown (−) → − rail5yellow: servo orange (signal) → GPIO 186black: − rail → GND pin: common GND7blue: GPIO 27 → button (row 10)8black: button, opposite leg → − railThe servo's + goes to its own pack only, never to a pin of the board. The + rail feeds only the servo and the capacitor.GPIO 18 is on the bottom header: the board sits off the breadboard, female jumpers go on its pins.
Tap the diagram to open it full screen.

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.

  1. 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].
  2. 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.
  3. 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 GND is joined to a GND pin 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.

  1. 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.

  2. 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].

  3. 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
  1. 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
  2. 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
  3. 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
  4. 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
  5. 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/

Pinch or double-tap to zoom, swipe to change diagram.Scroll with Ctrl or double-click to zoom. Arrow keys change diagram.