Arduino Capacitance Meter: Wiring, Code and Simulator
To build this Arduino Capacitance Meter project you need an Arduino Uno and a 10 kΩ resistor, a 220 Ω resistor, a 10 µF electrolytic capacitor and an oscilloscope. Pin 8 charges an unknown capacitor through 10 kΩ; the sketch times how long A0 takes to reach 63.2 % — one time constant — and prints C = τ / R. Make the 9 connections in the wiring table, upload the Arduino C++ code, and watch the serial monitor print about 10 µF, then change the capacitor to 47 µ or 1 µ and see the measurement follow. The scope shows each charge curve.
Open this circuit in the free Arduino Uno simulator
Parts list
| Qty | Part | What it does |
|---|---|---|
| 1 | Arduino Uno | the microcontroller board |
| 1 | 10 kΩ resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
| 1 | 220 Ω resistor | Limits current. 220 Ω in series with an LED; 10 kΩ as a pull-up or pull-down. |
| 1 | 10 µF electrolytic capacitor | A large, polarised capacitor for smoothing supplies: the stripe marks − . Reverse it, or exceed its voltage rating, and it fails. |
| 1 | Oscilloscope | Two channels against earth (GND). Turn TIME/DIV and VOLTS/DIV to fit the wave, set the trigger level to steady it, and read Vpp, RMS and frequency. X-Y mode draws Lissajous figures. Choose a digital (DSO) or phosphor (CRO) screen. |
Wiring
| # | From | To |
|---|---|---|
| 1 | Arduino Uno pin 8 | 10 kΩ resistor leg 1 |
| 2 | 10 kΩ resistor leg 2 | 10 µF electrolytic capacitor + |
| 3 | Arduino Uno pin 7 | 220 Ω resistor leg 1 |
| 4 | 220 Ω resistor leg 2 | 10 µF electrolytic capacitor + |
| 5 | Arduino Uno GND | 10 µF electrolytic capacitor - |
| 6 | Arduino Uno A0 | 10 µF electrolytic capacitor + |
| 7 | Arduino Uno pin 8 | Oscilloscope CH1 |
| 8 | 10 µF electrolytic capacitor + | Oscilloscope CH2 |
| 9 | Arduino Uno GND | Oscilloscope GND |
Step by step
- Open the simulator. Open the BitForBytes Embedded Lab in your browser and start from the Arduino Uno. No install or account is needed.
- Add the parts. Add a 10 kΩ resistor, a 220 Ω resistor, a 10 µF electrolytic capacitor and an oscilloscope from the parts palette.
- Wire 1. Connect Arduino Uno pin 8 to 10 kΩ resistor leg 1.
- Wire 2. Connect 10 kΩ resistor leg 2 to 10 µF electrolytic capacitor +.
- Wire 3. Connect Arduino Uno pin 7 to 220 Ω resistor leg 1.
- Wire 4. Connect 220 Ω resistor leg 2 to 10 µF electrolytic capacitor +.
- Wire 5. Connect Arduino Uno GND to 10 µF electrolytic capacitor -.
- Wire 6. Connect Arduino Uno A0 to 10 µF electrolytic capacitor +.
- Wire 7. Connect Arduino Uno pin 8 to Oscilloscope CH1.
- Wire 8. Connect 10 µF electrolytic capacitor + to Oscilloscope CH2.
- Wire 9. Connect Arduino Uno GND to Oscilloscope GND.
- Paste the Arduino C++ code. Paste the Arduino C++ code below into the code editor.
- Run it. Press Run. Watch the serial monitor print about 10 µF, then change the capacitor to 47 µ or 1 µ and see the measurement follow. The scope shows each charge curve.
Arduino C++ code
// Capacitance meter: charge a capacitor through a known resistor and time it.
// pin 8 -- 10 kOhm --+-- A0
// |
// C (the unknown)
// |
// GND
// After one time constant (tau = R x C) the capacitor reaches 63.2% of 5 V,
// so C = t / R. Pin 7 discharges it through 220 Ohm between measurements.
const float R = 10000.0;
void setup() {
Serial.begin(9600);
pinMode(8, OUTPUT);
digitalWrite(8, LOW);
}
void loop() {
// Discharge: pin 7 pulls the capacitor down through 220 ohm.
pinMode(7, OUTPUT);
digitalWrite(7, LOW);
while (analogRead(A0) > 0) {}
pinMode(7, INPUT); // let go of it
unsigned long start = micros();
digitalWrite(8, HIGH); // start charging
while (analogRead(A0) < 647) {} // 63.2% of 1023
unsigned long t = micros() - start;
digitalWrite(8, LOW);
float microfarads = (float)t / R; // t in us / R in ohm = C in uF
Serial.print("tau = ");
Serial.print(t);
Serial.print(" us -> C = ");
Serial.print(microfarads, 2);
Serial.println(" uF");
delay(500);
}
What to try
Watch the serial monitor print about 10 µF, then change the capacitor to 47 µ or 1 µ and see the measurement follow. The scope shows each charge curve.
Frequently asked questions
How do I wire the Capacitance Meter project on an Arduino Uno?
Make 9 connections: Arduino Uno pin 8 to 10 kΩ resistor leg 1; 10 kΩ resistor leg 2 to 10 µF electrolytic capacitor +; Arduino Uno pin 7 to 220 Ω resistor leg 1; 220 Ω resistor leg 2 to 10 µF electrolytic capacitor +; Arduino Uno GND to 10 µF electrolytic capacitor -; Arduino Uno A0 to 10 µF electrolytic capacitor +; Arduino Uno pin 8 to Oscilloscope CH1; 10 µF electrolytic capacitor + to Oscilloscope CH2; Arduino Uno GND to Oscilloscope GND.
What parts do I need for this Arduino project?
An Arduino Uno and a 10 kΩ resistor, a 220 Ω resistor, a 10 µF electrolytic capacitor and an oscilloscope.
Can I simulate this Arduino project online for free?
Yes. The BitForBytes Embedded Lab runs this exact circuit and Arduino C++ code in your browser for free, with no install and no hardware. The sketch is compiled with the real Arduino toolchain and runs on an emulated ATmega328P.
What does the code do?
Pin 8 charges an unknown capacitor through 10 kΩ; the sketch times how long A0 takes to reach 63.2 % — one time constant — and prints C = τ / R.
More Arduino Uno projects
- Arduino LED Blink: Wiring, Code and Simulator
- Arduino LDR Light Sensor: Wiring, Code and Simulator
- Arduino NTC Thermistor Thermometer: Wiring, Code and Simulator
- Arduino PWM to Analog RC Filter: Wiring, Code and Simulator
- Arduino DC Motor PWM Speed Control with MOSFET: Wiring, Code and Simulator
- Arduino Push Button LED: Wiring, Code and Simulator