Example Code for Arduino - Detecting Gesture with ID=1

Last revision 2026/03/05

FireBeetle 2 ESP32-E enables gesture detection with the AI Vision Posture Sensor. Setup includes hardware, Arduino IDE, and library guide. Follow the I2C wiring and use provided sample code for detecting learned gestures and controlling the onboard LED.

Hardware Preparation

Software Preparation

Wiring Diagram

I²C Connection (The following examples all use I²C communication)
SEN0670-I2C wiring

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
SEN0670-UART wiring
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.

Sample Code

Function: Drive gesture sensor over I2C, light on LED and print log when gesture ID=1 is detected.

Example Code:

#include <DFRobot_HumanPose.h>

// I2C communication
const uint8_t I2C_ADDR = 0x3A;
DFRobot_HumanPose_I2C humanPose(&Wire, I2C_ADDR);

void setup() {
  Serial.begin(115200);

  // Initialise the sensor
  while (!humanPose.begin()) {
    Serial.println("Sensor initialisation failed!");
    delay(1000);
  }
  Serial.println("Sensor initialisation successful!");

  // Set hand detection mode
  humanPose.setModelType(DFRobot_HumanPose::eHand);

  // Reduce false recognition: increase confidence threshold
  humanPose.setConfidence(80);
  humanPose.setLearnSimilarity(80);

  // Initialise LED
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, LOW);
}

void loop() {
  bool ledState = LOW; // Default: LED off

  if (humanPose.getResult() == DFRobot_HumanPose::eOK) {
    while (humanPose.availableResult()) {
      Result *result = humanPose.popResult();
      if (!result) continue;

      // ==========================================
      // ? LED turns on only for ID=1
      // ==========================================
      if (result->id == 1 && result->score >= 80) {
        ledState = HIGH;
        Serial.print("✅ Recognised gesture with ID=1: ");
        Serial.println(result->name);
      }
    }
  }

  // Control the LED
  digitalWrite(LED_BUILTIN, ledState);
  delay(100);
}

Result:

When you make the "victory" (✌) gesture towards the camera, the LED on the main board turns on.
SEN0670-ID1

Was this article helpful?

TOP