Min Ma
Created November 21, 2023

virtual joystick with face movement

Detect human face movement and use it as joystick to help handicaps to play game,

13
virtual joystick with face movement

Things used in this project

Hardware components

Blues Swan
Blues Swan
×1
Person Sensor
Useful Sensors Person Sensor
×1
SparkFun Qwiic Cable Kit
SparkFun Qwiic Cable Kit
×1

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Code

virtual joystick demo

C/C++
Using face recognize to detect face movement and simulate joystick control.
#include <Wire.h>

#include "person_sensor.h"

// How long to wait between reading the sensor. The sensor can be read as
// frequently as you like, but the results only change at about 5FPS, so
// waiting for 200ms is reasonable.
const int32_t SAMPLE_DELAY_MS = 200;

void setup() {
  // You need to make sure you call Wire.begin() in setup, or the I2C access
  // below will fail.
  Wire.begin();
  Serial.begin(9600);
}

void loop() {
  person_sensor_results_t results = {};
  // Perform a read action on the I2C address of the sensor to get the
  // current face information detected.
  if (!person_sensor_read(&results)) {
    Serial.println("No person sensor results found on the i2c bus");
    delay(SAMPLE_DELAY_MS);
    return;
  }

  Serial.println("********");
  Serial.print(results.num_faces);
  Serial.println(" faces found");
  for (int i = 0; i < results.num_faces; ++i) {
    const person_sensor_face_t* face = &results.faces[i];
    Serial.print("Face #");
    Serial.print(i);
    Serial.print(": ");
    Serial.print(face->box_confidence);
    Serial.print(" confidence, (");
    Serial.print(face->box_left);
    Serial.print(", ");
    Serial.print(face->box_top);
    Serial.print("), (");
    Serial.print(face->box_right);
    Serial.print(", ");
    Serial.print(face->box_bottom);
    Serial.print("), ");
    if (face->is_facing) {
      Serial.println("facing");
    } else {
      Serial.println("not facing");
    }
  }
  delay(SAMPLE_DELAY_MS);
}

Credits

Min Ma

Min Ma

8 projects • 1 follower
Senior Software Engineer

Comments