Will it work?

I have made up a circuit that is supposed to be a basic inductance meter, and it was written for an ATMEGA328, but I have it hooked to an arduino mega 2650, I can't get anything close to a legit reading and just wondered if maybe it was not a compatable thing.

This is the code I am using, though I did not write it. Any advice would be lovely. :D Thankse.

``````//13 is the input to the circuit (connects to 150ohm resistor), 11 is the comparator/op-amp output.
//reibot.org for guide
double pulse,frequency,capacitance,inductance;
void setup
() {
Serial.begin(115200);
pinMode(11,INPUT);
pinMode(13,OUTPUT);
Serial.println("Why hello!");
delay(200);
}
void loop() {
digitalWrite(13,HIGH);
delay(5);
//give some time to charge inductor.
digitalWrite(13,LOW);
delayMicroseconds(500);
//make sure resination is measured
pulse = pulseIn(11,HIGH,5000);  //returns 0 if timeout
if(pulse > 0.1) {
//if a timeout did not occur and it took a reading:
capacitance = 2.E-6;
//insert capacitance here. Currently using 2uF
frequency = 1.E6 / (2*pulse);
inductance = 1. / (capacitance * frequency * frequency * 4. * 3.14159 * 3.14159);    //one of my profs told me just do squares like this
inductance *= 1E6;    //note that this is the same as saying inductance = inductance*1E6
Serial.print("High for uS:");
Serial.print(pulse);
Serial.print("\tfrequency Hz:");
Serial.print(frequency);
Serial.print("\tinductance uH:");
Serial.println(inductance);
delay(20);
}
}
``````

I think you are trying to measure how fast the charge leaks away from the inductor.

You are using pin 13 which is connected to the onboard LED. It may be that the internal circuitry is different between the two boards. (Just a wild guess)

Try using a different I/O pin - perhaps 12

...R

Excellent observation. Making the changes. I also realized I was trying to measure an inductance smaller than I should have been with the setup I have. Now I need to also figure out how to measure down to 1uH.

When you get it working please post your final version as I might make one myself.

...R

I have got it working. I was making a silly mistake. When I looked at the diagram and it said pulseIn, I assumed that meant it was the input for the Arduino, but that was actually referring to the output pin that the function pulseIn() was driving. Why I was getting a reading at all is a mystery, but now that I have that sorted I can measure inductance. I have gotten as low as 250 readings. I do not yet have something to compare it too to know how accurate it is.

Everything you need is in the link below. When I get an inductor of a known value to test with, I will let you all know how accurate it is. They say it should be within 10% I think, which is good enough for most uses unless your into radio I suppose LOL. and they say it goes down to 200uH, which I want it lower, but that will take more current than the arduino can handle, so I will have to add some transistors to power things.

kaoshavoc: Everything you need is in the link below.

...R

Well, that was embarrassing. Not sure how the link didn’t happen LOL. Here it is.

Oh, I really messed up my words in my post about what I got wrong. the pin labeled pulseIn() is actually the input. Just, yeah, sometimes when things go from my head to the keyboard, they get all jumbled. So, yeah, just do that that link says and you will be all right. I still have not modified it to measure lower inductance's. But I really want to.

Thanks, but that link is from 2011 - is that the one you intended ?

I was hoping you would just post the final working version of your own code.

...R

That is the link I intended. I was not aware that year of publication meant anything. Still works in 2015.

I will post my code later if you wish with the small modifications that were made. I really only changed how often it sampled because it was just way too much at 4, and once a second is just fine with me.

kaoshavoc: I will post my code later if you wish with the small modifications that were made. I really only changed how often it sampled because it was just way too much at 4, and once a second is just fine with me.

I did not realize that is all you had done. I'm sure the link will be fine. I will bookmark it.

Thanks

...R