Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
Mirko Pavleski
Published © GPL3+

Grove Smart IR Gesture Sensor (PAJ7660) Arduino Project

Practical Arduino project with this intelligent gesture recognition module equipped with an infrared camera sensor and applied AI algorithm

BeginnerFull instructions provided2 hours680
Grove Smart IR Gesture Sensor (PAJ7660) Arduino Project

Things used in this project

Hardware components

Seeed Studio Grove Smart IR Gesture Sensor (PAJ7660)
×1
Arduino Nano R3
Arduino Nano R3
×1
I2C 16x2 Arduino LCD Display Module
DFRobot I2C 16x2 Arduino LCD Display Module
×1
Buzzer
Buzzer
×1
LED (generic)
LED (generic)
×5
Resistor 1k ohm
Resistor 1k ohm
×5

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)
Solder Wire, Lead Free
Solder Wire, Lead Free

Story

Read more

Schematics

Schematic

...

Code

Code

C/C++
...
#include "Gesture.h"
#include  <Wire.h>
#include  <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27,16,2);
 
pag7660 Gesture; // Combined mode is used by default

void setup() {
pinMode(2, OUTPUT);
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);  
  lcd.init();                      // initialize the lcd 
  lcd.backlight();
  
    Serial.begin(9600);
    tone(10, 500, 1000);
    
       while(!Serial) {
        delay(100);
    }
    Serial.println("\nPAG7660 TEST DEMO: Gesture combined mode.");
    
    if(Gesture.init()) {
        Serial.println("PAG7660 initialization success");
       lcd.setCursor(5,0);
  lcd.print("PAG7660");    
   lcd.setCursor(1,1);
  lcd.print("Init. success");
  
  delay(2000);
    } else {
        Serial.println("PAG7660 initialization failed");
    }
    Serial.println("Please input your gestures:\n");
   lcd.clear();
   lcd.setCursor(1,0);
  lcd.print("Input Gesture:");
}

void loop() {
    pag7660_gesture_t result;
    if (Gesture.getResult(result)) {
        printResultCombinedMode(result);
    }
    delay(100);
}

void printResultCombinedMode(const pag7660_gesture_t& result) {
    const char *cursor_str[] = {
        NULL,
        "Tap",
        "Grab",
        "Pinch",
    };
    switch (result.type) {
    case 0:
        switch (result.cursor.type) {
        case 1:
        case 2:
        case 3:
            if (result.cursor.select)
                Serial.println(cursor_str[result.cursor.type]);
            break;
        default:
            break;
        }
        break;
    case 1:
        
    case 2:
     
    case 3:
    case 4:
    case 5:
        Serial.print(result.type);
        Serial.println("-finger");
         
          lcd.setCursor(1,1);
          lcd.print(result.type);
          lcd.print(" - finger   ");

          if (result.type <= 1) {
         digitalWrite(2, HIGH); 
         digitalWrite(3,LOW); 
         digitalWrite(4,LOW);
         digitalWrite(5,LOW);
         digitalWrite(6,LOW); 
          }
      
          if (result.type >1  && result.type<=2 ) {
         digitalWrite(2, HIGH); 
         digitalWrite(3,HIGH); 
         digitalWrite(4,LOW);
         digitalWrite(5,LOW);
         digitalWrite(6,LOW); 
          }
       
         if (result.type >2  && result.type<=3 ) {
         digitalWrite(2, HIGH); 
         digitalWrite(3,HIGH); 
         digitalWrite(4,HIGH);
         digitalWrite(5,LOW);
         digitalWrite(6,LOW); 
          }
         if (result.type >3  && result.type<=4 ) {
         digitalWrite(2, HIGH); 
         digitalWrite(3,HIGH); 
         digitalWrite(4,HIGH);
         digitalWrite(5,HIGH);
         digitalWrite(6,LOW); 
          }
          if (result.type >4  && result.type<=5 ) {
         digitalWrite(2, HIGH); 
         digitalWrite(3,HIGH); 
         digitalWrite(4,HIGH);
         digitalWrite(5,HIGH);
         digitalWrite(6,HIGH); 
          }
    break;
      
    case 6:
        Serial.print("Rotate Right ");
        Serial.println(result.rotate);
        break;
    case 7:
        Serial.print("Rotate Left ");
        Serial.println(result.rotate);
        break;
    case 8:
    Serial.println("Swipe Left");
    lcd.setCursor(1,1);
    lcd.print("<-Swipe Left  "); 
     tone(10, 3000, 100);  
   digitalWrite(2, HIGH);  
   digitalWrite(3, HIGH);
   digitalWrite(4, LOW);  
   digitalWrite(5, LOW);  
   digitalWrite(6, LOW);  
   delay(1000);
   digitalWrite(2,LOW);  
   digitalWrite(3, LOW); 
   break;
   
    case 9:
        Serial.println("Swipe Right");

   lcd.setCursor(1,1);
   lcd.print("Swipe Right->"); 
  tone(10, 3000, 100);
  digitalWrite(2, LOW); 
  digitalWrite(3, LOW); 
  digitalWrite(4, LOW); 
   digitalWrite(5, HIGH);  
   digitalWrite(6, HIGH); 
    delay(1000);
   digitalWrite(5,LOW);  
   digitalWrite(6, LOW);  
   
        break;
    case 19:
    case 20:
    case 21:
    case 22:
    case 23:
        Serial.print(result.type - 19 + 1);
        Serial.println("-finger push");
        break;
    default:
        break;
    }
    
}

Credits

Mirko Pavleski

Mirko Pavleski

154 projects • 1301 followers

Comments