• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Please help me to build a code for a HB100 radar sensor

Pavi98

New Member
Hello all,
I'm trying to build a vehicle speed detector using a HB100 radar sensor but I couldn't find a proper code for this. I tried with few codes found on the Internet but I realised that they were not giving a correct output on the serial monitor. As I am a newbie in coding please help me to build a code for this sensor......
Thank you very much.
 

Pommie

Well-Known Member
Most Helpful Member
What do you have so far? Do you have an amplifier? Do you have a schematic? Source code (sketch)?

Mike.
 

rjenkinsgb

Well-Known Member
Most Helpful Member
In essence, you need a frequency meter system.

Have a look at this:
.

The only real difference is that you need to scale the "frq" measurement result appropriately from doppler frequency to speed.

But get it working displaying the raw frequency first!
 

Pavi98

New Member
What do you have so far? Do you have an amplifier? Do you have a schematic? Source code (sketch)?

Mike.
Hello Mike,:)
Thank you very much for the reply.
I used an amplifier based on LM324 and I will add the diagram below.
amplifier.png

It is said that the above amplifier works in clockwise operation and I'm not sure whether this can be used for this purpose. Also, I found a source code on the Internet and I tested it. But it did not work properly as it shows quite high values even there is no motion for the HB100 sensor. I actually don't know how to build a source code for this purpose and what libraries I should use. All I need is to build a code to measure the velocity of a oncoming vehicle and display it on a seven segment display. I will add the code I tired with and I can't understand how to modify it for my purpose or build a new one.

Thank you very much.
 

Attachments

Pavi98

New Member
In essence, you need a frequency meter system.

Have a look at this:
.

The only real difference is that you need to scale the "frq" measurement result appropriately from doppler frequency to speed.

But get it working displaying the raw frequency first!
Hello rjenkinsgb, :)
Thank you very much for the reply.
I actually don't know how to scale the frequency measurement result to velocity. I found on the Internet that the frequency measurement divide by 19.49 will give the speed. I'm quite not sure about that if I'm going to use that equation how would I modify the code for the purpose?

Thank you very much.
 

rjenkinsgb

Well-Known Member
Most Helpful Member
how would I modify the code for the purpose?
In principle, just divide the frequency reading by whatever the scale factor is, to get the speed.
I've made "speed" a floating point value and cast "frq" to a float for the division, to ensure a floating point calculation rather than integer.

eg.

C:
#include <FreqCounter.h>

void setup() {
  Serial.begin(57600);                    // connect to the serial port
  Serial.println("Frequency Counter");
}

long int frq;
float speed;

Void loop() {

    FreqCounter::f_comp= 8;                 // Set compensation to 12
    FreqCounter::start(100);                // Start counting with gatetime of 100ms
    while (FreqCounter::f_ready == 0)       // wait until counter ready

    frq=FreqCounter::f_freq;              // read result

    speed = (float)frq / 19.49;           // Scale frequency to speed

    Serial.println(speed);                     // print result
    delay(20);
}
 

Pavi98

New Member
In principle, just divide the frequency reading by whatever the scale factor is, to get the speed.
I've made "speed" a floating point value and cast "frq" to a float for the division, to ensure a floating point calculation rather than integer.

eg.

C:
#include <FreqCounter.h>

void setup() {
  Serial.begin(57600);                    // connect to the serial port
  Serial.println("Frequency Counter");
}

long int frq;
float speed;

Void loop() {

    FreqCounter::f_comp= 8;                 // Set compensation to 12
    FreqCounter::start(100);                // Start counting with gatetime of 100ms
    while (FreqCounter::f_ready == 0)       // wait until counter ready

    frq=FreqCounter::f_freq;              // read result

    speed = (float)frq / 19.49;           // Scale frequency to speed

    Serial.println(speed);                     // print result
    delay(20);
}
I tested this code and at first it printed something not readable and I changed this value Serial.begin(57600); to 9600. then it showed 0.00 value line by line continuously and I connected my preamp output to the pin number 5 of the Arduino. then it printed 0.11 to 0.89 values continuously. There was not enough change in the values when there is a movement in front of the sensor. Unfortunately, I don't have an oscilloscope to test the signal from the sensor or the preamp. So, I measured the voltages of the output of the sensor and it shows about 1.58 V and the preamp output was about 2.67 V. Is there any problem in these voltage values or is there any way to make sure that the HB100 sensor works properly?

Thank you very much.
 

rjenkinsgb

Well-Known Member
Most Helpful Member
The signal in to the Arduino needs to be amplified to the point it's a square wave. Does that preamp do that?

Remember it is a frequency signal, not a voltage signal - a voltmeter will not show anything really useful, you need an oscilloscope to view the waveform.

And, you will need a fast movement to get a useful reading in miles per hour. Taking out the scaling part (or changing the scale multiplier to 1.0) may give you a better idea if the basic circuit is working.

You could also change the counter sample time to one second, if the frequency is very low; eg. start(1000) rather than start(100).
 

Latest threads

EE World Online Articles

Loading
Top