Arduino based inductance meter - explanation?

I am following this: How to make a inductance meter using arduino

Using this code based on the authors code:

#include <Wire.h>

//13 is the input to the circuit (connects to 150ohm resistor), 11 is the comparator/op-amp output.
double frequency, capacitance, inductance;
uint32_t nPulse = 0;
void setup()
{
  Serial.begin(115200);
  pinMode(11, INPUT);
  pinMode(12, OUTPUT);
  delay(200);
}
void loop()
{
  digitalWrite(12, HIGH);
  delay(100);//give some time to charge inductor.
  digitalWrite(12,LOW);
  //delayMicroseconds(100); //make sure resination is measured
  nPulse = pulseIn(11,HIGH,5000);//returns 0 if timeout
  if(nPulse > 0){ //if a timeout did not occur and it took a reading:
    
    
  // #error insert your used capacitance value here. Currently using 2uF. Delete this line after that
  capacitance = 10.0; // - insert value here
 
 
  frequency = 1/(2*(float)nPulse);
  inductance = 1/(capacitance*frequency*frequency*4*3.14159*3.14159);//one of my profs told me just do squares like this

  //Serial print
  Serial.print("High for uS:");
  Serial.print( nPulse );
  Serial.print("\tfrequency kHz:");
  Serial.print( frequency * 1000);
  Serial.print("\tinductance uH:");
  Serial.println( inductance );
  delay(500);
        
  }
}

The circuit that the author specifies absolutely does not work - there is no response to the call to pulseIn(…)

However if a remove the connection from the bottom of the tank circuit to GND then there is a response to the call to pulseIn(…)

If I connect a 150R resistor between the tank circuit and GND then there is intermittent responses to pulseIn(…).

If I connect a 10k resistor between the tank circuit and GND then there is always a response to to pulseIn(…) but the pulse period, and therefore the calculated capacitance value, is unstable and varies widely between 0.01uH to 3uH (roughly) for a 10uH inductor.

If I connect a 1M resistor between the tank circuit and GND then there is always a response to to pulseIn(…) and the pulse period, and therefore the calculated capacitance value, is fairly stable and varies between 2uH to 10uH (roughly) for a 10uH inductor.

What is going on here?

The circuit that the author specifies absolutely does not work

It absolutely does. I think you have wired it up incorrectly, or configured it wrong. What technical reason do you have in saying it can not work?

You talk about things that are not on the diagram so we need a compleat schematic of what YOU have made, not what your design was based on. And also we need to know what you want to achieve in your project.

What capacitors do you use? You set in your code you use a 10 µF capacitor. It specifically specifies non-polarised (and indeed you need this as the voltage goes negative), and while 10 µF ceramics do exist they’re fairly uncommon, while film caps are quite expensive for those larger values. This makes me suspect this is a more common polarised electrolytic cap.

Grumpy_Mike:
It absolutely does. I think you have wired it up incorrectly, or configured it wrong. What technical reason do you have in saying it can not work?

You talk about things that are not on the diagram so we need a compleat schematic of what YOU have made, not what your design was based on. And also we need to know what you want to achieve in your project.

It does not work for me because pulseIn(....) fails to detect a pulse from the ringing. Advice from another electronics forum suggests that the ringing decays too fast for the arduino to detect any pulse through the comparator.
My multimeter also fails to detect any ringing from the circuit for the same reason, so the electronics expert on the other forum was saying.

What does work with this circuit is if you remove the link from tank circuit to GND or replace it with 1M resistor.

Then pulseIn(....) returns a pulse width.

With a 150R resistor from tank to GND pulseIn(....) returns a pulse width intermittently.

wvmarle:
What capacitors do you use? You set in your code you use a 10 µF capacitor. It specifically specifies non-polarised (and indeed you need this as the voltage goes negative), and while 10 µF ceramics do exist they're fairly uncommon, while film caps are quite expensive for those larger values. This makes me suspect this is a more common polarised electrolytic cap.

I made a non-polar cap by puting to electrolytics - to -.

This circuit is still a pain.

I created one with LM393 on a mega shield on a little bread board thing - works fine.

Created the same circuit on an uno shield but soldered and it won't work with the same sketch.

Both with - to - electrolytic caps.

Check all the LM393 pins on both circuits - similar readings.

Yet one circuit works the other doesn't - don't get it.

Perhaps the circuit is just too sensitive to upsets.

Think it would be a great deal easier to just buy the damn Shortcuits kit version where all of these tuned circuit complications have been ironed out by the experts.

Hi,

Please can you post a copy of your circuit and a picture of the failing project?

What value inductance are you using to test the circuit?

Thanks… Tom… :slight_smile:


[The LCR T4 Transistor Tester ESR Meter Mega328 Transistor Tester|tester esr|esr meteresr meter tester - AliExpress](The LCR T4 Transistor Tester ESR Meter Mega328 Transistor Tester|tester esr|esr meteresr meter tester - AliExpress?

spm=2114.search0204.3.3.1a333e63eLdghg&ws_ab_test=searchweb0_0,searchweb201602_4_10152_10065_10151_10344_10068_10130_5722815_10342_10547_10343_10340_10341_10548_5722915_5722615_10696_10084_10083_10618_10139_10307_5722715_5711215_10059_308_100031_10103_10624_10623_10622_5711315_5722515_10621_10620_10814_10815,searchweb201603_2,ppcSwitch_5_ppcChannel&algo_expid=eb78d6ab-0b5e-4f56-a17e-47f73927d43c-0&algo_pvid=eb78d6ab-0b5e-4f56-a17e-47f73927d43c&transAbTest=ae803_1&priceBeautifyAB=0)

Yet one circuit works the other doesn't - don't get it.

Many circuits are sensitive to the way you lay them out. A bad layout can reduce the performance of a circuit and even prevent it from working.

There is a lot more to electronics than just throwing components together, although you can getaway with doing that for simple low frequency circuits.

As the complexity and frequency of a circuit increases it becomes increasingly sensitive to layout. Digital circuits are much less sensitive to this that analogue circuits, but a switch mode power supply is one example of a circuit that is very sensitive to layout.

This is why it is difficult to scale up a circuit. We often get people wanting to control say 1000+ LEDs and are supprised when it doesn’t work.

The problems with this comparator circuit are the link from the tank circuit to ground.

Under no circumstances have I been able to get the code to work so long as there is a link from tank to GND. It either needs to be left out or replaced with a high value resistor - 1M worked for me.

And the other problem appears to be that comparator pullup resistor.
The author used 330 but I could not get the code to work with that value resistor.
Nor would it work with 1.5k as the pullup resistor.
A 10k pullup resistor works with my soldered circuit but only so long as measure the voltage from the Vcc pin to the out pin below it. So that suggests the pullup resistor needs to be lower but not as low as 1.5k.

Is my reasoning flawed here?

So the circuit is VERY fickle in my experience so far.

You can't assume that the authors specs will work in all circumstances, particular arduinos, particular tank capacitors, particular comparators.....

Grumpy_Mike:
Many circuits are sensitive to the way you lay them out. A bad layout can reduce the performance of a circuit and even prevent it from working.

There is a lot more to electronics than just throwing components together, although you can getaway with doing that for simple low frequency circuits.

As the complexity and frequency of a circuit increases it becomes increasingly sensitive to layout. Digital circuits are much less sensitive to this that analogue circuits, but a switch mode power supply is one example of a circuit that is very sensitive to layout.

This is why it is difficult to scale up a circuit. We often get people wanting to control say 1000+ LEDs and are supprised when it doesn’t work.

Well I guess that the issue with anything involving tuned cicruits - very difficult for novices like me to deal with without formal training and years of experience.

What is the average impedance of a multimeter in voltage mode?

Mohms isn't it?

So if I put a 1M resistor in parallel with my 10k pullup resistor then the code should work....theoretically....

So I just put a 1M resistor in parallel with my 10k pullup and the code works.
So the correct pullup resistance should be 1/(1/10000 + 1/1000000) under my circuit circumstances.
Trying 8.2k

The author used 330 but I could not get the code to work with that value resistor.
Nor would it work with 1.5k as the pullup resistor.
A 10k pullup resistor works with my soldered circuit but only so long as measure the voltage from the Vcc pin to the out pin below it. So that suggests the pullup resistor needs to be lower but not as low as 1.5k.

The value of the pull up resistor is largely irrelevant. If you are seeing variations like you said something else is wrong. Putting 1M in parallel with 10K is not going to make any difference. The fact that you say it does means something is happening that you do not know about.

Hi,

Please can you post a copy of your circuit and a picture of the failing project?
Reverse engineer your circuit.

What value inductance are you using to test the circuit?

Can you also note on the circuit, the DC voltages on each of the comparator pins, please.

Thanks.. Tom.. :)

Nup. This circuit is a bomb - to many things can go wrong with it and I am through wasting my time with it.

No good for novices.

Searching for an easier solution.

The time constant method worked OK with capacitance for me - got it working quite easily.

Not accurate but good enough to identify the magnitude of a capacitor if not its precise value.

Looks like you can do the same thing with an inductor.

TomGeorge:
Hi,

Please can you post a copy of your circuit and a picture of the failing project?
Reverse engineer your circuit.

What value inductance are you using to test the circuit?

Can you also note on the circuit, the DC voltages on each of the comparator pins, please.

Thanks.. Tom.. :)

Not going to bother mate because this circuit is just too much of a bother.

It is as inaccurate as the time constant method but the latter is far easier to implement as a circuit and nothing much can go wrong with it.

This comparator circuit is just not suitable for novices.

More suitable for a kit where all the vagaries of the circuit are ironed out with a PCB that works every time without fail once soldered up.

I made a non-polar cap by puting to electrolytics - to -.

I just think that will be a problem. While it will in effect be a non polarised capacitor, it's inductance will be horrendous, I think that is swamping out the inductance of the inductor you are trying to measure.

This circuit is a bomb

Like I said not the circuit but its implementation.

boylesg:
More suitable for a kit where all the vagaries of the circuit are ironed out with a PCB that works every time without fail once soldered up.

Where is the fun in that? :o :o :o

boylesg:
The time constant method worked OK with capacitance for me - got it working quite easily. Not accurate but good enough to identify the magnitude of a capacitor if not its precise value.

Without any special effort I got that one to about 1% accuracy, just throwing it together basically. Measuring a capacitor through its RC time constant is dead easy, really, largely as you don't try to resonate the circuit.

What frequency should your resonance be? Electrolytic caps are known to not work at high frequency (they act more like inductors than capacitors). ESR rises fast, capacitance decreases fast at 10 kHz or more. Replace it with a film cap or ceramic cap. They also react very badly to reverse voltages (your circuit produces those).