Example Code for Arduino-Reading Data via UART
Reading Data via UART
Hardware Preparation
Software Preparation
- Arduino IDE Click to download Arduino IDE
- Download and install DFRobot_GestureFaceDetection
- Download and install DFRobot_RTU
Wiring Diagram

Other Preparation Work
- Step 1: Connect the sensor to the ESP32-E controller according to the wiring diagram above, and switch the communication mode selection switch on the sensor to the UART side.
- Step 2: Open Arduino IDE, copy the following code and upload it to the ESP32-E.
- Step 3: Open the serial monitor in Arduino IDE, set the baud rate to 115200, and observe the serial print results.
Sample Code
#include "DFRobot_GestureFaceDetection.h"
#define DEVICE_ID 0x72
DFRobot_GestureFaceDetection_UART gfd(&Serial1, DEVICE_ID);
void setup(){
Serial1.begin(9600,SERIAL_8N1, D2, D3);
Serial.begin(115200);
delay(1500);
Serial.print("Product ID: ");
Serial.println(gfd.getPid());
Serial.print("Vendor ID: ");
Serial.println(gfd.getVid());
}
void loop(){
Serial.print("Faces detected: ");
Serial.println(gfd.getFaceNumber());
delay(1500);
}
Result
Output content of the serial monitor:

Additional Information
Interpretation:
- First two lines: Device identity information
- Product ID: 626: The product number of the sensor (corresponding to 0x3343 in hexadecimal);
- Vendor ID: 13123: The vendor number (corresponding to 0x0272 in hexadecimal).
- Third line: Face detection result
- Faces detected: 1: Indicates that 1 face (area above the shoulders) is currently detected, and the face indicator light is on steadily at this time;
- If there is no one, it will display Faces detected: 0, and the indicator light will turn off synchronously.
The face detection information is refreshed every 1.5 seconds, providing an intuitive feedback of the detection result.
Was this article helpful?
