Example Code for Arduino - Fixed gesture recognition
Last revision 2026/06/08
Covers Arduino fixed gesture recognition using AI posture and gesture sensor SEN0670 with ESP32. Guides from hardware wiring (I2C/UART) → Arduino IDE + DFRobot_HumanPose library → set fixed gesture model → read gesture ID, name, confidence. Topic path: Docs → Tutorials → Projects → SEN0670 → Gesture & AI Vision Category.
Hardware Preparation
- Gravity: AI Posture and Gesture Sensor (SKU: SEN0670) ×1
- FireBeetle 2 ESP32‑E (SKU: DFR0654)
- USB Type‑C cable ×1
- PC ×1
Software Preparation
- Programming environment: Click to download Arduino IDE
- Download and install the sensor library: DFRobot_HumanPose
- Please click here to view: How to install a library?
Wiring Diagram
- I²C Connection (The following examples all use I²C communication)

Connection Description:
| Sensor Pin: VCC | Connect to | Main Controller Pin: 5V |
|---|---|---|
| Sensor Pin: GND | Connect to | Main Controller Pin: GND |
| Sensor Pin: C | Connect to | Main Controller Pin: 22/SCL |
| Sensor Pin: D | Connect to | Main Controller Pin: 21/SDA |
- UART Connection

Connection Description:
| Sensor Pin: VCC | Connect to | Main Controller Pin: 5V |
|---|---|---|
| Sensor Pin: GND | Connect to | Main Controller Pin: GND |
| Sensor Pin: R | Connect to | Main Controller Pin: 26/D3 |
| Sensor Pin: T | Connect to | Main Controller Pin: 25/D2 |
Note:
- The default communication method of the sensor is I²C. If you need to switch to UART, use the on‑board DIP switch to change the communication method.
- After switching, the sensor must be powered off and on again for the change to take effect.
Other preparations
This feature is still in the testing phase, and the AI model recognition accuracy is currently limited. We are optimising this feature.
The list of fixed gestures is as follows:

In the code, set the sensor to fixed gesture recognition mode. It will recognise the fixed gestures shown in the image above, and the serial monitor will print the corresponding digital ID. For example, when the "OK" gesture is detected, it will print the corresponding ID "9". Any gesture not in the image above will be reported as no valid gesture detected.
Sample Code
Function: Drive gesture recognition sensor via I2C and output results over serial port.
#include <DFRobot_HumanPose.h>
// Select communication method: I2C by default (simplest wiring)
#define HUMANPOSE_COMM_I2C
#if defined(HUMANPOSE_COMM_I2C)
// I2C default address 0x3A, no need to modify
const uint8_t I2C_ADDR = 0x3A;
DFRobot_HumanPose_I2C humanPose(&Wire, I2C_ADDR);
#else
#error "Please define the communication method first (I2C recommended)"
#endif
// No target prompt interval (in milliseconds), default 1000ms = 1 second, to avoid spamming
const unsigned long NO_TARGET_INTERVAL = 1000;
// Record the last time the no-target prompt was printed
unsigned long lastNoTargetTime = 0;
void setup()
{
Serial.begin(115200);
// Initialise the sensor
while (!humanPose.begin()) {
Serial.println("Sensor initialisation failed, please check the wiring!");
delay(1000);
}
Serial.println("Sensor initialisation successful!");
Serial.println("Please make a gesture in front of the sensor~");
Serial.println("------------------------");
// Set to fixed gesture recognition mode
humanPose.setModelType(DFRobot_HumanPose::eGesture);
}
void loop()
{
// Get recognition result
if (humanPose.getResult() == DFRobot_HumanPose::eOK) {
bool hasTarget = false;
// Iterate through all detected gestures
while (humanPose.availableResult()) {
Result *result = humanPose.popResult();
if (result) {
hasTarget = true;
// Print core gesture information
Serial.print("Gesture ID: "); Serial.print(result->id);
Serial.print(" | Name: "); Serial.print(result->name);
Serial.print(" | Confidence: "); Serial.println(result->score);
Serial.print("Position: left="); Serial.print(result->xLeft);
Serial.print(" top="); Serial.print(result->yTop);
Serial.print(" width="); Serial.print(result->width);
Serial.print(" height="); Serial.println(result->height);
Serial.println("------------------------");
}
}
// Key modification: when no target is detected, print prompt at intervals
if (!hasTarget) {
unsigned long now = millis();
if (now - lastNoTargetTime >= NO_TARGET_INTERVAL) {
Serial.println("No valid gesture detected");
Serial.println("------------------------");
lastNoTargetTime = now; // Update the last prompt time
}
}
} else {
// Optional: add sensor read timeout prompt (generally not needed unless wiring is loose)
// Serial.println("Sensor read timeout");
}
delay(100);
}
Result:
Make any gesture from the image above, and the sensor will effectively recognise it and print the corresponding ID.

Was this article helpful?
