- Using FreqCounter library. It can measure frequencies up to several MHz, and is very precise. However, measurement is fixed to digital pin 5. Also it may affect Arduino PWM outputs, increasing their duty cycles. In case you don't use PWM and you need to measure frequency of just one signal, FreqCounter is an excellent choice
- Using pulseIn() function. The technique I'm suggesting below is free from FreqCounter limitations, so you can use it on any pin. However, it's minimal wave period is 10 uS, with corresponding maximum measurable frequency of 100 kHz
Here you can find documentation for pulseIn() function.
Most people usually take only one measurement with pulseIn() function. In many cases, frequency is not very stable, so we need to calculate an average value over time. Something like 1024 samples will be enough, however, for better results, you may increase the value - up to 32767 samples (you can, certainly, choose any value, but, (for HH100D), there's almost no difference in measured signal frequency for 4096 and 32767 samples. However, 32767-sample measurement takes up to 5 seconds - depending on frequency, of course.)
We will suggest that we have a square wave with 50% duty cycle, and measure the length of the pulse. Then we'll multiply that value for 2 to obtain signal period: (the distance between red lines on the image):
We wait for the pulse to occur in 250 mS. If you are using very slow signals, increase this value as you need. (line 4)
I use value of 500 000 uS instead of 1 000 000 uS (= 1 second), because I want to get signal's period (T), not pulse length(tpulse).
With duty cycle of 50%, so T = 2*tpulse.
Do not forget to configure your pin as input!