Project tutorial

LED Controlled by 3D Gesture Sensor

I tried controlling the display of flexible LED matrix with 3D gesture sensor.

  • 5,340 views
  • 0 comments
  • 17 respects

Components and supplies

Apps and online services

About this project

I tried controlling the display of flexible LED matrix with 3D gesture sensor.

Configuration

Display the eye on the LED matrix and move with the 3D gesture sensor.

Flexible 8x8 RGB LED Matrix

It has a 8x8 full color LED (NeoPixel) and soft by flexible board. The Arduino library for Neopixels is located in the following.

https://github.com/adafruit/Adafruit_NeoPixel

Please refer below for product details.

https://www.dfrobot.com/wiki/index.php/Gravity:_Flexible_8x8_RGB_LED_Matrix_SKU:_DFR0461

3D Gesture Sensor

Five electrodes are arranged in the up, down, left, right and middle. Gesture is sensed by changes in electrostatic capacitance of electrodes due to hand approach.

The Arduino library for the 3D Gesture Sensor is located in the following.

https://github.com/DFRobot/DFRobot_Gesture

This gesture sensor detects clockwise/counterclockwise rotation and movement directions (up, down, left, right) using program example "_3D_Gesture_Test.ino".

Please refer below for product details.

https://www.dfrobot.com/wiki/index.php/3D_Gesture_Sensor_Mini_SKU:_SEN0202

Arduino Programming

Display the eyeball on the LED matrix, move the eyes right and left with the left and right sensing of the gesture sensor, open and close the eyelids by vertical sensing. The pupil faces the front in clockwise or counterclockwise sensing.

LED Array:

Code:

#include <Adafruit_NeoPixel.h> 
#include <DFRobot_Gesture.h> 
#include <Wire.h> 
int sensePin= A1; 
unsigned char cmd; 
DFRobot_Gesture myGesture; 
#define DIN A0 
Adafruit_NeoPixel led = Adafruit_NeoPixel(64, DIN, NEO_GRB + NEO_KHZ800); 
int LR = 5; 
int eyelid = 0; 
int whiteNum = 52; 
int blackNum = 20; 
int pupilNum = 12; 
//white eye 
int whiteLED[52] = { 2,  3,  4,  5,  9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,   
                         32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 49, 50, 51, 52, 53, 54, 58, 59, 60, 61}; 
//black eye 
int blackLED[11][20] = {{50, 51, 52, 53, 58, 61, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, 
                             {42, 43, 44, 45, 49, 50, 53, 54, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, 
                             {34, 35, 36, 37, 41, 42, 45, 46, 49, 54, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, 
                             {26, 27, 28, 29, 33, 34, 37, 38, 41, 46, 54, 49, 58, 61, 61, 64, 64, 64, 64, 64}, 
                             {18, 19, 20, 21, 25, 26, 29, 30, 33, 38, 41, 46, 49, 50, 53, 54, 58, 59, 60, 61}, 
                             {10, 11, 12, 13, 17, 18, 21, 22, 25, 30, 33, 38, 41, 42, 45, 46, 50, 51, 52, 53}, 
                             { 2,  3,  4,  5,  9, 10, 13, 14, 17, 22, 25, 30, 33, 34, 37, 38, 42, 43, 44, 45}, 
                             { 2,  5,  9, 14, 17, 22, 25, 26, 29, 30, 34, 35, 36, 37, 64, 64, 64, 64, 64, 64}, 
                             { 9, 14, 17, 18, 21, 22, 26, 27, 28, 29, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, 
                             { 9, 10, 13, 14, 18, 19, 20, 21, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, 
                             { 2,  5, 10, 11, 12, 13, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}}; 
//pupil 
int pupilLED[11][12] = {{59, 60, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}, 
                             {51, 52, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64}, 
                             {43, 44, 50, 51, 52, 53, 58, 59, 60, 61, 64, 64}, 
                             {35, 36, 42, 43, 44, 45, 50, 51, 52, 53, 59, 60}, 
                             {27, 28, 34, 35, 36, 37, 42, 43, 44, 45, 51, 52}, 
                             {19, 20, 26, 27, 28, 29, 34, 35, 36, 37, 43, 44}, 
                             {11, 12, 18, 19, 20, 21, 26, 27, 28, 29, 35, 36}, 
                             { 3,  4, 10, 11, 12, 13, 18, 19, 20, 21, 27, 28}, 
                             { 2,  3,  4,  5, 10, 11, 12, 13, 19, 20, 64, 64}, 
                             { 2,  3,  4,  5, 11, 12, 64, 64, 64, 64, 64, 64}, 
                             { 3,  4, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64}}; 
//eyelid 
int eyelidNum[8] = {0,4,8,14,20,28,36,44}; 
int eyelidLED[56] = {23, 24, 39, 40, 22, 25, 38, 41,  9, 21, 26, 37, 42, 54, 10, 20, 27, 36, 43, 53,  5, 11,  
                    19, 28, 35, 44, 52, 58,  4, 12, 18, 29, 34, 45, 51, 59,  3, 13, 17, 30, 33, 46, 50, 60}; 
void setup(){ 
 Wire.begin();        // join i2c bus (address optional for master) 
 Serial.begin(115200);  // start serial for output 
 pinMode(sensePin, INPUT); 
 led.begin(); 
 led.setBrightness(100); //LED brightness 0-255  
 blink(LR, eyelid); 
} 
void loop(){ 
 if(digitalRead(sensePin)==0){   
   myGesture.I2C1_MasterRead(md.buf,26,0x42); //The address is:0x42 
   cmd = myGesture.mgcProcMsg();     //process the message 
   if(cmd != GI_NOGESTURE ){ 
     switch(cmd){ 
       case GI_FLICK_R: 
         Serial.println("RIGHT"); 
         //Move the eye right 
         for(int i = LR; i <= 10; i++){ 
           blink(i, eyelid); 
           delay(100); 
         } 
         LR = 10; 
         break; 
       case GI_FLICK_L: 
         Serial.println("LEFT"); 
         //Move the eye left 
         for(int i = LR; i >= 0; i--){ 
           blink(i, eyelid); 
           delay(100); 
         } 
         LR = 0; 
         break; 
       case GI_FLICK_D: 
         Serial.println("DOWN"); 
         //Eyelid close 
         for(int i = eyelid; eyelid <= 8; eyelid++){ 
           blink(LR, eyelid); 
           delay(100); 
         } 
         eyelid = 8; 
         break; 
       case GI_FLICK_U: 
         Serial.println("UP"); 
         //Eyelid open 
         for(int i = eyelid; eyelid >= 0; eyelid--){ 
           blink(LR, eyelid); 
           delay(100); 
         } 
         eyelid = 0; 
         break; 
       case GI_AIRWHEEL_CW://Clockwise in circles 
         Serial.println("CW"); 
         //Return eye to the front 
         Return(); 
         break; 
       case GI_AIRWHEEL_CCW://Counterclockwise circles 
         Serial.println("CCW"); 
         //Return eye to the front 
         Return(); 
         break; 
       default: break; 
       } 
     } 
   } 
} 
void blink( int LR, int eyelid) { 
 if (eyelid != 8){ 
   //white eye 
   for(uint16_t i=0; i<whiteNum; i++) { 
     led.setPixelColor(whiteLED[i], led.Color(66, 66, 66)); 
   } 
   //black eye 
   for(uint16_t i=0; i<blackNum; i++) { 
     led.setPixelColor(blackLED[LR][i], led.Color(0, 177, 55)); 
   } 
   //pupil 
   for(uint16_t i=0; i<pupilNum; i++) { 
     led.setPixelColor(pupilLED[LR][i], led.Color(0, 0, 66)); 
   } 
   //eyelid 
   for(int i=0; i < eyelidNum[eyelid]; i++) { 
     led.setPixelColor(eyelidLED[i], 0); 
   } 
 } else if (eyelid == 8){ 
   led.clear(); 
 } 
 led.show(); 
} 
void Return() { 
 if(LR == 0){ 
   for(int i = LR; i <= 5; i++){ 
     blink(i, eyelid); 
     delay(100); 
   } 
 } 
 if(LR == 10){ 
   for(int i = LR; i >= 5; i--){ 
     blink(i, eyelid); 
     delay(100); 
   } 
 } 
 LR = 5; 
} 

Operation

Comments

Similar projects you might like

Neopixel LED Eyeball Controlled by Nunchuck

Project tutorial by HomeMadeGarbage

  • 4,869 views
  • 7 comments
  • 26 respects

LED Hand Sensor

Project tutorial by Yaris

  • 248 views
  • 2 comments
  • 1 respect

3DCG Control Using TouchDesigner & 10 DOF Mems IMU Sensor

Project tutorial by HomeMadeGarbage

  • 2,976 views
  • 0 comments
  • 9 respects

Gesture Controlled Trainable Arduino Robot Arm via Bluetooth

Project tutorial by KureBas Robotics

  • 8,118 views
  • 37 comments
  • 63 respects

Visualising 3D Motion of IMU sensor

Project tutorial by Aritro Mukherjee

  • 21,330 views
  • 6 comments
  • 20 respects

Gesture detection using Particle and SparkFun Gesture Sensor

Project tutorial by Krishnaraj Varma

  • 1,433 views
  • 3 comments
  • 14 respects
Add projectSign up / Login