I want to make a radar to detect angle, speed and velocity of an object but using this amplifier circuit i am only getting a nearly value of 0.28

#include <ESP32Servo.h>
#include <arduinoFFT.h>

const int servoPin = 13;
const int trigPin  = 32;
const int echoPin  = 33;
const int buzzer   = 19;
const int ifPin    = 34;    // HB100 IF output

// Servo
Servo myServo;

// FFT parameters
#define SAMPLES 256
#define FS 1000    // sampling rate (Hz)

double vReal[SAMPLES];
double vImag[SAMPLES];

ArduinoFFT<double> FFT = ArduinoFFT<double>(vReal, vImag, SAMPLES, (double)FS);

// -------- Distance Measurement ----------
long readDistance() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);

  long duration = pulseIn(echoPin, HIGH, 20000);
  return duration * 0.034 / 2;   // cm
}

// -------- Doppler FFT -----------
double getDopplerFrequency() {

  // Sample uniformly
  for (int i = 0; i < SAMPLES; i++) {
    vReal[i] = analogRead(ifPin);
    vImag[i] = 0;
    delayMicroseconds(1000000 / FS);
  }

  FFT.windowing(FFT_WIN_TYP_HAMMING, FFT_FORWARD);
  FFT.compute(FFT_FORWARD);
  FFT.complexToMagnitude();

  double peak = FFT.majorPeak();

  // noise filtering
  if (peak < 5) peak = 0;      // ignore <5 Hz noise

  return peak;
}

// Convert Doppler frequency to speed (m/s)
double dopplerToVelocity(double fd) {
  double lambda = 0.032; // HB100 wavelength = 3.2 cm
  return (fd * lambda) / 2.0;
}

void setup() {
  Serial.begin(115200);

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(buzzer, OUTPUT);

  myServo.attach(servoPin);

  Serial.println("HB100 Radar Scanner Ready");
}

void loop() {

  // Sweep Forward
  for (int angle = 0; angle <= 180; angle++) {

    myServo.write(angle);
    delay(10);  // small movement delay

    long dist = readDistance();     // distance first
    double fd = getDopplerFrequency();
    double vel = dopplerToVelocity(fd);

    // CSV output: angle, distance(cm), velocity(m/s)
    Serial.print(angle);
    Serial.print(",");
    Serial.print(dist);
    Serial.print(",");
    Serial.println(vel, 2);

    if (dist > 0 && dist < 20) digitalWrite(buzzer, HIGH);
    else digitalWrite(buzzer, LOW);
  }

  // Sweep Backward
  for (int angle = 180; angle >= 0; angle--) {

    myServo.write(angle);
    delay(10);

    long dist = readDistance();
    double fd = getDopplerFrequency();
    double vel = dopplerToVelocity(fd);

    Serial.print(angle);
    Serial.print(",");
    Serial.print(dist);
    Serial.print(",");
    Serial.println(vel, 2);

    if (dist > 0 && dist < 20) digitalWrite(buzzer, HIGH);
    else digitalWrite(buzzer, LOW);
  }
}

angle with speed is velocity

Why not describe all the parts you have, how you put then together, and what is supposed to happen?

The schematic diagram is incomplete and meaningless as it stands.

2 Likes

Ah Sorry,I forgot to mention it.

I am using hb100 to detect velocity of the object and ultrasonic sensor for distance and servo for angle to make a radar system. As of now measurement of distance and angle can be done by the system but for velocity measurement it is showing a value approx 0.28 , so i guess there is some mistake in my pre amp circuit.

Do you know which pulse of the sensor is being returned as an echo? Some have 5 pulses per cycle.

Or in other parts of the entire circuit, which you forgot to post.

No.

How is the 10µF capacitor supposed to charge and discharge? It's supposed to create a High Pass Filter but only with a resistor to voltage reference (Gnd most of the time)

BTW, the first amp is already an HPF, why a second one ?

What is your reason for not using one of the many radar (human presence) detectors on the market?
I used one to 'see' through my wooden kitchen cabinets to 'see' me coming and turn on the lights.

The HLK-LD2451 measures distance, velocity and angle for about $14. Available on line.

Hi, @nishan_dutta
Welcome to the forum.

Can you please post a copy of your circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

I see code that is trying to run ALL the functions you want.

Did you write your code in stages?
If you did then you should have;

Code that JUST reads the Ultrasonic.
Code that JUST reads the HB100.

Prove that both those codes works and then move on.

Code that calculates your speed.

Have you done that and how?

Forget you main code for the moment and write code like above to prove you have communictions with your perepherals.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia: