超便宜測量電感的方法 Inexpensive measuring inductance with arduino

   一般要量測電感需要專用的 LCR 電錶或是用示波器,都不便宜,在網路上找到這篇
https://reibot.org/2011/07/19/measuring-inductance/ ,
使用 arduino 加上一個極簡單的電路達成,
關鍵的元件只有三個:
一個電壓比較器或 op amp、
兩個 1uF 無極性電容、
以及一台 arduino 相容板。

我用的是 LM393P 低功耗電壓比較器 $2
http://goods.ruten.com.tw/item/show?21403134960362

陶瓷電容 1uF(105) $0.8
http://goods.ruten.com.tw/item/show?21439300127596
或是用較小的並䏈
陶瓷電容 0.1uF(104) $8
http://goods.ruten.com.tw/item/show?21601579393657


電路圖

Measuring inductance with arduino
程式
// resonant frequency counting for inductance measuring
#define chargePin 13
#define pulsePin 11
void setup() {
  Serial.begin(115200);
  pinMode(pulsePin, INPUT);
  pinMode(chargePin, OUTPUT);
  Serial.println("LC Meter");
}
double pulse, frequency, inductance;
void loop() {
digitalWrite(chargePin, HIGH); // charge LC circuit.
delay(5);
digitalWrite(chargePin, LOW);
//
pulse = pulseIn(pulsePin, HIGH, 1000); //returns 0 if timeout
if (pulse > 0.1) {
 const double capacitance = 1.89E-6; // ~2 uF
 frequency = 1E6 / (2 * pulse);
 inductance = 1E6 / ( 4 * 3.1415926535 * 3.1415926535 * capacitance * frequency * frequency );
 Serial.print( int(pulse) );
 Serial.print(" uS, ");
 Serial.print( frequency );
 Serial.print(" Hz, ");
 Serial.print( inductance );
 Serial.println(" uH");
}
delay(480);
}
// end

原理:
當LC電路放電時,會震盪產生一個頻率,叫 resonant frequency
f = 1/(2π√LC)
https://en.wikipedia.org/wiki/LC_circuit

已知電容和頻率就可以算出電感
L =  1 / (4C π^2 f^2)

arduino 測量頻率的方法:
LC 的信號經過比較器後變成 0~5V 的方波(大於零變5V 小於零變 0V)
arduino 的 pluseIn() 可以測量信號在 HIGH 的時間

所以 頻率 f = 1 / ( 2 * pluseIn() 時間)

我的兩個1uF電容量測起來約 ~1.89 uF,使用較小的電容時因為頻率會上升,
arduino 的限制無法量到更小的時間 (10^-6),如果要量較小的電感,需要較大的電容,
用 1.89uF 實測可以量到 10 uH 以上。