Arduinoアナログポートをまたいで、コンデンサーつなぐと容量値を測れるという技術紹介があったので、これは面白そうと、自分でも確かめてみました。
![](https://cdn-ak.f.st-hatena.com/images/fotolife/n/nobcha23/20230311/20230311123229.jpg)
元のスケッチではA0とA2なのですが、表示にLCDシールドを使うため、A1とA3にポートをずらしました。(お隣同士のA1とA2に一旦設定したら、端子間浮遊容量により誤差が増えたので、一つ置きにしました)
「アナログポート浮遊容量を利用したコンデンサー値測定法」と言うトリッキーなやりかたです。
A0ポートの浮遊容量(C1=約30pF)とA0-A2間に接続する被測定容量CTとの間の容量比から値を計算するようです。
手元にあったシルバードマイカコンデンサーを測りましたが、そこそこの値が出ます。
![](https://cdn-ak.f.st-hatena.com/images/fotolife/n/nobcha23/20230310/20230310211401.jpg)
![](https://cdn-ak.f.st-hatena.com/images/fotolife/n/nobcha23/20230310/20230310211517.jpg)
セラコンのせいか、容量が多すぎなのか表示がふらふらしたりします。
![](https://cdn-ak.f.st-hatena.com/images/fotolife/n/nobcha23/20230310/20230310211624.jpg)
Arduinoで電子工作
http://harahore.g2.xrea.com/arduino/arduino.html
Capacitance measurement with the Arduino Uno
https://wordpress.codewrite.co.uk/pic/2014/01/21/cap-meter-with-arduino-uno/
この方式での測定容量値は1~1000pFぐらいまでなので、それ以上には容量充電時間で測る方式に切り替えるらしい。
Capacitance Meter Mk II
https://wordpress.codewrite.co.uk/pic/2014/01/25/capacitance-meter-mk-ii/
スケッチ(LCD Keypad Shieldを使用)
// Refer "Capacitance measurement with the Arduino Uno"
// https://wordpress.codewrite.co.uk/pic/2014/01/21/cap-meter-with-arduino-uno/
const int OUT_PIN = A3; //Changed for LCD Keypad Shield used
const int IN_PIN = A1; //Changed for LCD Keypad Shield used
//Capacitance between IN_PIN and Ground
//Stray capacitance is always present. Extra capacitance can be added to
//allow higher capacitance to be measured.
const float IN_STRAY_CAP_TO_GND = 24.48; //initially this was 30.00
const float IN_EXTRA_CAP_TO_GND = 2.0; // tuned
const float IN_CAP_TO_GND = IN_STRAY_CAP_TO_GND + IN_EXTRA_CAP_TO_GND;
const int MAX_ADC_VALUE = 1023;
//LCD Keypad Shield is used
#include
LiquidCrystal lcd( 8, 9, 4, 5, 6, 7);
void setup()
{
pinMode(OUT_PIN, OUTPUT);
//digitalWrite(OUT_PIN, LOW); //This is the default state for outputs
pinMode(IN_PIN, OUTPUT);
//digitalWrite(IN_PIN, LOW);
Serial.begin(9600);
lcd.begin(16, 2);
}
void loop()
{
//Capacitor under test between OUT_PIN and IN_PIN
//Rising high edge on OUT_PIN
pinMode(IN_PIN, INPUT);
digitalWrite(OUT_PIN, HIGH);
int val = analogRead(IN_PIN);
//Clear everything for next measurement
digitalWrite(OUT_PIN, LOW);
pinMode(IN_PIN, OUTPUT);
//Calculate and print result
float capacitance = (float)val * IN_CAP_TO_GND / (float)(MAX_ADC_VALUE - val);
Serial.print(F("Capacitance Value = "));
Serial.print(capacitance, 3);
Serial.print(F(" pF ("));
Serial.print(val);
Serial.println(F(") "));
lcd.setCursor(0, 0);
lcd.print("Cap = ");
lcd.print(capacitance, 3);
lcd.print(" pF ");
while (millis() % 500 != 0)
;
}