MH ET LIVE HB100 Arduino Speed Detection Problem

Hello, I am doing my project to develop a speed detector for motorcycle safety. The car A in front is the motorcycle, attached with HB100 to measure the speed of the upcoming vehicle. When high speed vehicle is approaching from back, a buzzer will give warning.


https://www.google.com/search?q=mh-et+live+microwave+sensor+&sxsrf=ALeKk01gO071I9vUiUAeogn-bHVbNqFkLQ%3A1627824228330&ei=ZKAGYdjfE-WC4-EPz_S9QA&oq=mh-et+live+microwave+sensor+&gs_lcp=Cgdnd3Mtd2l6EAMyBAgjECcyBAgjECcyBAgjECcyBggAEBYQHjoHCCMQsAMQJzoHCAAQRxCwA0oECEEYAFC4CVi4CWC3CmgBcAJ4AIABc4gB5gGSAQMwLjKYAQCgAQHIAQnAAQE&sclient=gws-wiz&ved=0ahUKEwjYoYvn9Y_yAhVlwTgGHU96DwgQ4dUDCA4&uact=5

I tried the HB100 sensor in static (not moving) and car B's speed is obtained quite accurate. So I tried moving car A without any approaching vehicle, and unsurprisingly I still got frequency value.

Will this sensor actually work if both car A and B is moving? I am using formula of fd = 19.49 V. Maybe it does not work because the formula is for static target not for moving target? Or does the sensor itself is not capable in doing so. Thank you for any help.

The sensor measures absolute relative speed. If an object is getting closer at V m/s or getting further away at -V m/s the doppler shift is the same. The resulting beat frequency is the same so the radar sensor can't tell the difference and just says 'V'.

Sorry I cannot quite understand your statement. When I am moving car A away, there is nothing behind it but it still detect frequency.

Btw, I think of this formula. If fd = 19.49V is for static source (radar) and moving target, so the formula for both moving target and source is V2= (F2 - 19.59V1)/19.49. Is this correct?

Hi, I am working on developing a speed detector for road safety. I used an Arduino car kit and HB 100 MH ET Live sensor together.

When I upload the code of HB100 and the car together, the HB100 sensor cannot work. The, I tried some troubleshooting that the line pinMode(2, OUTPUT); is the cause of this. HB 100 only works if this coding line is disabled. However, if the line is disabled, my car won't move because that is the coding for the DC motor.
It is weird that one line of coding can make a sensor stopped working.
This is the compiled coding for car to move and for the sensor to work. Thank you for your help.

#include "FreqPeriod.h"

#define in1 5 //L298n Motor Driver pins.
#define in2 6
#define in3 10
#define in4 11
#define LED 13

double lfrq;
long int pp;

int command; //Int to store app command state.
int Speed = 50; // 0 - 255.
int Speedsec;
int buttonState = 0;
int lastButtonState = 0;
int Turnradius = 0; //Set the radius of a turn, 0 - 255 Note:the robot will malfunction if this is higher than int Speed.
int brakeTime = 45;
int brkonoff = 1; //1 for the electronic braking system, 0 for normal.

void setup() {
Serial.begin(9600); //Set the baud rate to your Bluetooth module.
FreqPeriod::begin();
Serial.println("FreqPeriod Library Test");

pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(in3, OUTPUT);
pinMode(in4, OUTPUT);
pinMode(LED, OUTPUT); //Set the LED pin.

}

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/19.49);
Serial.println( " km/h ");}

if (Serial.available() > 0) {
command = Serial.read();
Stop(); //Initialize with motors stoped.
switch (command) {
  case 'F':
    forward();
    break;
  case 'B':
    back();
    break;
  case 'L':
    left();
    break;
  case 'R':
    right();
    break;
  case 'G':
    forwardleft();
    break;
  case 'I':
    forwardright();
    break;
  case 'H':
    backleft();
    break;
  case 'J':
    backright();
    break;
  case '0':
    Speed = 100;
    break;
  case '1':
    Speed = 140;
    break;
  case '2':
    Speed = 153;
    break;
  case '3':
    Speed = 165;
    break;
  case '4':
    Speed = 178;
    break;
  case '5':
    Speed = 191;
    break;
  case '6':
    Speed = 204;
    break;
  case '7':
    Speed = 216;
    break;
  case '8':
    Speed = 229;
    break;
  case '9':
    Speed = 242;
    break;
  case 'q':
    Speed = 255;
    break;
}
Speedsec = Turnradius;
if (brkonoff == 1) {
  brakeOn();
} else {
  brakeOff();
}
}
}

void forward() {
analogWrite(in1, Speed);
analogWrite(in3, Speed);
}

void back() {
analogWrite(in2, Speed);
analogWrite(in4, Speed);
}

void left() {
analogWrite(in3, Speed);
analogWrite(in2, Speed);
}

void right() {
analogWrite(in4, Speed);
analogWrite(in1, Speed);
}
void forwardleft() {
analogWrite(in1, Speedsec);
analogWrite(in3, Speed);
}
void forwardright() {
analogWrite(in1, Speed);
analogWrite(in3, Speedsec);
}
void backright() {
analogWrite(in2, Speed);
analogWrite(in4, Speedsec);
}
void backleft() {
analogWrite(in2, Speedsec);
analogWrite(in4, Speed);
}

void Stop() {
analogWrite(in1, 0);
analogWrite(in2, 0);
analogWrite(in3, 0);
analogWrite(in4, 0);
}

void brakeOn() {
//Here's the future use: an electronic braking system!
// read the pushbutton input pin:
buttonState = command;
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == 'S') {
if (lastButtonState != buttonState) {
digitalWrite(in1, HIGH);
digitalWrite(in2, HIGH);
digitalWrite(in3, HIGH);
digitalWrite(in4, HIGH);
delay(brakeTime);
Stop();
}
}
// save the current state as the last state,
//for next time through the loop
lastButtonState = buttonState;
}
}
void brakeOff() {

}

Hi Amin,

welcome to the forum ! You have ask a specific question, you have posted a link to the sensor you are using and you posted the code. This is very good. There are a few tthings to learn how to use this forum.

Imagine the amout of work of a single mouse-click. one mouse-click?! No work at all! Yes you are right.

Imagine the work of:

  • moving the mouse to the right place in your posting where your code starts
  • hold down left mousebutton starting to mark your code or keeping the shift-key pressed and then repeatedly pressing-cursor down to mark all lines of your sketch
    pressing Ctrl-C

much more work compared to a single mouse-click!

You should post code by using code-tags

There is an automatic function for doing this in the Arduino-IDE
just three steps

  1. press Ctrl-T for autoformatting your code
  2. do a rightclick with the mouse and choose "copy for forum"
  3. paste clipboard into write-window of a posting

As a code-section a single-mouseclick in the upper-right corner of the code-section is enough to copy your code into the clicpboard.
In a code-section the formatting with all the indentions stays the same as in the arduino-IDE

So please click on the pencil-icon of your post to re-edit your post
delete all the lines with the code and do the three steps as described above.

best regards Stefan

i don't see the pinMode(2, OUTPUT) in the code you posed. can you post the HB 100 code that does work?

I have revised my coding and found out that the problem was the wiring on the motor driver. Thanks btw.

My guess is that the car electronics are already using Pin 2 so you can't use Pin 2 for your doppler radar sensor. You may have to change the radar library to use a different pin or modify the car hardware to not use Pin 2.

Yes indeed. Thank you for that. I have another question that I posted in another post. If you have any free time, can you please review it?

TOPIC MERGED.

Could you take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.

I suspect it is getting reflections off of something, like the floor. Maybe even moisture in the air.

If the source is moving, add the motion of the source to the measured relative motion to get the target's motion.