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:
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:
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
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
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);
}
}
Top Comments