Hackster is hosting Hackster Holidays, Ep. 7: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Friday!Stream Hackster Holidays, Ep. 7 on Friday!
SurtrTech
Published © GPL3+

Hand Gesture Recognition Sensor (PAJ7620)

Add hand gestures to your Arduino projects (robots, HMI, lights, etc.).

BeginnerProtip1 hour32,820

Things used in this project

Story

Read more

Schematics

Wiring 1

Direct test and use

Wiring 2

Adding the LCD i²c

Code

PAJ7620_Gestures_LCD.ino

Arduino
The code that uses the LCD i²c, just to show you can adapt it to pretty much everything
/* This code works with PAJ7620 Hand gestures sensor and LCD ic screen
 * It shows the gestures detected on the LCD screen
 * Adapted from the Seeed PAJ7620 library examples
 * For more details check www.surtrtech.com
 */

#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include "paj7620.h"

#define I2C_ADDR 0x27 //I2C adress, you should use the code to scan the adress first (0x27) here
#define BACKLIGHT_PIN 3 // Declaring LCD Pins
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7

#define GES_REACTION_TIME    500     
#define GES_ENTRY_TIME      800        
#define GES_QUIT_TIME     1000


LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

void setup() {
  paj7620Init();
  
  lcd.begin (16,2);
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH); //Lighting backlight
  
}

void printing(){
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Gesture Sensor");
  lcd.setCursor(0,1);
}

void loop() {


  uint8_t data = 0, data1 = 0, error;
  
  error = paj7620ReadReg(0x43, 1, &data);       // Read Bank_0_Reg_0x43/0x44 for gesture result.
  if (!error) 
  {
    
    switch (data)                   // When different gestures be detected, the variable 'data' will be set to different values by paj7620ReadReg(0x43, 1, &data).
    {
      case GES_RIGHT_FLAG:
        delay(GES_ENTRY_TIME);
        paj7620ReadReg(0x43, 1, &data);
        if(data == GES_FORWARD_FLAG) 
        {
          printing();
          lcd.print("Forward");
          delay(GES_QUIT_TIME);
        }
        else if(data == GES_BACKWARD_FLAG) 
        {
          printing();
          lcd.print("Backward");
          delay(GES_QUIT_TIME);
        }
        else
        {
          printing();
          lcd.print("Right");
        }          
        break;
      case GES_LEFT_FLAG: 
        delay(GES_ENTRY_TIME);
        paj7620ReadReg(0x43, 1, &data);
        if(data == GES_FORWARD_FLAG) 
        {
          printing();
          lcd.print("Forward");
          delay(GES_QUIT_TIME);
        }
        else if(data == GES_BACKWARD_FLAG) 
        {
          printing();
          lcd.print("Backward");
          delay(GES_QUIT_TIME);
        }
        else
        {
          printing();
          lcd.print("Left");
        }          
        break;
      case GES_UP_FLAG:
        delay(GES_ENTRY_TIME);
        paj7620ReadReg(0x43, 1, &data);
        if(data == GES_FORWARD_FLAG) 
        {
          printing();
          lcd.print("Forward");
          delay(GES_QUIT_TIME);
        }
        else if(data == GES_BACKWARD_FLAG) 
        {
          printing();
          lcd.print("Backward");
          delay(GES_QUIT_TIME);
        }
        else
        {
          printing();
          lcd.print("Up");
        }          
        break;
      case GES_DOWN_FLAG:
        delay(GES_ENTRY_TIME);
        paj7620ReadReg(0x43, 1, &data);
        if(data == GES_FORWARD_FLAG) 
        {
          printing();
          lcd.print("Forward");
          delay(GES_QUIT_TIME);
        }
        else if(data == GES_BACKWARD_FLAG) 
        {
          printing();
          lcd.print("Backward");
          delay(GES_QUIT_TIME);
        }
        else
        {
          printing();
          lcd.print("Down");
        }          
        break;
      case GES_FORWARD_FLAG:
        printing();
        lcd.print("Forward");
        delay(GES_QUIT_TIME);
        break;
      case GES_BACKWARD_FLAG: 
        printing();    
        lcd.print("Backward");
        delay(GES_QUIT_TIME);
        break;
      case GES_CLOCKWISE_FLAG:
        printing();
        lcd.print("Clockwise");
        break;
      case GES_COUNT_CLOCKWISE_FLAG:
        printing();
        lcd.print("anti-clockwise");
        break;  
      default:
        paj7620ReadReg(0x44, 1, &data1);
        if (data1 == GES_WAVE_FLAG) 
        {
          printing();
          lcd.print("wave");
        }
        break;
    }
  }
  
  delay(100);

}

PAJ7620 - Seeed Library

LCD NewLiquidCrystal i²c library

Credits

SurtrTech
9 projects • 207 followers
YT Channel bit.ly/35Ai76l, run by Automation and Electrical Engineer, Electronics amateur, no IT background so you may see wreckage in codes

Comments