Home / Home made Projects / Arduino Projects / Arduino based Digital frequency counter

Arduino based Digital frequency counter

In this article we will discuss the construction of Arduino based digital frequency counter.  The code which is needed for this project is also presented. Simulation results are taken for different frequency ranges. Finally results are cross checked by connecting oscilloscope with the sources.

Introduction 

Since after the introduction of inverters and high frequency converters, the application of high frequency devices has been increased. Due to the increase in application of such components, it is the need of time to construct frequency counters. Frequency counters though already available in market, however they are costly and sometimes not accurate. So in this article we will try to construct a digital frequency counter using only a single component called Arduino.

Arduino as Digital frequency counter

Now days Arduino is getting more and more attention in the field of controllers because of its versatile features and rich library functions. It is user robust, fast and at the same time user friendly. It has the provision of measuring voltage. However it cannot measure frequency directly. To enable Arduino to measure frequency, it must be programmed accordingly with the use of some additional components in some cases. Interrupt is one of the powerful features of Arduino which can be used to accomplish this task.  The frequency of low voltage and low current system can be measured directly however if the system current or voltage is very high, CTs (Current transformer) and PTs (Potential Transformer) can used as additional components to bring current and voltage to lower level.

Schematic:

Following figure shows the digital frequency counter using arduino. A source of unknown frequency is supplying power to load. A connection is given to the Pin 2(PD2) and 3 (PD3) of Arduino to measure frequency. To show the measured value by Arduino, a 16bit LCD is interfaced with Arduino. The connections are shown in the Schematic diagram. For verification, Oscilloscope is also connected to verify the reading of frequency counter.  Make sure that Power supply and ground is connected to Arduino if hardware model is to be developed.

Schematic of digital frequency counter

Results

Initially an 50V of unknown frequency is applied to the system. The response of the digital frequency counter is shown in the figure.

Results of digital frequency counter 1

The value shown by the digital frequency meter is shown which is 50Hz. It can be verified by two ways. Below the source, different specifications are shown. Frequency is specially been circled. Also the value can be verified by using oscilloscope.image006From the above figure we can see that total time period is 20ms.

Time period = 20ms

Frequency = 1/Time period = 1/20m = 50 Hz

So from the oscilloscope it is also verified that the value shown by digital frequency counter is correct.

Now we change the frequency to 60Hz.

Results of digital frequency counter 2

As shown by the Digital frequency counter, the frequency is 60Hz which is confirmed by value shown below the source. (Encircled).

Code

The following code should be embedded in Arduino

Syntax Comments
unsigned int lastmillis=0; // initializing variables
unsigned int count=0;
double frequency=0;
double a=0;
#include <LiquidCrystal.h>  //header file for LCD infront of liquid crystal.h
LiquidCrystal lcd(12, 11, 7, 6, 5, 4); //lcd being operated in 4 bit mode
void setup() 
   Serial.begin(9600);                           //INTIALISING THE SERIAL COMMUNICATION
  lcd.begin(16,2);                             //initialising 16×2 LCD
  attachInterrupt(1,RisingInt,RISING);         //INITIALISING THE INTERRUPT 0
}
void loop() // setting infinite loop
{
    lcd.setCursor(0,0); // putting cursor in row 0 and column 0 position
    lcd.print(“Frequency= “);
  if( (millis()) – (lastmillis) >= (1000)) //After every1 second
  {
     detachInterrupt(1);           //SUSPENDING THE INTERRUPT
     frequency=count;           //CALCULATING THE FREQUENCY
     lcd.setCursor(0,1); // setting cursor to row 0 and column 1 position
     lcd.print(frequency); // printing the value stored in variable “frequency” on row 1 column 1 position.
     lcd.print(“Hz”); // displaying unit “Hz” on LCD
     lastmillis=millis(); //Keeping the record of previous milliseconds
     count=0;
     attachInterrupt(1,RisingInt,RISING);
}   }
void RisingInt()     //INTERRUPT SERVICE ROTINE FOR RISING EDGE
{
  ++count;       //Counting the cycles in one second
}

Future Extension.

This project can be further extended to measure frequency of high voltages and currents which can not be measured directly. Current and Voltage transformers must be used to accomplish the task. Also it can be combined with other small projects like measuring current and voltage to make Arduino based Digital multimeter. Furthermore, same project can be extended to measure frequency and duty cycle of PWM waves which is already explained on our site How to measure frequency and duty cycle of PWM waves.

About Syed Noman ud din

Syed Noman ud din is an Electrical Engineer and working in Industry from last 3 years. He writes technical articles for electrical and electronic engineers. He has also published several research publications in renowned international journals.

Check Also

Arduino based energy monitor with Emonlib library

In this article we will discuss the design of Arduino based energy monitor. How to …

Leave a Reply

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

*