Example Code for Arduino-Dazzling LED Ring

Create a dazzling, gesture-controlled LED ring with the Gravity AI Sensor. The ring lights up when a person is detected and changes color based on five distinct hand gestures (e.g., "Good" for Blue, "OK" for Green), offering an intuitive, touchless interactive lighting experience.

Hardware Preparation

Software Preparation

Wiring Diagram

 Wiring Diagram

Other Preparation Work

  • Step 1: Connect the sensor, WS2812B LED ring, and ESP32-C3 controller according to the wiring diagram, and switch the sensor's communication mode switch to the I2C side.
  • Step 2: Open Arduino IDE, copy the following code and upload it to the ESP32-C3.

Sample Code

#include <Wire.h>
#include <FastLED.h>
#include "DFRobot_GestureFaceDetection.h"

#define LED_PIN     4
#define NUM_LEDS    93
#define DEVICE_ID   0x72

CRGB leds[NUM_LEDS];
DFRobot_GestureFaceDetection_I2C gfd(DEVICE_ID);

void setup() {
  FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS);
  Wire.begin(8, 9);  // SDA, SCL
  gfd.begin(&Wire);
  Serial.begin(115200);
  gfd.setFaceDetectThres(60);
  gfd.setGestureDetectThres(60);  
  gfd.setDetectThres(100);
}

void loop() {
  if(gfd.getFaceNumber() > 0) {
    uint16_t gestureType = gfd.getGestureType();
    switch(gestureType) {
      case 1:
        setAllLEDs(CRGB::Blue);
        break;
      case 2:
        setAllLEDs(CRGB::Green);
        break;
      case 3:
        setAllLEDs(CRGB::Red);
        break;
      case 4:
        setAllLEDs(CRGB::Yellow);
        break;
      case 5:
        setAllLEDs(CRGB::Purple);
        break;
      default:
        setAllLEDs(CRGB::Black);
        break;
    }
  }
  else {
    setAllLEDs(CRGB::Black);
  }
  delay(1500);
}

void setAllLEDs(CRGB color) {
  for(int i = 0; i < NUM_LEDS; i++) {
    leds[i] = color;
  }
  FastLED.show();
}

Result

When the sensor detects a face (area above the shoulders), the LED ring will synchronously change color according to the gesture you make:

  • Gesture 1 (Good) → Blue;
  • Gesture 2 (OK) → Green;
  • Gesture 3 (Stop) → Red;
  • Gesture 4 (Victory) → Yellow;
  • Gesture 5 (Call me) → Purple.

When no face is detected, the LED ring automatically turns off, achieving the intelligent effect of "lights on when someone is present, color controlled by gestures".

Was this article helpful?

TOP