Example Code for Arduino-Single Target Detection

Last revision 2025/12/17

Explore step-by-step instructions for integrating a 24GHz Microwave Radar Sensor with Arduino UNO, including hardware setup, wiring diagrams, and sample code for detecting single targets and measuring distances based on reflection intensity, perfect for hobbyists and educators.

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 is unconnected.

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 the data read from serial port
unsigned char buffer_RTT[8] = {};
int YCTa = 0, YCTb = 0,YCT1 = 0;
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 < 8; 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 the obstacle distance of maximum reflection intensity
                    Serial.print("D: ");
                    Serial.println(YCT1);//Output the obstacle distance of maximum reflection intensity          
        }
        }  

Result

Output result: the obstacle distance of maximum reflection intensity.

Was this article helpful?

TOP