RadarSensor library not working

I'm working on the Human radar project from the Arduino website:
Video:

Guide:
Detect and Track Humans with mmWave Radar on an Arduino - Tutorial Australia

The problem I'm having is that I get an error message "Fatal error: RadarSensor.h: No such file or directory #include <RadarSensor.h>" when I Verify the code. I downloaded the RD03D.zip per the instructions in both the video and guide. But even when I opened the Zip file and saved the contents (RadarSensor.h and RadarSensor.cpp) to a different folder, the Arduino web page couldn't find it the RadarSensor file.

I think the directions are geared toward the IDE software that people download to their PCs's. But I'm using the Arduino website. As shown in the screenshot below, I went to the Libraries page and downladed the Radar. h library since the description seemed to be what I was looking for. But the Verify process still comes up with an error when it comes to the "RadarSensor.h" line of code.

#include <radar.h>
#include <RadarSensor.h>

RadarSensor radar (2,3); // RS, TX pin to sensor TX, RX pins

void setup() {
  Serial.begin (115200);
  radar.begin (256000);
  Serial.println ("Radar Sensor Started");
}

void loop() {
  if (radar.update()) {

    RadarTarget tgt = radar.getTarget();
    Serial.print ("X (mm): "); Serial.println (tgt.x);
    Serial.print ("Y (mm): "); Serial.println (tgt.y);
    Serial.print ("Distance (mm): "); Serial.println (tgt.distance);
    Serial.print ("Angle (degrees): "); Serial.println (tgt.angle);
    Serial.print ("Speed (cm/s): "); Serial.println (tgt.speed);
    Serial.println ("-------------------------");
    delay (100);
  }
    
}

I just checked and the library I downloaded is for a different sensor than the one I have, so I have to keep looking.

Since the library is not really in a good library format, what you can do is add them directly to your project.

Download the RD03D zip file, get the two files from it and add them to you sketch directory.

Then in the code, instead of

#include <RadarSensor.h>

do

#include "RadarSensor.h" // notice the "" instead of <>

This will instruct the compile chain to look for the file in your local directory first rather than standard library locations.

I wasn't able to download either of the two files: RadarSensor.cpp & RadarSensor.h. The computer displays the message "0% downloaded" and never changes.

Download the RD03D zip file instead, following the instructions on the instruction guide web page.

Unzip it to get the individual files.

I'm using the Arduino Cloud page, not the IDE.

First I tried to download the individual files to the main Sketches directory. That didn't work. Then I discovered I could go into the sketch itself and add the individual files. I think this is what @J-M-L and you are referring to.

I entered #include "RadarSensor.h" like @J-M-L recommended and that worked. Yay!

I was just showing off the radar shown by the Processing IDE. Oh s


So cool!

Well I was thinking you were using the standard IDE.

Glad you got it to work!

I am trying the same code / library but it’s not working, I don’t have any compilation errors but the radar.update is failing. The only thing I changed was the RX/TX pin numbers. I also only connected the Tx from RD-03D to RX of the Nano.

#include <RadarSensor.h>

RadarSensor radar(0,1); // RX, TX pins to sensor TX, RX pins

void setup() {
  Serial.begin(115200);
  radar.begin(256000);
  Serial.println("Radar Sensor Started");
}

void loop() {

  if(radar.update()) {
    Serial.println("test2");
    RadarTarget tgt = radar.getTarget();
    Serial.print("X (mm): "); Serial.println(tgt.x);
    Serial.print("Y (mm): "); Serial.println(tgt.y);
    Serial.print("Distance (mm): "); Serial.println(tgt.distance);
    Serial.print("Angle (degrees): "); Serial.println(tgt.angle);
    Serial.print("Speed (cm/s): "); Serial.println(tgt.speed);
    Serial.println("-------------------------");
    delay(100);
    }
}


what arduino do you have ?

Serial might be using pins 0 and 1...

That was your mistake

On the Nano pins 0 and 1 are used by the hardware Serial interface and it will interfere with the library

Hi,

It’s a Nano

OK so you have a conflict as @UKHeliBob and myself have said.

The Nano has only one UART, which you takeover when you do

  Serial.begin(115200);

and this UART is also connected to pins 0 and 1, which you try to use at the same time with

RadarSensor radar(0,1); // RX, TX pins to sensor TX, RX pins
radar.begin(256000);

âžś get rid of all the Serial stuff

Think I understand, so it looks like trying to get data from the Rd-03d and output it to PC using “serial monitor” in the arduino IDE whilst using a nano isn’t possible? is your suggestion get an Uno?

You could use any pins other than 0 and 1 to communicate with the sensor which leaves pins 0 and 1 to communicate with the Serial monitor.

Getting a Uno will do you no good as it is basically the same as the Nano

Incidentally, this line

radar.begin (256000);

seems to set a very high baud rate for a software serial interface

indeed - I just looked at the library and they have an instance variable that is

    SoftwareSerial radarSerial;

and the .cpp does

#include "RadarSensor.h"

RadarSensor::RadarSensor(uint8_t rxPin, uint8_t txPin)
  : radarSerial(rxPin, txPin)
{}

void RadarSensor::begin(unsigned long baud) {
  radarSerial.begin(baud);
}

so indeed it's instantiating SoftwareSerial for the radar communication - which makes your comment

totally right indeed.

OK, I have changed the code and attached the RD-03D TX pin to D2 of the nano and still not getting anything, BTW Isn’t 256000 the default comms speed the the RD-03D outputs? I did try lowered it to 115200 and I still didn’t get anything.

#include <RadarSensor.h>

RadarSensor radar(2,3); // RX, TX pins to sensor TX, RX pins

void setup() {
  pinMode(2,INPUT);
  Serial.begin(115200);
  radar.begin(256000);
  Serial.println("Radar Sensor Started");
}

void loop() {
  if(radar.update()) {

    RadarTarget tgt = radar.getTarget();
    Serial.print("X (mm): "); Serial.println(tgt.x);
    Serial.print("Y (mm): "); Serial.println(tgt.y);
    Serial.print("Distance (mm): "); Serial.println(tgt.distance);
    Serial.print("Angle (degrees): "); Serial.println(tgt.angle);
    Serial.print("Speed (cm/s): "); Serial.println(tgt.speed);
    Serial.println("-------------------------");
    delay(100);
    }
}

I always shake my head in wonder when library writers do things like that. Much better to have the constructor accept a Stream class object (C++ reference or pointer) that's set up in the user code. That way it could be used with SoftwareSerial or a hardware UART. That's especially useful for processors with multiple hardware UARTs.

agreed - esp. when the default baud rate for this sensor is 256000 bps...

SoftwareSerial will choke on that speed, all the more if Serial printing is also happening at the same time...

both pins needs to be attached probably and you need GND too. Also looking at the doc, it seems to be a 3.3V sensor. Connecting it directly to a Nano's pin is not a great idea...

Hi,

In the video about this (the one I was following) it did say do not connecting both pins as you rightly point out it’s 3.3v and in the video he does says not to connect (Arudino Tx - RD-03D RX) and I haven’t, however I should (in my mind be able to receive data on Arduino Rx. I have checked the RD-03D Tx and there is data on that line, it’s not showing it on the Arduino.

With reduced noise margin as the source is 3.3V logic.