Hello experts. Please help me as I am new at this platform. I am using arduino mega whose D8 pin is connected from amplifier output of HB100 doppler sensor. I have made this amplifier as per suggested in the HB100 datasheet. I found this code from somewhere in internet. But nothing is showing up in the serial monitor. #include <FreqPeriod.h>
Actually I found it on a web page where they are using freqperiod library. Can you suggest me which library should I use in place of that and what modification should I do to the code accordingly?
This code is working for me. But the frequency range is always showing 270 to 280Hz and speed 14km/hr to 16km/hr irrespective of any movement near hb100.. what is the reason
// Below: pin number for FOUT
#define PIN_NUMBER 47
// Below: number of samples for averaging
#define AVERAGE 4
// Below: define to use serial output with python script
//#define PYTHON_OUTPUT
unsigned int doppler_div = 19;
unsigned int samples[AVERAGE];
unsigned int x;
void setup() {
Serial.begin(115200);
pinMode(PIN_NUMBER, INPUT);
}
void loop() {
noInterrupts();
pulseIn(PIN_NUMBER, HIGH);
unsigned int pulse_length = 0;
for (x = 0; x < AVERAGE; x++)
{
pulse_length = pulseIn(PIN_NUMBER, HIGH);
pulse_length += pulseIn(PIN_NUMBER, LOW);
samples[x] = pulse_length;
}
interrupts();
// Check for consistency
bool samples_ok = true;
unsigned int nbPulsesTime = samples[0];
for (x = 1; x < AVERAGE; x++)
{
nbPulsesTime += samples[x];
if ((samples[x] > samples[0] * 2) || (samples[x] < samples[0] / 2))
{
samples_ok = false;
}
}
if (samples_ok)
{
unsigned int Ttime = nbPulsesTime / AVERAGE;
unsigned int Freq = 1000000 / Ttime;
#ifdef PYTHON_OUTPUT
Serial.write(Freq/doppler_div);
#else
//Serial.print(Ttime);
Serial.print("\r\n");
Serial.print(Freq);
Serial.print("Hz : ");
Serial.print(Freq/doppler_div);
Serial.print("km/h\r\n");
#endif
}
else
{
#ifndef PYTHON_OUTPUT
Serial.print(".");
#endif
}
}