codewrite / arduino-capacitor

Capacitance measurement library for Arduino
GNU General Public License v3.0
36 stars 8 forks source link

Testing this library out on an Arduino Uno R3, and it does not return the right value #10

Open TechPro424 opened 1 month ago

TechPro424 commented 1 month ago

I tested the library out on an Arduino Uno R3 (that I borrowed from a friend) using a 47pF capacitor and it does not seem to return the right value. (Returns around 3600 to 3700) I used the CapacitorLite example, but set the delay to 5 seconds

Code:

/*
    MeasureCapacitorLite

    Measures the capacitance between D7 and A2.
    Prints the result to the Serial Monitor.

    This is the "Lite" version. It uses a lot less program storage and is a lot quicker than the "Standard" version.
    However, it will only measure from 0.2pF to 655pF.
    Also, note that Measure() returns an unsigned int (pF * 100) rather than a float.

    For more detailed usage examples (e.g. liquid level measurement) and explanation of how the library works please see the wiki:
    https://github.com/codewrite/arduino-capacitor/wiki

    This example code is in the public domain.
*/
#include <CapacitorLite.h>

// Capacitor under test.
CapacitorLite cap1(7,A2);

void setup() {
  Serial.begin(9600);
}

void loop() {
  Serial.println(cap1.Measure());  // Measure the capacitance (in pF * 100), print to Serial Monitor
  delay(5000);                     // Wait for 1 second, then repeat
}

Output for a 47pF capacitor:

3715
3656
3730
3641
3670
3670
3626
3656
3641
3700
3715
3656
3730
3641
3670
3670
3626
3656
3641
3700
TechPro424 commented 1 month ago

For a 4.7 pF cap:

527
580
580
487
509
502
576
542
527
580
580
487
509
502
576
542
TechPro424 commented 1 month ago

Bump

TechPro424 commented 1 month ago

Tried using Capacitor instead if CapacitorLite, and got these values (for a 47 pF cap)

37.61
37.30
37.30
37.76
37.61
37.61

Code:

/*
    MeasureCapacitor

    Measures the capacitance between D7 and A2.
    Prints the result to the Serial Monitor.

    This example code is in the public domain.
*/
#include <Capacitor.h>
#include <CapacitorLite.h>

// Capacitor under test.
// Note that for electrolytics the first pin (in this case D7)
// should be positive, the second (in this case A2) negative.
Capacitor cap1(7,A2);

void setup() {
  Serial.begin(9600);
}

void loop() {
  while (Serial.available() == 0) {
  }

  String input = Serial.readString();

  if(input.length() > 0) {Serial.println(cap1.Measure());
  }  // Measure the capacitance (in pF), print to Serial Monitor  
}
TechPro424 commented 1 month ago

For a 4.7 pF cap

5.35
5.09
5.39
5.35
5.20