element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino Projects
  • Products
  • Arduino
  • Arduino Projects
  • More
  • Cancel
Arduino Projects
Blog CAPACITANCE METER PROTOTYPE
  • Blog
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino Projects to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Spain_mtg
  • Date Created: 7 Jul 2023 10:10 AM Date Created
  • Views 1977 views
  • Likes 11 likes
  • Comments 4 comments
  • ardbeginner
  • arduino_projects
  • arduino nano project
Related
Recommended

CAPACITANCE METER PROTOTYPE

Spain_mtg
Spain_mtg
7 Jul 2023
CAPACITANCE METER PROTOTYPE

CAPACITANCE METER PROTOTYPE

   This is my first proyect, a capacitance meter prototype of capacitors with Arduino. As we know, the Arduino digital pins have an output voltage of 5 volts, we are going to take advantage of this voltage and the ADC function of the Arduino analog pins to perform the necessary calculations and in this way know the capacitance of the capacitors.


   First, a simple brief detail about the charging of the capacitors. The simplest circuit for charging a capacitor and its curve charge are:

image

   When we connect a capacitor to a voltage, we can know the time it takes to charge to 63.2% of the voltage supply using the equation:

T = RxC

   Where T is the time constant in Seconds, R is the resistance in Ohms of the circuit and C is the value of the capacitor in Farad.The defintion of the Time Constant of a capacitor is the time that it take to charge to the 63,2% of the voltaje supply.

  How can we know then the time taken to charge to 63.2%? The response is: using the ADC in the Analog ports, since 63.2% of 5 volts is 3.16 volts. The simplified circuit is:

image

   The project have a switch to select the measurement of capacitors in the uF-nF and nF-pF ranges and an OLED screen to show the measurements.


MATERIALS

1 x Arduino Nano
2 x 1K resistors
1 x 10K resistor
1 x 220 ohm resistor
1 x 0.91 inch OLED I2C Display 128x32 pixels
1 x PCB Board
1 x Switch
Wire
Sockets

PROJECT CIRCUIT

image

High values (F-nF) measurement circuit , select pin D6 with the switch

   We start charging the capacitor with pin A2 through the 10K resistor, at the same time we start a timer and measure the voltage at pin A0. We know that the voltage supplied by the Arduino pins is 5V, so using the ADC we know that 5V is 1023 and 63.2% of 5V is 3.16V and it is equivalent to the value of 648, when the reading from pin A0 reaches at the value of 648, we stop supplying voltage and stop the timer. Next, dividing the time taken by the 10K resistor, we find the value of the capacitor and begin to discharge it.


Low values (nF-pF) measurement circuit, select pin D5 with the switch

   For low values we use the load and measured by pins A3 and A0 respectively. We supply the 5V voltage with pin A3 through the 220 ohm resistor and start charging the capacitor. We use the ADC of pin A0, if the value is less than 976 it means that the value of the capacitor is a quantity in pF, we carry out the necessary calculations using the measurement taken and the margin of error of the internal resistance of the Arduino with the exterior resistor.


   If the reading at A0 is greater than 976, then we configure pin A0 to supply 5V output and pin A3 to read the voltaje. We count the time in microseconds and if in a time 400 ms the reading does not reach 5V, we carry out the calculations of the capacitor capacity with the value of the internal pull-up resistor, the measurement of time and the conversión value of the ADC of the voltaje measurement in A3. If the result of the value is greater than 1000 the measurement is in uF, while if it is less it will be in pF.


PICTURE PROYECT

image

image

image

image

image

image

   SKETCH

/* Spain_mtg - Capacitence Meter */

//OLED screen config
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define SCREEN_WIDTH 128 	        				// Width screen OLED
#define SCREEN_HEIGHT 32 	       					// Height screen OLED

// Adafruit_SSD1306 class object        						
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);	// -1 if sharing Arduino reset pin

// Switch to select values to measure
int ScalepF=5;
int ScalenF=6;

//High values//
#define analogPin      A0         
#define chargePin      A2
#define dischargePin   A1
#define resistorValue  10000.0F         				// 10K resistor value to charge the capacitor

unsigned long startTime;
unsigned long elapsedTime;
float microFarads;                
float nanoFarads;

//Low values//
const int OUT_PIN = A3;
const int IN_PIN = A0;  
const float IN_STRAY_CAP_TO_GND = 50.28;      				// Value with 220 resistors 
                                              
const float IN_CAP_TO_GND  = IN_STRAY_CAP_TO_GND;
const float R_PULLUP = 30.0;  
const int MAX_ADC_VALUE = 1023;

void setup() {
  Serial.begin(9600);
  delay(100);
  Serial.println("Initializing OLED display");

  // Start OLED display at address 0x3C
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
  	Serial.println(F("OLED screen not found"));
  	for(;;); // Don't proceed, loop forever
  }

  pinMode(ScalepF, INPUT);
  pinMode(ScalenF, INPUT);

  pinMode(OUT_PIN, OUTPUT);
  pinMode(IN_PIN, OUTPUT);
  pinMode(chargePin, OUTPUT);     
}

void loop() {

  /***************************    HIGH VALUES: SCALE 4F - 100nF    ****************************************/

  if (digitalRead(ScalenF)) {
  
    pinMode(OUT_PIN, OUTPUT);
    digitalWrite(OUT_PIN, LOW);          				// A3 like GND
    pinMode(analogPin, INPUT);           				// A0 read the voltage
  
    digitalWrite(chargePin, HIGH);  
    startTime = micros();

    while (analogRead(analogPin) < 648) {   }     			// The capacitor is charging

    elapsedTime = micros() - startTime;
    microFarads = ((float)elapsedTime / resistorValue);
     
    if (microFarads > 1) {

    	display.clearDisplay();                                 	// Clean buffer
    	display.setTextSize(1);                                 	// Text size  	
    	display.setTextColor(SSD1306_WHITE);                    	// Color text  	
    	display.setCursor(1, 2);                               		// Text position
    	display.println("Scale: 4F-100nF");
    	display.setCursor(1, 12);
    	display.println(microFarads);
    	display.setCursor(50, 12);
    	display.println("uF");	
    	display.display();                                      	// Display text on screen	
    	delay(500);

    } else {

    	nanoFarads = microFarads * 783;
    	display.clearDisplay();                                 	// Clean buffer
    	display.setTextSize(1);                                 	// Text size  	
    	display.setTextColor(SSD1306_WHITE);                    	// Color text  	
    	display.setCursor(1, 2);                               	        // Text position
    	display.println("Scale: 4F-100nF");
    	display.setCursor(1, 12);
    	display.println(nanoFarads);
    	display.setCursor(50, 12);
    	display.println("nF");  	
    	display.display();                                      	// Display text on screen	
    	delay(500);
 
    }
  
    digitalWrite(chargePin, LOW);            
    pinMode(dischargePin, OUTPUT);            
    digitalWrite(dischargePin, LOW);          				// Discharging the capacitor     
  
    while (analogRead(analogPin) > 0) {   }     			// Waits till the capaccitor is discharged

    pinMode(dischargePin, INPUT);             				// This sets the pin to high impedance
  
    display.setTextSize(1);                                 		// Text size  	
    display.setTextColor(SSD1306_WHITE);                    		// Color text  	
    display.setCursor(1, 22);                               		// Text position
    display.println("DISCHARGING.....");     				// Message to display	
    display.display();                                      		// Display text on screen	
    delay(1000);
 
  
  }

  /****************************    LOW VALUES SCALE 1nF - 1pF    ***************************/

  if (digitalRead(ScalepF)) {
    
    pinMode(chargePin, INPUT);
    pinMode(dischargePin, INPUT);        				// Configure ports with high impedance because it is not used

    pinMode(IN_PIN, INPUT);
    digitalWrite(OUT_PIN, HIGH);
    int val = analogRead(IN_PIN);
    digitalWrite(OUT_PIN, LOW);

    if (val < 976) {
      
      pinMode(IN_PIN, OUTPUT);

      float capacitance = ((float)val * IN_CAP_TO_GND / (float)(MAX_ADC_VALUE - val))/2;                        
           
      display.clearDisplay();                                 		// Clean buffer
      display.setTextSize(1);                                 		// Text Size  	
      display.setTextColor(SSD1306_WHITE);                    		// Color text  	
      display.setCursor(1, 2);                               		// Text position
      display.println("Scale: 1nF-1pF");				// Message to display
      display.setCursor(1, 12);						// Text position
      display.println(capacitance);					// Value to display
      display.setCursor(50, 12);
      display.println("pF"); 	
      display.display();                                      		// Display text on screen	
      delay(200);

    } else {

      pinMode(IN_PIN, OUTPUT);
      delay(1);
      pinMode(OUT_PIN, INPUT_PULLUP);
      unsigned long u1 = micros();
      unsigned long t;
      int digVal;

      do {
        digVal = digitalRead(OUT_PIN);
        unsigned long u2 = micros();
        t = u2 > u1 ? u2 - u1 : u1 - u2;
      } while ((digVal < 1) && (t < 400000L));

      pinMode(OUT_PIN, INPUT);
      val = analogRead(OUT_PIN);
      digitalWrite(IN_PIN, HIGH);
      int dischargeTime = (int)(t / 1000L) * 5;
      
      delay(dischargeTime);   
      
      pinMode(OUT_PIN, OUTPUT);  
      digitalWrite(OUT_PIN, LOW);
      digitalWrite(IN_PIN, LOW);

      float capacitance = -(float)t / R_PULLUP / log(1.0 - (float)val / (float)MAX_ADC_VALUE);
      
      if (capacitance > 1000.0) {
        display.clearDisplay();                                 		// Clean buffer
        display.setTextSize(1);                                 		// Text size  	
        display.setTextColor(SSD1306_WHITE);                    		// Color text  	
        display.setCursor(1, 2);                               			// Text position
        display.println("Scale: 1nF-1pF");
        display.setCursor(1, 12);
        display.println(capacitance/1000.0, 3);
        display.setCursor(50, 12);
        display.println("uF");  	
        display.display();                                      		// Display text on screen	
        
        delay(200);    
      
      } else {
        display.clearDisplay();                                 		
        display.setTextSize(1);                                 		 	
        display.setTextColor(SSD1306_WHITE);                    		 	
        display.setCursor(1, 2);                               			
        display.println("Scale: 1nF-1pF");
        display.setCursor(1, 12);
        display.println(capacitance, 3);
        display.setCursor(50, 12);
        display.println("pF");  	
        display.display();                                      			
        
        delay(200); 
      }
    }         
    while (micros() % 1000 != 0);
  }
}

  • Sign in to reply

Top Comments

  • shabaz
    shabaz over 2 years ago +1
    This is quite a complex first project! One thing worth modifying is to add a MOSFET to perform the discharge operation rather than use the GPIO pin as output set to 0V. When you set the GPIO pin in that…
  • Spain_mtg
    Spain_mtg over 1 year ago in reply to shabaz

    Thanks for the recommendation Shabaz.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Spain_mtg
    Spain_mtg over 1 year ago in reply to DAB

    Thank you !!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 2 years ago

    Very good first project.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • shabaz
    shabaz over 2 years ago

    This is quite a complex first project!

    One thing worth modifying is to add a MOSFET to perform the discharge operation rather than use the GPIO pin as output set to 0V. When you set the GPIO pin in that way, a tiny MOSFET inside the microcontroller switches on. The MOSFET cannot handle the high current from the charged capacitor and may eventually blow. So, to protect that tiny MOSFET, you can either add a resistor to reduce the discharge current or add an external MOSFET (google 'mosfet open drain' to see examples of how to wire that.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • More
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube