# LC Frequency Meter Not Reading or Displaying Results

**URL:** <https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339>\
**Category:** Programming\
**Created:** [April 13, 2022, 12:25am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339 "2022-04-13T00:25:06Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![necklas322](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@necklas322](https://forum.arduino.cc/u/necklas322)\
**Post date:** [April 13, 2022, 12:25am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/1 "2022-04-13T00:25:06Z")

</div>

Hi all,

Newbie programmer here. I am attempting to make an LC meter using an Arduino, and this is my first code project from scratch. I am using the I2C LCD connection, so the schematic I'm attaching does not include the button, 1k resistor, and 10k resistor. I am getting a reading of 0 Farads and 0 Henrys on my screen despite my scope verifying the input frequency from my signal generator. Not sure where I'm going wrong. Any assistance is greatly appreciated!

Reference document for more background info:

> **[Design of Lc Meter Using Arduino](https://zenodo.org/record/2598878#.YlYYOCjMK3A)**
>
> All lovers that are embedded are familiar with multimeter which is a great tool for measuring voltage, current, resistance, etc. They can be easily measured by a multimeter. But sometimes with a normal multimeter, we need to measure inductance and...

Code:

```cpp
#include <Arduino.h>
#include <wiring_private.h>
#include <math.h>
#include <Arduino.h>
#include <EEPROM.h>

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

int outputpin = 2;
int inputpin = 3;
//int Fout = 2;
int highTime2;
int lowTime2;
int highTime1;
int lowTime1;
unsigned long duration;
int period1;
int freq1;
int period2;
int freq2;
int c1 = .0000001; // reference cap value in F
int l1 = 1000; //reference ind value in L
int L;
int C;
int Henrys;
int Farads;

LiquidCrystal_I2C lcd(0x27,16,2);

void setup()
{
  Serial.begin(9600);//baud rate at which arduino communicates with Laptop/PC
 
  pinMode(2,OUTPUT);
  pinMode(3, INPUT);
  

  
   lcd.init();
  lcd.clear();         
  lcd.backlight();

  
  
   
    
  
}

void loop()
{
  digitalWrite(3, HIGH);
  highTime1=pulseIn(3, HIGH);
  lowTime1=pulseIn(3, LOW);
  period1= highTime1+lowTime1;
  freq1= 1/(2*period1);
  digitalWrite(2, HIGH);
 highTime2=pulseIn(2,HIGH); //read high time
    lowTime2=pulseIn(2,LOW); //read low time
    period2 = highTime2+lowTime2; // Period = Ton + Toff
    freq2=1/(2*period2); //getting frequency 
    //delay(1000);
   // int L = ((1/(2*3.14*freq)*(1/(2*3.14*freq))/c1; //L value measured

    L = 1/(4* 3.14 * 3.14 * freq1 * freq2 * c1);
    L = Henrys;
    C = 1/(4* 3.14 * 3.14 * freq1 * freq2 * l1);
    C = Farads;

     lcd.setCursor(0,0) ;
 lcd.print("Farads= ");
lcd.println(Farads);
Serial.print("Farads= ");
 Serial.println(Farads);

 lcd.setCursor(0,1);
 lcd.print("Henrys= ");
lcd.println(Henrys);
 Serial.print("Henrys= ");
 Serial.println(Henrys);

}

```

---

<div class="post-metadata">

**Author:** ![DaveX](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davex/32/751443_2.png) [@DaveX](https://forum.arduino.cc/u/DaveX)\
**Post date:** [April 13, 2022, 2:35am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/2 "2022-04-13T02:35:59Z")

</div>

> [@necklas322](#):
>
> ```arduino
> int period1;
> int freq1;
> int period2;
> int freq2;
> int c1 = .0000001; // reference cap value in F
> int l1 = 1000; //reference ind value in L
> int L;
> int C;
> int Henrys;
> int Farads;
> 
> ```

What values are you measuring? Are they in multiple Farads or Henrys?

Fractional Farads or Henrys will be truncated to zero when you use integer math like this:

> [@necklas322](#):
>
> ```arduino
> L = 1/(4* 3.14 * 3.14 * freq1 * freq2 * c1);
> L = Henrys;
> C = 1/(4* 3.14 * 3.14 * freq1 * freq2 * l1);
> C = Farads;
> 
> ```

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [April 13, 2022, 3:03am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/3 "2022-04-13T03:03:00Z")

</div>

Hi,  
What value inductor or capacitor are you measuring?

Tom... 😃 👍 ☕ 🇦🇺

---

<div class="post-metadata">

**Author:** ![necklas322](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@necklas322](https://forum.arduino.cc/u/necklas322)\
**Post date:** [April 13, 2022, 7:51am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/4 "2022-04-13T07:51:55Z")

</div>

I should have been more specific. I am wanting to measure the L and C values of a given signal input essentially. This is going to be part of a larger code using the stored L and C values from this to perform other calculations. Basically frequency is the product of 1/2pisqrt(LC) and the document I was reading says I can calculate the respective L and C values using the values in my circuit and in code for calculation. I hope this clarifies, thanks for the response!

---

<div class="post-metadata">

**Author:** ![necklas322](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@necklas322](https://forum.arduino.cc/u/necklas322)\
**Post date:** [April 13, 2022, 7:53am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/5 "2022-04-13T07:53:50Z")

</div>

I have a reference cap of .1 uH. My reference inductor is 10mH. I want to use these values to make a calculation of a given signal input at X frequency, which I can use to determine the L and C values of that signal which I'll need to use in a larger code for further calculation. Thanks for the response, I hope that made sense

---

<div class="post-metadata">

**Author:** ![necklas322](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@necklas322](https://forum.arduino.cc/u/necklas322)\
**Post date:** [April 13, 2022, 7:54am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/6 "2022-04-13T07:54:30Z")

</div>

And also, if not int, how would you go about storing the values?

---

<div class="post-metadata">

**Author:** ![TomGeorge](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/tomgeorge/32/215261_2.png) [@TomGeorge](https://forum.arduino.cc/u/TomGeorge)\
**Post date:** [April 13, 2022, 8:14am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/7 "2022-04-13T08:14:11Z")

</div>

Hi,  
So you basically want to find the resonant frequency of a L C circuit and then work out L and C from there.  
L and C in parallel or series?  
They will produce different responses.

I hope you realize that the project you cited, calculates C by using a known value of L and calculates L by using a known value of C.

From what I gather from your explanation of what you want to do, you do not know L or C.

So knowing the resonance formula you cited, all you will be able to measure is the product of L and C, not L and C directly.

Tom.... 😃 👍 ☕ 🇦🇺  
PS. A long long time since I've had to use that equation.  
 ![Lc_resonance](https://europe1.discourse-cdn.com/arduino/original/4X/6/1/c/61caf6bd8a260483cad17417a453c19a0ae4f021.jpeg)

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [April 13, 2022, 9:30am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/8 "2022-04-13T09:30:55Z")

</div>

> [@necklas322](#):
>
> And also, if not int, how would you go about storing the values?

You use type float for real values. int only holds integer values (the clue is in the name!)

So:

```arduino
float period1, freq1, period2, freq2;
float c1 = 0.1e-6 ; // reference cap value in F
float l1 = 1.0e3 ; //reference ind value in L
float L, C, Henrys, Farads;

```

Don't know what units you are using for l1, "in L" isn't anything I've heard of.

> [@necklas322](#):
>
> ```arduino
> L = 1/(4* 3.14 * 3.14 * freq1 * freq2 * c1);
> L = Henrys;
> C = 1/(4* 3.14 * 3.14 * freq1 * freq2 * l1);
> C = Farads;
> 
> ```

These lines calculate L and C, then throw immediate throw the results away. You seem confused about units somehow - why do you have both L and Henries? Why both C and Farads?

BTW the units henry and farad are lower case - they are not people's names, they are units like foot and metre.

---

<div class="post-metadata">

**Author:** ![necklas322](https://avatars.discourse-cdn.com/v4/letter/n/c67d28/32.png) [@necklas322](https://forum.arduino.cc/u/necklas322)\
**Post date:** [April 13, 2022, 10:02am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/9 "2022-04-13T10:02:21Z")

</div>

Thank you for your answer very helpful! I'm just using C and L to simplify calculation later in the code. How would I get the code to store the values of the L and C I am getting within the loop? I would need to use these stored values in formulas outside of loop. Thanks!

---

<div class="post-metadata">

**Author:** ![DaveX](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davex/32/751443_2.png) [@DaveX](https://forum.arduino.cc/u/DaveX)\
**Post date:** [April 13, 2022, 1:11pm UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/10 "2022-04-13T13:11:00Z")

</div>

Oh -- and the code doesn't appear to use the values of the calculations. It would just print out the initialized-to-zero and unmodified `Henrys` and `Farads`:

> [@necklas322](#):
>
> ```arduino
> int Henrys;
> int Farads;
> ...
> 
> lcd.setCursor(0,0) ;
> lcd.print("Farads= ");
> lcd.println(Farads);
> Serial.print("Farads= ");
> Serial.println(Farads);
> 
> lcd.setCursor(0,1);
> lcd.print("Henrys= ");
> lcd.println(Henrys);
> Serial.print("Henrys= ");
> Serial.println(Henrys);
> 
> ```

Maybe try something like [Arduino Project Hub](https://create.arduino.cc/projecthub/mircemk/diy-simple-autorange-capacitance-meter-10pf-10000microf-e6e797) or [Arduino Project Hub](https://create.arduino.cc/projecthub/sainisagar7294/how-to-make-inductance-meter-using-arduino-b9cb20)

---

<div class="post-metadata">

**Author:** ![MarkT](https://avatars.discourse-cdn.com/v4/letter/m/c89c15/32.png) [@MarkT](https://forum.arduino.cc/u/MarkT)\
**Post date:** [April 14, 2022, 9:52am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/11 "2022-04-14T09:52:05Z")

</div>

You've just calculated L and C, don't immediately overwrite those variables! Use them!

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [October 11, 2022, 9:52am UTC](https://forum.arduino.cc/t/lc-frequency-meter-not-reading-or-displaying-results/980339/12 "2022-10-11T09:52:19Z")

</div>

Closed on October 11, 2022, 9:52am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
