Easily measuring inductance with Arduino
July 19, 2011 45 Comments
So you need to make or measure an inductor, but you don’t have an oscilloscope or signal generator? Measuring inductance with a handful of cheap common parts is certainly possible. I’ve verified this method is accurate with a scope from 80uH to 30,000uH, but it should work for inductors a bit smaller or much larger. There are some contingencies to keep in mind when it comes to measuring inductors — more on this in “Other Notes:“
There are three components that you’ll probably have to buy, but they can be picked up at your local Radio$hack: LM399 and two 1uF non polar capacitors – look at the schematic. If you don’t want to shop at radio$hack, there is a list of products at the end that should work.
No Arduino?
There is 1 digital output and 1 digital input, so this will work with most micro controllers. The output works better with a high current and uses ~33mA at 5V. The only thing left is to measure the rising edge to falling edge time on a square wave. You may want to look at the code if you’re unsure about how to enter the equations, you too can measure inductance with a microcontroller!
A short lesson on the theory:
An inductor in parallel with a capacitor is called an LC circuit, and it will electronically ring like a bell. Well regardless of the frequency or how hard a bell is struck, it will ring at it’s resonating frequency. We will electronically strike the LC bell, wait a bit to let things resonate, then take a measurement. There is some internal resistance so this is really an RLC circuit, and I’ll talk about this more in the math.
Now micro controllers are terrible at analyzing analog signals. The ATMEGA328 ADC is capable of sampling analog signals at 9600hz or .1ms, which is fast but no where near what this project requires. Let’s go ahead and use a chip specially designed for turning real world signals into basic digital signals: The LM339 comparator which switches faster than a normal LM741 op amp, but there will be a schematic for the LM741 too.
As soon as the voltage on the LC circuit becomes positive, the LM339 will be floating, which can be pulled high with a pull up resistor. When the voltage on the LC circuit becomes negative, the LM339 will pull its output to ground. I’ve noticed that the LM339 has a high capacitance on it’s output, which is why I used a low resistance pull up.
Math:
Since our wave is a true sinusoidal wave, it spends equal time above zero volts and below zero volts. This means that the comparator will turn it into a square wave with a duty of 50%, and pulseIn(pin, HIGH, 5000); will measure the time in microseconds elapsed from rising edge to falling edge. This measurement can then be doubled to get the period and the inverse of the period is the frequency. Since the circuit is resonating, this frequency is the resonating frequency.
To the left are the equations where f is the resonating frequency, c is capacitance, and L is inductance. Solving for inductance will result in the last equation
Since this is an RLC circuit due to internal resistance, it won’t change any characteristics of the resonating frequency. The RLC will still resonate, but the amplitude will die out. With a low resistance the RLC will tend to latch onto the exact resonating frequency quicker. For you EE’s think of the frequency response of an RLC with low resistance versus high resistance.
Parts that should work:
review the circuit before buying anything. All resistors are 1/4 watt, but anything will work.
- LM741 – just search for LM741 at your favorite parts engine. here’s what I used
- LM339 – just search for LM339 at your favorite parts engine here’s what I used
- 1uF capacitor – a, b, c, here’s what I used, 5% tolerance do not use electrolytic or tantalum
The Circuit:
Pick whichever circuit is better for you, but the one using the LM339 is better. Both the capacitors are 1uf metalized film, but anything that is non polar will work. It will need to be very close to 2 uF though. You can not use a capacitor that marks which connection is ground. One thing you may notice is that the LM741 is geared for analog computing. This means that it requires a negative voltage on it’s V- pin. If you don’t have a power supply that offers this, use two AA batteries to go 3v below ground as shown. The LM339 doesn’t need this and there is no problem inputting a negative voltage. Remember that the LC circuit will vary above and below ground. Here’s a picture of the breadboard.
Code:
Code for Arduino – With large inductors, you may need to increase the timeout on pulseIn() from 5000 to 10000. If you’re having issues with very small inductors – under 200uH – increase the delayMicroseconds() right before pulseIn() to a larger value ~500uS.
Other Notes:
Not accurate enough? If you look at the equation and you’ll see that the capacitor’s tolerance is key. Expect your results to be accurate within ~10% with a 10% tolerance capacitor. What does this mean? Let’s say you’re using a 10% tolerance capacitor, and the Arduino spits out that the inductor is 1000uH. Well this means that the inductor is in between 900uH and 1100uH. Think of a bell curve if you’ve taken a statistics class – most capacitors with 10% tolerance will be under 10%. (pdf)
If you require a very accurate measurement for a system running at a very high frequency, then this method is definitely not for you due to parasitic capacitance, which isn’t taken into account. This method uses low current to measure inductance, so saturation characteristics will be unavailable (measurements will be taken in an unsaturated state.) This won’t be an issue for most people.
There is this wonderful thing called permeability. Filling an inductor with certain materials changes the inductance without changing the coils. This is similar to mutual inductance in transformers. Ever notice how high frequency transformers are made with nearly non conductive ferrite, and 60hz transformers are made with an iron/steel?
You could make a metal detector. Inductors that don’t have closed fields — not magnetically isolated — will change their inductance when something with a different permeability than air is near.
If you have access to fast sampling rates, you can use the method on the right too, but it will require a p type mosfet to really pump some current into the inductor and R1 less than an ohm or so, but greater than the equivalent series resistance of the inductor. This method will probably run into saturation issues if the sample isn’t taken quickly, but if you’re smart about it you should be able to get information about the saturation characteristics.
And there you have it! This is the most difficult part to build on a diy LCR meter.






Pingback: Easily measuring inductance with Arduino « adafruit industries blog
Pingback: Electronics-Lab.com Blog » Blog Archive » Easily measuring inductance with Arduino
Looks like there is a bug in your program:
the line
pulse = pulseIn(9,HIGH,5000);//returns 0 if timeout
Should be
pulse = pulseIn(11,HIGH,5000);//returns 0 if timeout
since you define pin 11 as the input pin.
Thanks for the nifty idea, this will be really helpful for me.
Fixed.
Yes Thank you for pointing that out I probably changed that when I went from the LM741 to LM339. puseIn() will change the pin to digital input anyway, which is probably why I didn’t catch it.
Built the circuit today and it works great! Just a tip on improving the accuracy – most digital multimeters have a capacitance measurement. Just measure your caps and use that. Not sure what is now driving the accuracy now, DMM tolerance? timing of the LM339? Either way, it is more accurate by a couple orders of magnitude.
Also, not that the code needs much optimization based on its simplicity, but I moved the capacitance definition to the void setup() function so the little microcontroller isn’t constantly redefining it.
Good to hear it! you can use different capacitance, and a larger capacitance will be able to measure smaller inductors. The main drawback is that in order to get energy into smaller inductors is that it requires much more current. Could be done with a p type mosfet and the mosfet ESR wouldn’t change resonation.
Yes if you have a DMM that can measure capacitance, then that will be the best thing to use for capacitance. My multimeter was about 10$ lol and doesnt.
Thank you for your article and code.
What would the schematic look like with the p-channel mosfet included?
I’m also interested in measuring smaller inductances << 20 uH – down to 1uH or less.
using the P channel mosfet: Vin on the image above would be connected to the drain on the p channel mosfet

I’ve thought of a few ways how to measure very small inductances thinking in terms of the frequency domain rather than a resonanting circuit. This would allow a circuit measure at different frequencies (like 100kHz, which i think is the standard for measuring inductors.)
I may get to it this summer, and I will definitely post results and a guide!
Can you use the internal comparator present on the AVR?
The main thing to keep in mind is that the LC circuit may go 10-15 volts above and below ground, so this would be somewhat of a concern for the micro since they’re picky about voltage. Did some searching around and it looks like a no, but definitely send an update if you get it working!
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1163394545
and it’s on section 22.1 of the atmega328 datasheet
i’d start an attempt like this with a pin change interrupt and wheatstone bridge to scale up the signal… adjust the resistance of R2 or R3 to pull the signal within range… might have to use a fast switching zener to block out noise: negative end of the zener connected to the zener, current limiting R between zener and digital pin with resistance large enough to keep the current below whatever will fry the zener — if a digital output is used as the excitation voltage, and the zener can handle 40mA, then the R can be ignored. i don’t know how zeners affect oscillating circuits, though.
I successfully done it. You only need 10-20k resistor connected before arduino comparator positive input. It is required to drop high voltage spikes through internal clamping diodes, which are exists inside any atmega chip. So, it is safe enough.
The only one tricky thing, is to write precise procedure to count time between comparator change it’s state. I’ve done it using inline assembler with interrupts disabled. The results are great. I checked accuracy using some marked inductors, and it’s about 2-5%.
Good luck!
Pingback: ArduinoProjects.INFO » Easily measuring inductance with Arduino
Pingback: Using an Arduino to measure inductance - Hack a Day
Pingback: Using an Arduino to measure inductance
Pingback: Using an Arduino to measure inductance | The Depot of Talk
Hey very neat idea :)! As for trying to remove the comparator, my suggestion is to feed the oscillation through a capacitor to the center of a Vcc resister divider by 2, then a current limiting resistor and to the AVR’s comparator.
Feeding the signal coming from the capacitor into the resistor divider will make the center of the resistor divider oscillate with center point equal to Vcc/2.
All AVR pins are protected by diodes going from GND to the pin and from the pin to VCC, which will clamp the voltage to within GND – 0.5V to Vcc + 0.5V, as long as you provide a series external resistor that doesn’t let go more than 1mA when clamping.
Very nice Idea and project ;) keep it up ;)
Just got one small question, could it be used to measure values below 20uH? or it be out of scale?
Make the capacitance larger which would decrease the frequency. In order to charge up the system you’ll probably need to provide more current, so try using a p type mosfet. remember U=1/2L*i^2 for an inductor.
Possibly use a frequency to voltage converter like the LM2917? Sounds inaccurate though
http://www.national.com/mpf/LM/LM2917.html
I have a challenge for you guys :):
1) Generate a sinusoidal wave, Vs peak voltage, as perfect as possible, with frequency (f) 1 to a few KHz
2) Apply that wave to an unknown capacitor (Cx) in series with a low value resistor (Rt) (allow at least a few 10ths of mA, a few 100ths is better)
3) Sample voltage at the input (sinus wave) and at the resistor, to find peak values, time-stamped; the resistor measurement is to measure current (It) and timestamps are to measure phase difference (a). Current peak will come before voltage peak.
4) Apply formulas to measure capacitor value and ESR, using complex impedance in Ohm’s Law: Z = V / I, where V = Vs + 0.j and I = It x cos(a) + It x j.sin(a); ESR = It x cos(a) – Rt (that is, real part of impedance minus Rt); capacitor reactance, Xc = It x j.sin(a) = 1 / (2 x Pi x f x Cx) => Cx = 1 / (2 x Pi x f x It x j.sin(a))
5) If successful, do the same to measure inductance
Pingback: Made my Inductor » Transportation Scholar
Dear Moser,
I have made it according to your instruction, and it is working!!
Thanks a lot!!!
hey i’ve tried making ur circuit….but the inductance and frequency is varing ,in the serial monitor……..am new with
electronics……what am i supposed to do???please guid me…..am stuck….am using the same lm339…
It’s best to test the circuit with an inductor which you know the inductance. Have you tried this? Are you using electrolytic capacitors on the resonating part?
yes i am using electrolytic cap…..
Thanks for the article. One question, though: The datasheet of LM339 says that the input voltage range in either differential input ports (+ and -) must be -0.3…36V. However, to me it seems that the LC oscillations can cause the + input to go below -0.3V?
You’re right, but i didn’t have problems and no one complained which is interesting. Put two resistors (1k should do) in series on the + differential input. In between those two resistors put a diode with the cathode connected to ground (striped end). Use a 1N4148 but that would let it go down to -.6v, a schottky diode would keep it closer to -.3
Pingback: Tube_Exploratie3 | TIII
Can you measure inductance using a 555 timer in place of the LM339? It seems reasonable as the 555 would trigger high/low on the 1/3 and 2/3 voltage, measuring the same length of time. I tried wiring something up, but didn’t manage to get it to work.
Surprisingly i’ve never really done anything with the 555. If you can get the 555 to act as a comparator then yeah you can use it. Make it simple and just use a comparator chip since it will activate as soon as the signal goes onto the positive voltage ranges.
Did you choose the LM339 for some particular (functional) reasons, or if I want to build a (phisically) small circuit, do you think that also a LM311 can do the job?
LM311 will do the job just fine. Just make sure that you’re operating within spec of the LM311!
Duplicating my post from Adafruit here just in case…
Looking for a little guidance…
My girl took over a drive thru for her coffee shop. They have an induction loop detection system installed, but pulled out the controller box when they left.
I’d love to hook it up to ring the old gas station bell I bought her, it just has a normally open switch to kick it. Already set up a relay for that part.
So I built your LM339 circuit and have it all hooked up to an arduino… But i know I’m missing something from here.Probably a lot of somethings. Any guesses to whatto do next? :?
Any help/links/direction/divine intervention would be appreciated.
That is awesome! One of my dreams in life is to own or partially own a coffee shop – even if I don’t make a profit! Anyway were you able to measure an inductor with a known inductance? It might not work for the drive through inductor and my thoughts are that: There isn’t enough current going through the drive through inductor to make a magnetic field large enough to reach out to the car’s metal. If it can’t reach out that far, then the car’s metal won’t affect the inductance. I’m not sure, there are lots of ways to measure a ‘change’ in inductance though that aren’t too difficult. You could stimulate the circuit more aggresively with a mosfet and use a larger (non electrolytic) capacitor – and then you’d probably have to add some protection circuitry to cut off the tips of the resonating sinusoid (you don’t care about those anyway, just 0volt intersection). If this is gibberish then look around for one of the drive through sensor boxes :P
http://vehicle-counters.com/TC-BL44.htm
you could also get a weather proof ultrasonic sensor and have it pointed at where the car will be.
http://www.adafruit.com/products/1137
sparkfun sells one too
I actually have a zero cross intersection detection circuit for the home roaster I’m going to run off an Arduino… Might just be the thing. I’m setting up my oscope this weekend to take some tests and see what I get. Funny you mentioned the prox sensor… I was thinking about that earlier this morning.
I’ll try the MOSFET amp and the ZCD and see if that works. If you can recommend a good amp circuit link, that’d help. Here’s the ZCD I’m going to use:
http://goo.gl/oYkBV
Cheers!
I tried with two 0.1uF caps and with a 1mH inductance and it worked like a charm :) Thanks for sharing!
A happy reader :)
Actually I realized a single power supply and it still works. I’m using a lm324 so in the negative lobe the opamp ouputs zero and in the positive it outputs 5v.
Pingback: Kaip pasidaryti henriometrą | Darau, blė
Hi I improved the measurement of the resonance frequency, I hope you like it!
http://codinglab.blogspot.be/
Thanks for your great article!
Very well written article! I tried it with an lm471 I had lying around and it won’t output anything until I disconnect or reconnect the 3 volt as batteries- it outputs something different each time though depending on how fast I disconnect and reconnect?? Any ideas?
Is it possible to measure capacitance/capacitor (changing code) with this circuit?
Yeah but there are much easier ways how to do this. Modify the code from my post: “measuring resistance with a digital i/o…” also most multi meters can measure capacitance.
Yes. That is simple and good for resistance or capacitance :).
I made this inductance meter earlier, and works well. I think this can also measure capacitance without changing any hardware design. Can you please take a look here – http://www.microsyl.com/index.php/2010/03/29/inductor-capacitor-meter-lcmeter/ ?
Best regards.
Sorry, my mistake. Tested, and this does not work for capacitance. Anyway measuring capacitance is not much important.
Pingback: Naminis Arduino shield’as | Darau, blė