int cnt=0; int sample=90; //Sample size, should be at least 1.5 times expected frequency float t1,t2,freq; void setup() // code for counting the increasing values { Serial.begin(9600); pinMode(2,INPUT); attachInterrupt(0,count,RISING); t1=millis(); t2=0; Serial.print("Starting\n"); } void loop() { if (t2!=0) { noInterrupts(); //Disable interrupts to ensure accuracy of readings freq=sample/((t2-t1)/1000); Serial.print(cnt);Serial.print(" Freq: "); Serial.println(freq); //Treat output to your liking t1=millis(); //Reset variables t2=0; cnt=0; interrupts(); //Enable interrupts again } } void count() { cnt++; if (cnt==sample) { //signal when set number of samples have been taken t2=millis(); } }