Reading distance, using esp32 and seeed 24ghz human static lite sensor

using esp32 and seeed 24ghz human static lite sensor. I want to publish the distance from the sensor to the person in the room, to my mqtt server. currently to test, I am using this code to show the distance in the serial monitor and it just stays at 0… any recommendations?

image

void loop() {

  digitalWrite(2, HIGH);

  delay(1000);

  digitalWrite(2, LOW);

  delay(1000);

  // connect to MQTT

  connectMQTT();

  // get chip MAC Address

  char macAddress[13];

  snprintf(macAddress, sizeof(macAddress), "%012llx", ESP.getEfuseMac());

  radar.recvRadarBytes();

  // get radar data as a string

  String radarData = radar.showDataString();

  if (!radarData.isEmpty()) {

    String csvData = macAddress;

    csvData += ", ";

    csvData += radarData;

    Serial.println(radar.dynamic_val, DEC);

    if (client.connected()) {

      client.publish(MQTT_PUB_TOPIC, csvData.c_str());

    }

  }

  delay(1000);

}

Hi there, and welcome here.
So what’s the scenario? , how is it connected? do you have a picture?
Have you tried it without the MQQT portion?
also if you edit your original post and use the </> above for the code , it will look better and some of the smart folks here will comment.
HTH
GL :slight_smile: PJ :v:

Have you tried the PC tool utility? Page 7
from this document.

Print out the radarData variable to see if it’s empty or if it contains any meaningful data.

Hi there,
I pretty sure the code there, does exactly that, It’s “zero” ?
I would try the Tool and see where that takes it. Also verify the connections and orientation, I see several folks have it upside down, LOL :face_with_peeking_eye:
GL :slight_smile: PJ :v:

(continued) 10 minutes later…
I had one of these NIB, popped it open and soldered the sockets to it, mounted a
Xiao ESP32C3 to it, Went to google play and down loaded the Radar app.
Super easy I turned on Bluetooth on my phone(sam10+) it scanned and found the unit.

I setup a ruler and a mini test, WOW!. I was surprised how well it worked and how accurate it became the longer I left it on.(see the pics)
They do work well, Note I have NOT updated it firmware wise. ( I see some issues with that)
I’ll use it as is, and test more moving to the PC app and see what that yields. Then to Real Code :laughing: :crossed_fingers:
I’m not sure what app is on the Xiao it’s connected to but it’s only providing power at this point , which I feel is a good starting point for anyone having one of these and struggling.


I hit connect and Instantly it was connected and reading :pinched_fingers:

With a curved top , I got the end measurements and with a flat top, It hit it Exactly at 46cm



WithOut the Top it measures the Distance to the ceiling 200+cm LOL :stuck_out_tongue_winking_eye:

HTH
GL :slight_smile: PJ :v:

Ps. You may want to edit the post Title and include the part in Question, That would really be helpful to ALL, better for you and better for searching. :+1:

does anyone know if the microwave is better than ultrasonic for measuring water levels?

Hi there,
So I added the code to the Xiao that was powering the Radar for the previous post.

In order to connect up the PC app and get it going. SoftSerial is needed for the pins 2, 3 in the sketch those are connected to the radar and did the trick,(the Radar uses the pins 3 & 2 Respectively) that and setting all the speeds (baud rate) the same, including the Radar.


You use the Bluetooth app to change the baud rate by Clicking the more button , change it from default 256000 to 115200, confirm the change and go back to PC app and Click Connect , then Start. and “Bob’s your Uncle” it works,
Notes:
You can’t have a serial monitor open on the port from the IDE or the PC app won’t connect.
you can leave the IDE open but no serial monitor OPEN, in the video I close it b4 hitting the connect and Start.
When you press reset on the Xiao, you will see the POWER ON message on the serial monitor, along with the radar , wrong baud rate data…Close the monitor and proceed.

Pretty trick Hardware SEEED I’ll be using a few of them.
here’s the code for the Xiao ESP32C3

/*
  Multiple Serial ports relay test (works and tested on Xiao ESP32C3)

  Receives from the main serial port, sends to the others.
  Receives from serial port 1, sends to the main serial (Serial 0).
*/ 

#include <SoftwareSerial.h>

#define MYPORT_TX A3
#define MYPORT_RX A2

EspSoftwareSerial::UART myPort;
void setup() {
Serial.begin(115200); // Standard hardware serial port
 while (!Serial);
  delay(2000);//relax...Get Ready for serial port
  Serial.println();
  Serial.println("Power ON \n ");  // Let's BEGIN!!
  Serial1.print("\r");

  myPort.begin(115200, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, false);
  if (!myPort) { // If the object did not initialize, then its configuration is invalid
     Serial.println("Invalid EspSoftwareSerial pin configuration, check config"); 
     while (1) { // Don't continue with invalid configuration
     delay (1000);
    }
  } 
}

void loop() {
  // read from port 1, send to port 0:
  if (myPort.available()) {
    int inByte = myPort.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    myPort.write(inByte);
  }
}

HTH
GL :slight_smile: PJ :v:

Hey thanks for the quick reply:

basically this is it (hopefully the diagram isn’t too confusing):

I can get the raw hex data from the sensor and the mac address of the esp32 to publish to the mqtt server I set up. However, I wanted to try to get a real time distance reading from the sensor to me standing in the room… right now, to test, I am using some code from an example file in the sensor library to try to print the distance in the serial monitor, but all i am getting in the output is 0 →

My sketch code (loop function):

void loop() {
  digitalWrite(2, HIGH);
  delay(1000);
  digitalWrite(2, LOW);
  delay(1000);

  // connect to MQTT
  connectMQTT();

  // get chip MAC Address
  char macAddress[13];
  snprintf(macAddress, sizeof(macAddress), "%012llx", ESP.getEfuseMac());

  radar.recvRadarBytes();

  // get radar data as a string
  String radarData = radar.showDataString();

  if (!radarData.isEmpty()) {
    String csvData = macAddress;
    csvData += ", ";
    csvData += radarData;

    if (client.connected()) {
      client.publish(MQTT_PUB_TOPIC, csvData.c_str());
    }
  }

  radar.HumanStatic_func(false);

    Serial.print("Spatial static values: ");
    Serial.println(radar.static_val);

    Serial.print("Distance to stationary object: ");
    Serial.println(radar.dis_static, DEC);

    Serial.print("Distance from the movement object: ");
    Serial.println(radar.dis_move);
    Serial.println("");

  delay(1000);
}

Serial Monitor output:

09:51:56.099 -> Spatial static values: 0
09:51:56.099 -> Distance to stationary object: 0.0000000000
09:51:56.099 -> Distance from the movement object: 0.00
09:51:56.099 ->
09:51:59.120 -> Spatial static values: 0
09:51:59.120 -> Distance to stationary object: 0.0000000000
09:51:59.120 -> Distance from the movement object: 0.00
09:51:59.120 ->
09:52:02.088 -> Spatial static values: 0
09:52:02.088 -> Distance to stationary object: 0.0000000000
09:52:02.088 -> Distance from the movement object: 0.00

mqtt server output:

6878abb3a3a0, 53 59 08 01 00 05 DF 02 05 00 0A AA 54 43
6878abb3a3a0, 53 59 08 01 00 05 5F 02 02 00 0A 27 54 43
6878abb3a3a0, 53 59 08 01 00 05 BD 02 07 02 0A 8C 54 43

I have been talking to the Seeed support team and they said this isn’t possible with the sensor that I am using?? I am very new to this so I am trying to learn more.

Hi There,
AWE’ Snap! I thought it was the other Radar,Mwave device…LOL
OK, so for that one may be the same thing. let me look it over.
It doesn’t look like it’s giving any data at all?
GL :slight_smile: PJ

Have you tried the PC app?
this is the code from the wiki, load that on the ESP and see if you can connect THROUGH the ESP32 to the radar, Like I do for the MMwave device.

/*
  Multiple Serial ports relay test (works and tested on Xiao ESP32C3)

  Receives from the main serial port, sends to the others.
  Receives from serial port 1, sends to the main serial (Serial 0).
*/ 

#include <SoftwareSerial.h>

#define MYPORT_TX 16 //A3
#define MYPORT_RX 17 //A2

EspSoftwareSerial::UART myPort;
void setup() {
Serial.begin(115200); // Standard hardware serial port
 while (!Serial);
  delay(2000);//relax...Get Ready for serial port
  Serial.println();
  Serial.println("Power ON \n ");  // Let's BEGIN!!
  Serial1.print("\r");

  myPort.begin(115200, SWSERIAL_8N1, MYPORT_RX, MYPORT_TX, false);
  if (!myPort) { // If the object did not initialize, then its configuration is invalid
     Serial.println("Invalid EspSoftwareSerial pin configuration, check config"); 
     while (1) { // Don't continue with invalid configuration
     delay (1000);
    }
  } 
}

void loop() {
  // read from port 1, send to port 0:
  if (myPort.available()) {
    int inByte = myPort.read();
    Serial.write(inByte);
  }

  // read from port 0, send to port 1:
  if (Serial.available()) {
    int inByte = Serial.read();
    myPort.write(inByte);
  }
}

Try this code You should get the Power ON message if the pins are correct , if NOT switch them, 17,16 > to 16,17 . Pay attention to the com port number, also be sure to close the Serial monitor after you see the Power ON message. Like in the Video.
if it works, then run the PC app link in wiki, See if it’s (radar) is Alive.
HTH
GL :slight_smile: PJ :v:
it should work. change the pins to 20(RX) and 21(TX) for a Xiao ESP32C3 FYI…(using GPIO numbers) And You could use Serial1 and Serial without the need for SoftSerial Also. Either way, Your call. Those are the possibilities, and the code Works! :stuck_out_tongue_winking_eye:

I am not sure if I am using the correct app but this is what I got so far,

I am not getting any reading in the app… I don’t understand why, I can get raw data readings using the showDataString() method that i made (copy of the showData method, but it returns the data as a string instead of printing to the serial monitor so that i can publish it to mqtt)

Also, the Seeed support person I’ve been talking to said “We don’t have millimeter wave radar that can detect distance for sale” ?? :sob: I am very stuck with this project, I just want to make use of the presence detection capabilities of the sensor to monitor where someone is in a room and if they are moving

update -
weirdly enough, using my code, just now i am getting sparse and random readings, similar to this, out of all the ones that just have 0 as the output:

14:07:29.663 -> 53 59 08 01 00 05 4D 06 02 00 0A 19 54 43 
14:07:29.663 -> Spatial static values: 77
14:07:29.663 -> Distance to stationary object: 3.0000000000
14:07:29.696 -> Distance from the movement object: 0.00

Hi there,
Hold the Phone… On that. Does the data sheet say it will?
You are too close to give up now, I beleive it will once you get it working.
I’m using the mmwave Xiao Unit 24Ghz , I know that works the same way.

I notice you get the Power on message, but are you disconnecting all Serial monitors (or closing them) I went so far as to select different com ports for the Dev window, where the status line is.
only the PC software is using com3? It must be that way to get anything through FYI.
Try again, close everything but the pc app, LMK
You’ll get it. It’s NOT rocket science.
HTH
GL :slight_smile: PJ :v:

ps, watch that video I made again slowly, you’ll see when I get the power ON message the data is coming the other way fast(from the radar) , Albeit at the wrong Baud rate(speed) default is 256000, You don’t appear to be receiving that, right?

Hello @1parkerj1 ,
In fact, millimeter-wave radar is unable to accurately detect distance. It may be possible to use mmwave to monitor movement or determine if there is someone within a certain range, but it cannot track the exact position of a person in a room.