Frequency counter using arduino

praveen February 19, 2015 11 Comments

Frequency counter using Arduino (upto 40KHz).

Many guys here were asking for a frequency counter and at last I got enough time to make one.  This frequency counter using arduino is based on the UNO version and can count up to 40KHz. A 16×2 LCD display is used for displaying the frequency count. The circuit has minimum external components and directly counts the frequency. Any way the amplitude of the input frequency must not be greater than 5V. If you want to measure signals over than 5V, additional limiting circuits have to be added and i will show it some other time. Now just do it with 5V signals.

The frequency to be counted is connected to digital pin 12 of the arduino. pulseIn() function is used here for counting the frequency connected to pin 12. pulseIn() function counts the number of pulses (HIGH or LOW) coming to a particular pin of the arduino. The general syntax of this function is pulseIn(pin, value, time) where pin is the name of the pin, value is either HIGH or LOW and time is time for which the function to wait for a pulse. The function returns zero if there is no valid pulse with in the specified time. The pulseIn() function can count pulses with time period ranging from 10 μS to 3 minutes. Circuit diagram of the frequency counter using arduino is given below.

frequency counter using arduino

Potentimeter R1 is used to adjust the contrast of the LCD screen. Resistor R2 limits the current through the back light LED.

In the program, high time and low time of the input signal is measured using separate pulseIn() functions. Then the high and low times are added together to get the total time period of the signal. Frequency is just 1/time period in seconds. The pulseIn() function returns the time period in microseconds. Total timeperiod in microseconds first divided by 1000. Then 1000 is divided by the result to get the frequency in hertz. The program of the frequency counter using arduino is shown below.

Program.

#include <LiquidCrystal.h>
int input=12;

int high_time;
int low_time;
float time_period;
float frequency;
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
void setup()
{
pinMode(input,INPUT);
lcd.begin(16, 2);
}
void loop()
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Frequency Meter");

high_time=pulseIn(input,HIGH);
low_time=pulseIn(input,LOW);

 
time_period=high_time+low_time;
time_period=time_period/1000;
frequency=1000/time_period;
lcd.setCursor(0,1);
lcd.print(frequency);
lcd.print(" Hz");
delay(500);
}

The circuit can be powered through the 9V external power jack of the arduino. 5V DC required at some parts of the circuit can be tapped from the built in 5V regulator of the arduino itself. This is actually a simple counter circuit using arduino. We can modify this circuit for other applications like tachometer, intrusion counter etc.

Comments
  • sachin
    December 2, 2015

    Hello,
    I am doing project of remote monitoring and control of a generator. I am facing some difficulty in some part of the program. Could you please guide me? i can provide you my code and circuit simulation .

    thank you

  • absinthe
    April 23, 2015

    This is good but what about circuitry to limit the peak voltage of the input frequency and also to deal with a floating input – e.g. swinging between, say, -10v and +10v. My inclination is to use an op-amp buffer with a 3v9 zener between the output and ground (plus a load resistor, of course). It could also be used to shape sine and other non-sq waves into square waves.

    What it the lower limit at which the counter can act?

  • neckos
    April 16, 2015

    i’m trying to measure audio frequency. is this coding able to do so?

  • March 9, 2015

    Whether can I apply the sine signal to the input pin

  • March 9, 2015

    hello sir
    if I change the frequency of the input signal simultaneously whether it is showing the exact output frequency as same as input.

    send me the screenshots of this program simulation in proteus . I am not getting the output

    • March 9, 2015

      Whether can I apply the sine signal to the input pin

  • champasit
    February 23, 2015

    Dear sir
    My project have to make arduino board for check freq counter 10 – 60 MHz
    connector is BNC
    I have old freq counter, my boss want to replace it to arduino.

    Please see in the picture

    http://img.coolz-server.com/2015-02-24_09-05-06_0.976285.jpg

    http://img.coolz-server.com/img/2015-02-24/09-05-06_0.981947.jpg

    Could you advise to me

    Thank you

    • jojo
      March 11, 2015

      @champasit – Please wire up the circuit and use code we have given. We have tested this in our lab!

      • March 14, 2015

        jojo what input you r applying to the aurdino

        pulse input? ?

  • February 19, 2015

    Could you please tell what software you are using for drawing the circuits.

    • praveen
      February 22, 2015

      PCB123

Leave a Reply to champasit Cancel reply

Your email address will not be published. Required fields are marked *