Hello friends, I hope you all are doing great. Today, I am going to share the Supercapacitor ESR Tester with Raspberry Pi 5 in Proteus Simulation, the sixty-sixth project of our IoT Projects series. If you have searched for a supercapacitor tester, an ESR meter project, or a Proteus simulation of capacitance measurement with a Raspberry Pi, here is a complete one. A Raspberry Pi 5 charges a supercapacitor from 5 V through a resistor, holds it, discharges it through another resistor, and reads the voltage all the way with a 16-bit ADC. From that one curve it works out the two numbers that matter for any supercap: its capacitance and its equivalent series resistance, the ESR. Then it tells you how much energy the part holds, how much power it can deliver, and which standard value it really is.
Supercapacitors are everywhere now: they keep a clock alive through a power cut, buffer the pulses of a GSM modem, store the trickle from a solar cell or a vibration harvester, and catch the braking energy of buses and trams. Their weakness is the ESR: a supercap can hold a lot of charge but often cannot give it back quickly, and an old one loses capacitance and gains resistance. In this tutorial, we will go through the circuit, see what happens at the terminals when a capacitor with a series resistance is charged, turn the exponential curve into a straight line, find both numbers from it, check them a second way on the discharge, and then test a second part. At the end, you can download the project with the program and every library file.
NOTICE: Our team has put a lot of effort into this project: the circuit, the code and every part in the simulation are our own work, and you get them all free. Your feedback is the fuel that keeps us going, so please tell us what you think in the comments below. And if our free projects help you, you can buy us a coffee. So, let's get started with the supercapacitor ESR tester with Raspberry Pi 5 in Proteus simulation:
What Does This Supercapacitor Tester Do?
- Charges the supercap: relay channel 1 joins it to 5 V through a 47 ohm resistor until the terminals reach 90 % of the supply.
- Holds it, then discharges it: after 2 seconds, relay channel 2 joins it to ground through another 47 ohm resistor for one and a half time constants.
- Reads the whole curve: an ADS1115 16-bit ADC reads the terminal voltage through a divider twenty times a second.
- Finds the capacitance and the ESR from the charge: a straight-line fit of the logarithm gives the time constant and the voltage step at the very start.
- Checks both on the discharge: the step down when the current starts gives the ESR again, and the fall gives the time constant again.
- Reports what the part can do: the energy it holds at 5 V, the most power it can deliver, and the nearest E6 value.
- Shows it all: an OLED with the results, and a dashboard with the last two tests and the curve drawn by the Pi.
It is a great project for learning how capacitors really behave: an RC time constant you can measure, a series resistance that hides inside every capacitor, and a fit that turns a curve into numbers, all with a Raspberry Pi, a relay module and an ADC. In the simulation, the supercapacitor's pop-up shows the charge, the current, the energy and its own ESR, so you can check each of the Pi's numbers against the part itself.
Components Used in the Proteus Simulation
All the parts come from our Proteus libraries, each with its own tutorial. The project zip at the end includes every LIB and DLL file and the TEPPi runtime that runs Python in Proteus.
| Part | Proteus device | Library post | Connection |
|---|---|---|---|
| Raspberry Pi 5 | RASPBERRY PI 5 | Raspberry Pi 5 Library for Proteus | PI1, supercap_tester.py, Ethernet 192.168.1.51 |
| Supercapacitor 5.5 V 0.1 F | CAPSUPERTEP | Supercapacitor Library for Proteus | C1: + to VC, - to GND |
| 2-channel relay module | RELAY2ADVTEP | Relay Module Library for Proteus | RLY1: IN1 GPIO17, IN2 GPIO27 |
| ADS1115 16-bit ADC | ADS1115ADVTEP | ADS1115 ADC Library for Proteus | U1, I2C at 0x48, A0 the divider |
| SSD1306 OLED 128x64 | OLED12864WHITEADVTEP | OLED SSD1306 Library for Proteus | OLED1, I2C at 0x3C |
| Resistors | RESISTOR4BANDTEP | Resistor Library | R1 10k, R2 20k (the divider), R3 / R4 47 ohm |
| Laptop WiFi Monitor | LAPTOP WIFI MONITOR | Laptop WiFi Monitor | PC1 |
| Mobile WiFi Monitor | MOBILE WIFI MONITOR | Mobile WiFi Monitor | MOB1 |
Proteus Simulation of the Supercapacitor Tester: the Circuit
| Part | Pins | Raspberry Pi 5 / net |
|---|---|---|
| RLY1 relay | IN1 / IN2 | GPIO17 (pin 11) / GPIO27 (pin 13), active LOW |
| RLY1 relay | VCC / JD-VCC / GND | +5V / +5V / GND |
| RLY1 channel 1 | COM1 / NO1 | +5V / R3 47 ohm to VC |
| RLY1 channel 2 | COM2 / NO2 | R4 47 ohm from VC / GND |
| C1 supercap | + / - | VC / GND |
| R1 / R2 divider | VC - 10k - A0 - 20k - GND | |
| U1 ADS1115, OLED1 | SDA / SCL / VDD | GPIO2 (pin 3) / GPIO3 (pin 5) / +3.3V |
The relay module does the switching, because the currents are far too big for a GPIO pin: the first charging current is 5 V / 77 ohm = 65 mA. Each channel's contact closes a path: channel 1 from the 5 V supply through R3 to the supercap, channel 2 from the supercap through R4 to ground. The program never closes both, which would short the supply through the two resistors. The relay module's VCC and JD-VCC are real supply pins in its model, so they sit on the +5V net; an early test with net labels left the coils at 0 V and the relays never clicked. The ADS1115 runs on 3.3 V, so the supercap's up to 5 V goes through a divider of 10k and 20k, which passes two thirds: 5 V becomes 3.33 V. The divider's 30k takes only 0.17 mA, nothing next to the test currents.
How the Supercapacitor Tester Works
What a Supercapacitor Is
A normal capacitor stores charge on two plates separated by a thin insulator. A supercapacitor, an electric double-layer capacitor, stores it in the layer of ions that forms where porous carbon electrodes meet an electrolyte: the "plates" are a few molecules apart and the carbon has a huge surface, so the capacitance is enormous, here 0.1 F in a coin 11.5 mm across, a hundred thousand times a big electrolytic. The price is a low voltage, 5.5 V for this stacked part, and a large internal resistance, the ESR, because the charge has to travel through the electrolyte and the carbon. This part's ESR is 30 ohm. That is why a supercap is perfect to hold a clock's memory for days but poor at starting a motor.
Charging Through a Resistor: What the Terminals Show
Think of the supercap as an ideal capacitor C in series with its ESR. Charged from a supply V through a resistor R, the current is (V - Vc) / (R + ESR), where Vc is the voltage on the ideal capacitor inside, and it falls exponentially with the time constant tau = (R + ESR) C. The ADC cannot see Vc; it sees the terminals, which sit above Vc by the current times the ESR. The moment the relay closes, Vc has not moved yet, so the terminals jump by (V - Vc0) x ESR / (R + ESR). Worked example for an empty supercap: 5 x 30 / (47 + 30) = 1.95 V straight away, and tau = 77 ohm x 0.1 F = 7.7 s. After that the terminals follow V - (V - Vc0) x R / (R + ESR) x exp(-t / tau): they climb towards 5 V, quickly at first and then more slowly.
A Straight Line from a Curve
An exponential is hard to fit, but its logarithm is a straight line: ln(5 - V) = ln((5 - Vc0) x R / (R + ESR)) - t / tau. So the Pi takes ln(5 - V) for every reading between 15 % and 85 % of the way up and fits a straight line by least squares. The slope is -1 / tau. The intercept, the value at t = 0, gives 5 - V at the moment the relay closed, which is the size of the jump; from it, ESR = R x ((5 - Vc0) / (5 - Vt0) - 1). Finally C = tau / (R + ESR). One charge, one fit, both numbers, and the fit uses dozens of readings, so the ADC's noise averages out.
The Discharge: a Second Opinion
After 2 s of hold, with the relays open, the terminals show the plates' voltage, because no current flows through the ESR. Then channel 2 closes. The current jumps to Vc / (R + ESR) and the terminals fall at once to Vc x R / (R + ESR): the drop is the current times the ESR. The Pi reads the voltage just before and 10 ms after the contact closes, and since the current is the new terminal voltage divided by R, ESR = R x (V before - V after) / V after. The fall that follows is a plain exponential, ln(V) against time is a straight line again, and its slope gives tau a second time. The two halves of the test use different resistors and different directions of current, so when they agree, the result is trustworthy.
What the Numbers Mean
The energy a capacitor holds is C V squared / 2: 0.1 F at 5 V is 1.25 J, about what a small LED uses in a minute. The ESR sets how much of that you can get quickly: the most power any load can take from a source with an internal resistance is V squared / (4 ESR), into a load equal to the ESR. Worked example: 5 V and 30 ohm give 25 / 120 = 0.21 W, and then half of the energy is lost in the ESR itself. Finally, the Pi compares the capacitance with the E6 series of standard values (0.1, 0.15, 0.22, 0.33, 0.47, 0.68 F...) and names the nearest one, and it calls the part GOOD when it is a 0.1 F within 20 % and its ESR is no more than 20 % above the 30 ohm rating.
The Python Code Explained
The program is supercap_tester.py. It uses lgpio, the GPIO library of Raspberry Pi OS, for the relays and the I2C bus, and Python's own http.server and threading for the dashboard. The relays are switched so that the two channels are never on together:
lgpio.gpio_write(chip, CHARGE, 1); lgpio.gpio_write(chip, DISCHARGE, 1)
if charge or discharge:
time.sleep(0.02)
lgpio.gpio_write(chip, CHARGE if charge else DISCHARGE, 0)
A reading of the supercap's terminals, through the ADC and the divider:
return ads.volts(0) * DIVIDER
The charge stops at 90 % of the supply:
if v >= FULL * V_SUPPLY or t > 120:
The readings for the fit, between 15 % and 85 % of the way up, as ln(5 - V):
used = [(t, math.log(V_SUPPLY - v)) for t, v in pts if lo <= v <= hi]
The least-squares straight line:
b = (n * sxy - sx * sy) / (n * sxx - sx * sx)
return (sy - b * sx) / n, b
The time constant, the jump at the start, the ESR and the capacitance:
tau = -1 / b
vt0 = V_SUPPLY - math.exp(a) # the terminals the moment the relay closed
esr = R_CHARGE * ((V_SUPPLY - vc0) / (V_SUPPLY - vt0) - 1)
c = tau / (R_CHARGE + esr)
The step down at the discharge, the ESR a second time:
esr_d = R_DISCHARGE * (v_hold - v_step) / v_step # the step down: v_hold - v_step = I x ESR, I = v_step / R
The fall, the time constant a second time:
a2, b2 = fit_line([(t, math.log(v)) for t, v in dpts if v > 0.05])
What the part can do, and the nearest standard value:
r = {'n': n, 'c': cm, 'c_charge': c, 'c_discharge': c_d, 'esr': em, 'esr_charge': esr, 'esr_discharge': esr_d, 'tau': tau,
'energy': 0.5 * cm * V_SUPPLY ** 2, 'pmax': V_SUPPLY ** 2 / (4 * em), 'e6': e6, 'verdict': verdict}
return min(E6, key=lambda e: abs(math.log(c / e)))
The test runs in its own thread, and all the I2C traffic, the ADC and the OLED, stays in that thread. A test can start from any voltage, because the fit uses the voltage the supercap had when the relay closed. The dashboard's pages are / (the dashboard), /test (a new test), /stop, /curve.bmp (a 240 x 100 picture of the last test: the charge in green, the hold in white, the discharge in orange, drawn by the Pi) and /data (everything as JSON).
How to Run the Proteus Simulation
- Download the project zip below and install the library files and the TEPPi folder (the steps are under the download button).
- Open Pi-5-Supercap-Tester.pdsprj from the Proteus Simulation folder. Keep supercap_tester.py and the DLL files next to it.
- Press Play. The first test starts at once: relay 1 charges the supercap, then relay 2 discharges it. It takes about 30 seconds.
- Click the supercap (C1) for its pop-up and press E6 up: now it is a 0.15 F part.
- Open the Laptop or the Mobile WiFi Monitor, press Go, then TEST: the tester measures the new part and names it.
Simulation Results: the Supercapacitor Tester in Proteus
Here is the run that made the screenshots of this tutorial, 85 seconds of simulation: a test of the 0.1 F part as it starts empty, then a test of a 0.15 F part from where the first test left it. The times are the program's own clock, as it printed them on the Pi's terminal; the parts' numbers come from their pop-ups.
Test 1: Charging the 0.1 F Supercap
The test starts at once: the supercap reads 0.000 V, and relay channel 1 closes. The relay module's pop-up shows K1 on, its coil drawing 69 mA, and the charging current through the contact. The supercap's pop-up says CHARGING, and its green level fills; its peak current was 64.9 mA, the 5 V / 77 ohm worked out above. At 14.4 s the terminals reach 90 %, and the fit of 71 readings gives: "CHARGED to 4.503 V in 14.1 s: tau 7.76 s, the step at the start 1.945 V, ESR 29.9 ohm, C 0.1009 F". The step was predicted at 1.95 V and tau at 7.7 s.
The Discharge and the Result
After 2 s of hold, channel 1 is open and channel 2 closes; the relay pop-up shows K2 on. The terminals drop at once by 1.640 V, the current times the ESR, and then fall away. At 28.2 s: "DISCHARGED to 0.571 V: the step down 1.640 V, ESR 30.2 ohm, tau 7.70 s, C 0.0997 F". The two halves agree within 1.2 %, and the result is "C 0.1003 F (nearest E6 0.1 F), ESR 30.0 ohm, 1.25 J at 5 V, 0.21 W at most - GOOD". The supercap's own pop-up says 100.0 mF and 30.0 ohm. After the test it shows a tiny current of 30.8 uA leaving the part: that is the divider, 0.92 V over 30 kohm. The dashboard draws the whole test: the charge climbing from the 1.95 V step, the hold, the step down and the fall.
Test 2: Which Part Is This?
E6 up on the supercap's pop-up makes it a 0.15 F part. TEST on the laptop at 37.1 s, and this time the supercap starts at 0.919 V, where the first test left it. The fit does not mind: "CHARGED to 4.504 V in 18.9 s: tau 11.66 s, the step at the start 1.589 V, ESR 30.0 ohm, C 0.1515 F" from 107 readings; the step is smaller because only (5 - 0.92) x 30 / 77 = 1.59 V is left to jump. The discharge: "ESR 30.1 ohm, tau 11.54 s, C 0.1497 F". The result names the part: "C 0.1506 F (nearest E6 0.15 F), ESR 30.0 ohm, 1.88 J at 5 V - NOT 0.1 F". The tester knows it is not the 0.1 F it expects, and it says what it is instead.
| What | Test 1 (0.1 F) | Test 2 (0.15 F) |
|---|---|---|
| From the charge | tau 7.76 s, ESR 29.9 ohm, C 0.1009 F | tau 11.66 s, ESR 30.0 ohm, C 0.1515 F |
| From the discharge | ESR 30.2 ohm, tau 7.70 s, C 0.0997 F | ESR 30.1 ohm, tau 11.54 s, C 0.1497 F |
| The result | C 0.1003 F, ESR 30.0 ohm, GOOD | C 0.1506 F (E6 0.15 F), ESR 30.0 ohm |
| Energy at 5 V / most power | 1.25 J / 0.21 W | 1.88 J / 0.21 W |
| The part itself | 0.1 F, 30 ohm | 0.15 F, 30 ohm |
Download the Project Files
Click the button below to download Supercapacitor-ESR-Tester-Raspberry-Pi-5-Proteus-Simulation-v1.0.zip (about 14.5 MB, without the source code of the models):
Supercapacitor ESR Tester with Raspberry Pi 5 (Proteus Simulation) V1.0- Proteus Simulation: Pi-5-Supercap-Tester.pdsprj, supercap_tester.py and copies of the models.
- Python Code: supercap_tester.py, the program.
- Proteus Library Files: the LIB files of the Raspberry Pi 5, the supercapacitor, the relay module, the ADS1115, the OLED, the resistor and the two WiFi Monitors.
- Proteus Model Files: the DLL models and the TEPPi folder (Python 3.11 and the runtime).
- README.txt: the installation steps, the properties, the test results and the links to every library post.
No Proteus yet? Read How to Download and Install Proteus 7 and 8. New to libraries? Follow How to Install a New Library in Proteus.
How to Install the Project Files
- Close Proteus and extract the whole zip file, for example to your Desktop.
- Copy the files from Proteus Library Files into the LIBRARY folder of Proteus.
- Copy the files and the TEPPi folder from Proteus Model Files into the MODELS folder.
- Start Proteus and open the project from the Proteus Simulation folder.
Changing the Code
supercap_tester.py is plain Python: edit it next to the project and press Play again; PI1's PROGRAM property names the file it runs. The resistors, the supply, the 90 % end of the charge, the reading interval and the GOOD limits are at the top. For a bigger supercap, use bigger resistors, or the test takes minutes: the time constant grows with both. The same program runs on a real Raspberry Pi 5 with Raspberry Pi OS, where lgpio is already installed; enable I2C with raspi-config.
Ideas to Extend the Project
- Measure the leakage: hold the charged supercap for a few minutes and fit the slow fall of its voltage.
- Test at several currents, with switchable resistors, and see whether the ESR changes.
- Keep a history of each part and warn when its capacitance falls or its ESR rises, the two signs of ageing.
- Add a constant-current charger and measure C from the slope of a straight line, the way datasheets define it.
- Log every curve to a CSV file for a spreadsheet.
- Test ordinary electrolytic capacitors with smaller resistors and a faster ADC rate.
From Simulation to Real Hardware
- Never go over the rating: a 5.5 V supercap on 5 V is fine; on a 12 V supply it would burst. Check the polarity: a reversed supercap heats up.
- Mind the relay contacts: relays bounce for a few milliseconds; for the ESR step, a MOSFET switch is cleaner on a real bench.
- Measure your resistors: the result is only as good as R; use 1 % resistors or measure them with a multimeter and put the real values in the program.
- Real supercaps are slower than their ESR: charge creeps deep into the carbon pores for minutes, so a real part reads a little more capacitance on a slow test.
- Discharge before you handle it: a charged supercap can deliver a surprising spark across a screwdriver.
Troubleshooting
- The relays never click: VCC and JD-VCC on the relay module need a real 5 V supply, not a net label.
- The voltage reads 1.5 times off: the divider must be 10k to VC and 20k to ground.
- C or the ESR reads far off: R_CHARGE and R_DISCHARGE in the program must match R3 and R4.
- The test never ends: the charge stops at 4.5 V; a part that cannot reach it stops after 120 s.
- The OLED stays blank: SDA / SCL on GPIO2 / GPIO3, address 0x3C, VCC on 3.3 V.
Limitations of the Simulation
- The supercapacitor is the library's model: an ideal capacitance behind a fixed ESR with a little leakage; a real one also has slow charge redistribution and an ESR that changes with temperature.
- The relays are the module's model: they switch cleanly, without the contact bounce of real ones.
- The E6 values on the pop-up are perfect parts; real supercaps are often -20 % / +80 % of their label.
- The network to the laptop and the phone is simulated inside Proteus.
- Raspberry Pi is a trademark of Raspberry Pi Ltd and the ADS1115 a product of Texas Instruments; this project is not made or endorsed by them or by Labcenter.
So, that was all about the Supercapacitor ESR Tester with Raspberry Pi 5 in Proteus Simulation. I hope it helps you understand what a supercapacitor is, why its series resistance matters as much as its capacitance, and how one charge curve, a logarithm and a straight line give you both, all tested in a simulation before you build a real tester. More IoT projects with the Raspberry Pi 5 and the ESP32 are coming in this series. If you have any questions, ask in the comments and I will help you out. Till the next tutorial, take care and have fun!