Frequency is the number of complete cycles per second in alternating current direction. The standard unit of frequency is the hertz, abbreviated Hz.
Frequency Measurement is carried out by measuring the number of cycles in one second, this method requires time of one second. Other method is to measure time period of one cycle F = 1 / T.
In this example time from first rise to the second rise is measured using interrupt on Pin 2 (INT0). It is set to detect rising pulse and at every 100mSec measured frequency is displayed on serial monitor.
Circuit Diagram of Frequency measurement
It does not require any external components; you may connect pull down resistor of 100k on Pin 2 to avoid noise measurement when there is no input. Measurement is carried out on interrupt 0, Use only Pin 2 of Arduino.
Arduino Frequency Measurement Code
* Frequency Measurement Using Arduino
* Inpout is given to Pin 2
* Uses Interrupt to get pulse duration
* F = 1 / pulse duration
#define MainPeriod 100
long previousMillis = 0; // will store last time of the cycle end
volatile unsigned long duration=0; // accumulates pulse width
volatile unsigned int pulsecount=0;
volatile unsigned long previousMicros=0;
attachInterrupt(0, myinthandler, RISING);
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= MainPeriod)
previousMillis = currentMillis;
// need to bufferize to avoid glitches
unsigned long _duration = duration;
unsigned long _pulsecount = pulsecount;
duration = 0; // clear counters
pulsecount = 0;
float Freq = 1e6 / float(_duration); //Duration is in uSecond so it is 1e6 / T
Freq *= _pulsecount; // calculate F
// output time and frequency data to RS232
void myinthandler() // interrupt handler
unsigned long currentMicros = micros();
duration += currentMicros - previousMicros;
previousMicros = currentMicros;
Frequency Measurement Result
Open Serial monitor and give some frequency input to Pin2 of Arduino and Observer the result.
For testing this circuit just take Pin2 wire near AC Supply cable, it will show line frequency.