Example Code for Arduino - Custom Posture Recognition

Last revision 2026/03/05

Step‑by‑step guide to Arduino custom posture recognition with AI posture and gesture sensor SEN0670 and FireBeetle 2 ESP32‑E: hardware list, I2C/UART wiring, Arduino IDE setup, DFRobot_HumanPose library, and example code to classify learned vs unknown postures.

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

Before starting this example, make sure the sensor has already learned custom postures using the host computer software. If no postures have been learned beforehand, the sensor will recognise them as unknown postures.

Function: Drive posture sensor via I2C, output posture info including ID and confidence over serial.

#include <DFRobot_HumanPose.h>

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

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

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

  // 2. Set to "human posture detection" mode
  humanPose.setModelType(DFRobot_HumanPose::ePose);
}

void loop()
{
  // 3. Get the detection result
  if (humanPose.getResult() == DFRobot_HumanPose::eOK) {
    // Iterate through all detected targets
    while (humanPose.availableResult()) {
      Result *result = humanPose.popResult();
      if (result) {
        // Print prefix uniformly
        if (result->id == 0) {
          Serial.print("[Unknown posture/person]");
        } else {
          Serial.print("[Learned posture]");
        }
        
        // Print ID and name uniformly
        Serial.print(" ID: ");
        Serial.print(result->id);
        Serial.print(" | Name: ");
        if (result->id == 0) {
          Serial.println("unknown"); // Show "unknown" for unlearned
        } else {
          Serial.println(result->name); // Show actual name for learned
        }
        
        // Print common information: confidence
        Serial.print("Confidence: ");
        Serial.println(result->score);
        Serial.println("------------------------");
      }
    }
  }

  delay(100); // 100ms delay to avoid spamming the serial monitor
}

Result:

The sensor automatically recognises postures and can distinguish between learned and unlearned postures.
SEN0670-Get posture

Was this article helpful?

TOP