Arduino Frequency Counter

Introduction: Arduino Frequency Counter

About: iam a B.E Electronics and Communication Engineer. I have great interest on electronics.I love my college life.Even though there are many sadness in my life.I find joy in making instructables.

To find out the frequency of any signal we need to use CRO. We can also use frequency meter.But both of them are costly.Using Arduino Frequency Counter we can easily measure the frequency of various signals.This Circuit can be easily made with very less cost when compare to CRO and Frequency Meter.

Step 1: Components Required

  • Arduino Uno.
  • 3 Pin LCD Interface Board.
  • 16 x 2 LCD
  • IC 74LS14

I have used 3 Pin LCD interface Board to Connect LCD easily with 3Pins. If you don't have 3 pin interface board you can easily make it.Click on the bellow link to know how to make 3 pin interface board.

Interfacing LCD With Arduino Using Only 3 Pins

Step 2: Operation of IC 74LS14

IC74LS14 is a schmitt trigger.In order to convert any signal into square wave schmitt trigger is used.

Advantages of Using this IC 74LS14

  • It is a 5volt IC
  • It's Output current is below 40mA
  • It converts any signal into square wave
  • The time period of output square wave is same as input signal,So the frequency of input signal to be measured does not change when converting it to square wave.
  • Arduino Digital and Analog Pins only withstand 5Volt and 40mA current.Any thing out of this Range damage your Arduino. Since ic 74LS14 uses 5volt and gives the output current less than 40mA.It is safe to use this IC74LS14.

Step 3: Schematic Diagram

You can use any Oscillator circuit to measure frequency.I have used CD4047 which is a oscillator used for demo in this Schematic.

Step 4: Formula Used to Calculate Frequency

In CRO we use f=1/T formula to calculate frequency.Here also the same concept is used to calculate frequency

where

T is the time period of one cycle of signal in microseconds(us)

In the program of Arduino Frequency counter we used f=1000000/pulseTotal.

Where

pulse Total is nothing but, a Time period of Signal(T).

microseconds(us)=10^-6

See below how the formula is given asf=1000000/pulseTotal for Arduino Frequency Counter

f=1/T in microseconds,so the formula is given as f=1/Tx(us)

microseconds(us)=10^-6,So the formula is written as f=1/Tx10^-6.

If we Take micro seconds(us) to numerator it becomes 10^6.It is equal to the value that is 1000000

So finally the formula for arduino frequency counter is given as f=1000000/T.

since we are converting signals into square wave.The square wave contains Ton and Toff period,

So total time period of one cycle of signal is given as

pulseTotal=Ton+Toff

The below Code is used to calculate Ton and Toff.Ton=pulseHigh.Toff=pulseLow

pulseHigh = pulseIn(pulsePin, HIGH);

pulseLow = pulseIn(pulsePin, LOW);

Step 5: Program Code(if You Use 3 Pin Interface Board for LCD)

#include <Wire.h>

#include <LiquidCrystal_SR.h>

LiquidCrystal_SR lcd(6, 5, 9);

const int pulsePin = 12; // Input signal connected to Pin 12 of Arduino

int pulseHigh; // Integer variable to capture High time of the incoming pulse

int pulseLow; // Integer variable to capture Low time of the incoming pulse

float pulseTotal; // Float variable to capture Total time of the incoming pulse

float frequency; // Calculated Frequency

void setup() {

pinMode(pulsePin, INPUT);

lcd.begin(16, 2);

lcd.setCursor(0, 0);

lcd.print("Instructables");

lcd.setCursor(0, 1);

lcd.print(" Freq Counter ");

delay(5000);

}

void loop() {

lcd.setCursor(0, 0);

lcd.print("Frequency is ");

lcd.setCursor(0, 1);

lcd.print(" ");

pulseHigh = pulseIn(pulsePin, HIGH);

pulseLow = pulseIn(pulsePin, LOW);

pulseTotal = pulseHigh + pulseLow; // Time period of the pulse in microseconds

frequency = 1000000 / pulseTotal; // Frequency in Hertz (Hz)

lcd.setCursor(0, 1);

lcd.print(frequency);

lcd.print(" Hz");

delay(500);

}

Step 6: Program Code (if You Use LCD Without 3Pin Interface Board)

#include <LiquidCrystal.h>

LiquidCrystal lcd(11, 7, 5, 4, 3, 2);

const int pulsePin = 12; // Input signal connected to Pin 12 of Arduino

int pulseHigh; // Integer variable to capture High time of the incoming pulse

int pulseLow; // Integer variable to capture Low time of the incoming pulse

float pulseTotal; // Float variable to capture Total time of the incoming pulse

float frequency; // Calculated Frequency

void setup() {

pinMode(pulsePin, INPUT);

lcd.begin(16, 2);

lcd.setCursor(0, 0);

lcd.print("Instructables");

lcd.setCursor(0, 1);

lcd.print(" Freq Counter ");

delay(5000);

}

void loop() {

lcd.setCursor(0, 0);

lcd.print("Frequency is ");

lcd.setCursor(0, 1);

lcd.print(" ");

pulseHigh = pulseIn(pulsePin, HIGH);
pulseLow = pulseIn(pulsePin, LOW);

pulseTotal = pulseHigh + pulseLow; // Time period of the pulse in microseconds
frequency = 1000000/ pulseTotal; // Frequency in Hertz (Hz)

lcd.setCursor(0, 1);
lcd.print(frequency);

lcd.print(" Hz");

delay(500);

}

Step 7: Video

Share

    Recommendations

    • Metalworking Contest

      Metalworking Contest
    • Creative Misuse Contest

      Creative Misuse Contest
    • Fix It! Contest

      Fix It! Contest

    14 Discussions

    Hi

    In the code you update the text "Frequency is" in void loop.

    If it was placed at the end of the code in void setup it would still be displayed on the LCD, with the advantage of allow the arduino to spend more time polling the input pin.

    0
    None
    LarsT7

    8 months ago

    What is the accuracy of this counter .... if it differs dependent of the frequency, what is the accuracy around 60 Hz ??

    0
    None
    kwyke

    9 months ago

    Hi

    What are the value of the capacitor and pot-meter in the demo frequency conter?

    0
    None
    EmreM2

    10 months ago

    hello;

    I get some error while loading code.Please help. Thanks

    Error message;

    Arduino:1.8.1 (Windows 7), Kart:"Arduino/Genuino Uno"

    C:\Program Files (x86)\Arduino\libraries\LiquidCrystal\I2CIO.cpp:35:26: fatal error: ../Wire/Wire.h: No such file or directory

    #include <../Wire/Wire.h>

    ^

    compilation terminated.

    exit status 1

    Error compiling for board Arduino/Genuino Uno.

    This report would have more information with

    "Show verbose output during compilation"

    option enabled in File -> Preferences.

    1 reply

    You need to install old IDE version of arduino software.That is 1.0.6.Don't go to latest version of IDE.The wire.h command is available only in older versions like 1.0.6.Install the older version and try uploading the code.You will get that right.

    0
    None
    vilif1

    1 year ago

    is there a way to use this as a BPM counter ?

    1 reply
    0
    None
    n7rgw

    1 year ago

    I found an issue with the statement: frequency = 1000000/ pulseTotal; // Frequency in Hertz (Hz)

    If pulseTotal =0 then you divide by 0 which is a no-no.

    I added this line of code just before the above listed line of code: if (pulseTotal<=0) pulseTotal=1000000;

    Thus, you can't read lower than 1 Hz.

    2 replies

    You can read lower that 1 Hz. You are using floats in this example which can give you a fraction of a Hz. This is less than 1 but still greater than 0. The frequency .01 Hz has a period of 100 seconds.

    In my IF statement, I increased the value: if (pulseTotal<=0) pulseTotal=100000000;

    The whole purpose for the IF statement is to avoid a divide by 0. This will give a reading of 0.01 Hz if it is open instead of inf. I could increase this number if you were really trying to read less than 0.01 Hz. Other than that it works great.

    I have another issue related to this. If I change my display from a parallel to an I2D display, I can't seem to get the display to work. Many of the LiquidCrystal_I2D.h files are not compatible and I can't get the code to compile. If I do get the code to compile, nothing seems to come to the display. Do you happen to have any working code for the Frequency Counter using an LCD that looks like attached file? Thanks

    FE9KIYSIDR7WXWO.MEDIUM.jpg

    great effort, kumar

    i wonder, if i can use 74HC14 IC instesd of your 74LS14 IC as i didn't find it in my country??

    1 reply

    Yes you can use 74HC14 IC.The HC is not important.Only the IC number is important