Hello,
I am working on a project with a humidity sensor that provides the information via output frequency. Therefore, in order to measure it with an Arduino Nano, we are using the library "FreqMeasure.h" to save time and effort. Even though it is working perfectly, we need to explain the functionality of the code (shown below) in the report. My main doubt is: why are the count and sum variables needed? Why do we need to wait 30 cycles for count in order to measure?
Example code found in the website 'FreqMeasure Library, for Measuring Frequencies in the 0.1 to 1000 Hz range, or RPM Tachometer Applications'
#include <FreqMeasure.h>
void setup() {
Serial.begin(57600);
FreqMeasure.begin();
}
double sum=0;
int count=0;
void loop() {
if (FreqMeasure.available()) {
// average several reading together
sum = sum + FreqMeasure.read();
count = count + 1;
if (count > 30) {
float frequency = FreqMeasure.countToFrequency(sum / count);
Serial.println(frequency);
sum = 0;
count = 0;
}
}
}
Anyone please help
Thank you for your time
X