Go Down

Topic: Facing problem in interfacing HB100 doppler radar sensor with arduino (Read 206 times) previous topic - next topic

rit2019

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>

double lfrq;
long int pp;

void setup() {
Serial.begin(9600);
  FreqPeriod::begin();
  Serial.println('FreqPeriod Library Test');
}

void loop() {
  pp = FreqPeriod::getPeriod();
  if (pp) {
    Serial.print ('period: ');
    Serial.print(pp);
    Serial.print(' 1/16us / frequency: ');

  lfrq = 16000400.0 /pp;
  Serial.print(lfrq);
  Serial.print(' Hz ');
  Serial.print(lfrq/31.36);
  Serial.println( ' Mph ');
}
}

jremington

Please use code tags when posting code. For instructions, see "How to use this forum".

Please post a link to the "FreqPeriod" library, and to the HB100 data sheet.

This won't work. You need double quotes, not single quotes, around a character string.
Code: [Select]
    Serial.print(' 1/16us / frequency: ');

rit2019

#2
Aug 18, 2019, 09:03 pm Last Edit: Aug 18, 2019, 09:10 pm by rit2019 Reason: I want to add freqperiod library link
Yes double quotation is required and I have changed them accordingly.. Now the code looks like..
Code: [Select]
#include <FreqPeriod.h>

double lfrq;
long int pp;

void setup() {
Serial.begin(9600);
  FreqPeriod::begin();
  Serial.println("FreqPeriod Library Test");
}

void loop() {
  pp = FreqPeriod::getPeriod();
  if (pp) {
    Serial.print ("period: ");
    Serial.print(pp);
    Serial.print(" 1/16us / frequency: ");

  lfrq = 16000400.0 /pp;
  Serial.print(lfrq);
  Serial.print(" Hz ");
  Serial.print(lfrq/31.36);
  Serial.println( " Mph ");
}
}

Now in the serial monitor only showing 'FreqPeriod Library Test'
 this is the link forfreqperiod library

https://github.com/Jorge-Mendes/Agro-Shield/blob/master/OtherRequiredLibraries/FreqPeriod/FreqPeriod.h


jremington

That would suggest that the mysterious library is not getting whatever input it might expect.

jremington

Why do you think the "FreqPeriod" library can be used with the HB100?

It seems to be intended for a completely different sensor, and for something called "Agro-Shield".

rit2019

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?

jremington

No, because I have no idea what you want to do, or why.

For advice on how to get help from this forum, I recommend to read the "How to use this forum" psot.

rit2019

I want to measure frequency and speed at the same time which will be printed on serial monitor as it can be seen from the code.

rit2019

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
Code: [Select]
// 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
  }
}

Go Up