Example Code for Arduino-Multiple Targets Detection
Last revision 2025/12/17
Detect multiple targets using the 24GHz Microwave Radar Sensor with Arduino, outputting the distance of up to 5 obstacles (maximum reflection intensity and other targets).
Hardware Preparation
- DFRduino UNO R3 (or similar) x 1
- 24GHz Microwave Radar Sensor x1
- Connectors
Software Preparation
Wiring Diagram

As the diagram shows, the pin 1 to 6 are placed from top to bottom. Pin 1 to UNO 5V, P2 to GND, pin 4 and 5 to UNO digital pin 4 and 5, Pin 6 to UNO GND.
Sample Code
* ****************************************************
* @brief 24GHz Microwave Radar Sensor
* @copyright [DFRobot](https://www.dfrobot.com), 2016
* @copyright GNU Lesser General Public License
* @author [Xiaoyu]([email protected])
* @version V1.0
* @date 2019-03-11
* GNU Lesser General Public License.
* All above must be included in any redistribution
* ****************************************************/
#include <SoftwareSerial.h>
char col;// For storing data read from serial port
unsigned char buffer_RTT[134] = {};
int YCTa = 0, YCTb = 0,YCT1 = 0,checka,checkb,Tarnum=1,TargetY1 = 0;
double Tar1a,Tar1b,Distance,Distance1,Distance2,Distance3;
SoftwareSerial mySerial(4,5);
void setup() {
mySerial.begin(57600);
Serial.begin(115200);
}
void loop() {
// Send data only when received data
if (mySerial.read() == 0xff)
{
// Read the incoming byte
for (int j = 0; j < 134; j++)
{
col = mySerial.read();
buffer_RTT[j] = (char)col;
delay(2);
}
mySerial.flush();
if(buffer_RTT[1]==0xff){
if(buffer_RTT[2]==0xff){
YCTa = buffer_RTT[3];
YCTb = buffer_RTT[4];
YCT1 = (YCTa << 8) + YCTb;
}
}//Read obstacle distance of the maximum reflection intensity.
for(int i=6;i<134;i++){
if(buffer_RTT[i]==buffer_RTT[i-1]){
if(buffer_RTT[i-1]>buffer_RTT[i-2]){
Tar1a = i-6;
checka= buffer_RTT[i-1];
} //Check the increase of the peak
}
if(buffer_RTT[i]<buffer_RTT[i-1])
{
if(buffer_RTT[i-1]==buffer_RTT[i-2])
{
checkb= buffer_RTT[i-1];//Check the decrease of the peak
if(checka==checkb&&checkb>=10)
{
Tar1b = i-6;
Tar1b=Tar1b-Tar1a;
Tar1b=Tar1b/2;
Tar1a=Tar1a+Tar1b;
Distance=Tar1a*0.126;
Distance=Distance*100;//Calculate distance
Serial.print("Distance");
Serial.print(Tarnum);
Serial.print(":");
Serial.println(Distance);//Output the distance of other obstacles, can read other 3 obstacles at most.
Serial.print("D: ");
Serial.println(YCT1);//Output the obstacle distance of the maximum reflection intensity.
if(Tarnum==1){
Distance1=Distance;
}
if(Tarnum==2){
Distance2=Distance;
}
if(Tarnum==3){
Distance3=Distance;
}
Tarnum++;
}
}
}
}
Tarnum=1;
}
}
Result
Output Result: output about 5 distance values at most.
Was this article helpful?
