Thursday, May 31, 2018

Arduino frequency meter

In this project i used arduino for frequency counting.
The testing signal first should connect to a "schmitt trigger" to convert that to a square wave with constant amplitude about 5v, then the output of schmitt trigger connected to pin4 of arduino board to calculating the frequency.
If your signal is square wave with amplitude not more than 5v and without noise, so you don't need to use schmitt trigger and you can connect the signal directly to pin4 of arduino.

Arduino frequency meter


Frequency calculating process is very simple by measuring High time, Low time and period time (High time+Low time), then used frequency formula which is (1 second / period time)

Arduino frequency meter
I test this project with function generator and the frequency reading was accurate within frequency range of 31Hz to 100KHz


Parts list:
Arduino board 
LCD display 16X2
Breadboard 
Connecting wires
Schmitt trigger IC 74HC14
Potentiometer 10K
Resistor 220 ohm

In following video i don't use schmitt trigger because my input signal's amplitude lower than 5v and without noise.




CODE:

#include <LiquidCrystal.h>

LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

int Htime;              //integer for storing high time
int Ltime;                //integer for storing low time
float Ttime;            // integer for storing total time of a cycle
float frequency;        //storing frequency

void setup()
{
    pinMode(4,INPUT);
    lcd.begin(16, 2);
}
void loop()
{
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Frequency = ");

    Htime=pulseIn(4,HIGH);      //read high time
    Ltime=pulseIn(4,LOW);        //read low time
   
    Ttime = Htime+Ltime;

    frequency=1000000/Ttime;    //getting frequency with Ttime is in Micro seconds
    lcd.setCursor(0,1);
    lcd.print(frequency);
    lcd.print(" Hz");
    delay(500);
}