Wednesday, March 22, 2023

Arduino Based Digital Capacitance Meter: An Interrupt Based Approach

Saikat Patra is passionate about electronics and MCU based embedded system applications -- Shibendu Mahata is M.Tech (gold medallist) in instrumentation and electronics engineering from Jadavpur University. Currently, he is pursuing Ph.D from NIT, Durgapur. He is interested in MCU based real-time embedded signal processing and process control systems

- Advertisement -
Circuit diagram of Arduino based digital capacitance meter with NE555 timer in monostable mode
Fig. 5: Circuit diagram of Arduino based digital capacitance meter with NE555 timer in monostable mode

In this mode of operation, when trigger pin of the timer is made low (0V) by sending an active low pulse from pin 9, output of the timer (from pin 3) goes high (+5V) for a certain period of time, which is determined by the values of R1 and Cx. Time period (T) for which the timer’s output remains high is given as:

T = 1.1×R1×Cx

Output of the timer is connected to pin 2 of Arduino, which is a hardware interrupt pin (called Interrupt 0). The source code (capacitance2.ino) uploaded to Arduino uses an interrupt-within-an-interrupt handler, that is, a two-level nested interrupt sub-routine (ISR).

- Advertisement -

The first interrupt-handler gets executed whenever the timer output makes low-to-high transition, and the second ISR is called from within the first when timer output makes high-to-low transition. Thus, time for which the output of the timer remains high is obtained by calculating the time difference between two such consecutive interrupts, which is equal to T.

Thus, value of Cx is given as:
Cx = T/(1.1×R1)

Measured value of Cx (in µF) is then displayed on a 16×2-character LCD and serial monitor of Arduino IDE.

NE555 timer

NE555 timer IC1 operates in monostable multivibrator mode, where time for the output goes high, after applying high-low-high pulse from pin 9 of Arduino, which is controlled by R1 and Cx connected externally to the IC.

Output of timer pin 3 is connected to interrupt pin (pin 2) of Arduino. Pins 4 and 8 of the IC1 are connected to +5V connector of Board 1. R1 of 100k is connected between pins 8 and 7. IC1 shares the same ground with Arduino board. The authors’ designed breakout board for the timer is shown in Fig. 6.

NE555 timer connection in authors’ breakout board
Fig. 6: NE555 timer connection in authors’ breakout board


The code (capacitance2.ino) written in Arduino programming language uses LiquidCrystal.h header file provided by Arduino library for working with the LCD.

attachInterrupt(0,analyze1,RISING) function calls the interrupt handler named analyze1 whenever output of IC1 connected to interrupt 0 pin (pin 2) of Arduino makes low-to-high, that is, rising-edge transition.

attachInterrupt(0,analyze2,FALLING) function calls the interrupt handler named analyze2 whenever output of IC1 connected to pin 2 of Arduino makes high-to-low, that is, falling-edge transition.

The high-low-high trigger pulse applied to pin 2 of IC1 is generated by pin 9 of Arduino using the following code within void loop() function. Refer source code for the same.

[stextbox id=”grey”]

void loop ( ){
digitalWrite(9, HIGH);
digitalWrite(9, LOW);
digitalWrite(9, HIGH);
while (1);


Note. To test a new capacitor (Cx), connect the capacitor and press Reset on Arduino Uno board.

Download source code



  1. I have built the circuit, downloaded the code for capacitance 1 and uploaded it to Arduino and run it The lcd displays Capacitance: 0.000uF even with a 10uf capacitor used as Cx. I don’t know how to solve it . it may be the code. I have double checked the circuit Arduino to LCD display and the 555 but nothing wrong. Perhaps you can help?



What's New @

Truly Innovative Tech

MOst Popular Videos

Electronics Components

Tech Contests