Gravity: PAJ7620U2 Gesture Sensor Wiki - DFRobot

Introduction

Build an awesome interactive project with this PAJ7620U2 Gesture Sensor! It is an interactive sensor with 3D gesture recognition that can recognize 13 gestures at most within 20cm.

There are two recognition modes for this sensor: fast mode (9 gestures) and slow mode (13 gestures). In fast detection mode, the sensor can recognize 9 gestures: move left, right, up, down, forward, backward, clockwise, counter-clockwise, wave. The slow mode can recognize 4 expanded gestures besides the 9 basic gestures: slowly move left and right, slowly move up and down, slowly move forward and backward, move randomly. The unit sampling time can be defined by users in this mode. Moreover, users can customize their own gestures if necessary.

The sensor offers stable performance, fast response and high accuracy, which makes it an excellent choice for interactive applications like non-contact remote controller, interactive robot, gesture-based game device, smart lighting management, and so on.

Specification

SEN0315 Size

Module Cover

Board OverView

SEN0315 Top View Bottom View

Silkscreen Description
D IIC SDA
C IIC SCL
- Negative
+ Positive

Tutorial

Requirements

Connection Diagram

Connection with UNO

Sample Code

Functions for reference:

DFRobot_PAJ7620U2(TwoWire *pWire=&Wire); 
 /**
  * @brief Constructor
  * @param mode Call the function and designate the device's default working mode. 
  */
 int begin(void) 
  /**
  * @brief Init function
  * @return Return 0 if the initialization succeeds, otherwise return non-zero.
  */
void setGestureHighRate(bool b);
  /**
  * @brief Set the gesture recognition mode 
   * @param b true Fast detection mode, recognize gestures quickly and return. 
   * @n  false Slow detection mode, the system will do more judgements. 
   * @n  In fast detection mode, the sensor can recognize 9 gestures: move left, right, up, down, forward,
   * @n  backward, clockwise, counter-clockwise, wave.  
   * @n  To detect the combination of these gestures, like wave left, right and left quickly, users need to  
   * @n  design their own algorithms logic. 
   * @n  Since users only use limited gestures, we didn't integrate too much expanded gestures in the library. 
   * @n  If necessary, you can complete the algorithm logic in the ino file by yourself.   
   * @n
   * @n
   * @n  In slow detection mode, the sensor recognize one gesture every 2 seconds, and we have integrated the       
   * @n  expanded gestures inside the library, which is convenient for the beginners to use.  
   * @n  The slow mode can recognize 9  basic gestures and 4 expanded gestures: move left, right, up, down,      
   * @n  forward, backward, clockwise, counter-clockwise, wave, slowly move left and right, slowly move up 
   * @n  and down, slowly move forward and backward, wave slowly and randomly.
   */
 String gestureDescription(eGesture_t gesture);
 /**
   * @brief Get the string descritpion corresponding to the gesture number. 
   * @param gesture Gesture number inlcuded in the eGesture_t
   * @return Textual description corresponding to the gesture number:if the gesture input in the gesture table      
   * @n doesn't exist, return null string 
   * @n Normally, it may return "None","Right","Left", "Up", "Down", "Forward", "Backward", "Clockwise",
   * @n "Anti-Clockwise", "Wave", "WaveSlowlyDisorder", "WaveSlowlyLeftRight", "WaveSlowlyUpDown",
   * @n "WaveSlowlyForwardBackward"
  */
eGesture_t getGesture(void);
/**
   * @brief Get gesture
   * @return The gesture value it may return: eGestureNone  eGestureRight  eGestureLeft  eGestureUp  
   * @n     eGestureDown  eGestureForward  eGestureBackward  eGestureClockwise
   * @n     eGestureWave  eGestureWaveSlowlyDisorder  eGestureWaveSlowlyLeftRight  
   * @n     eGestureWaveSlowlyUpDown  eGestureWaveSlowlyForwardBackward
   */

Fast Detection Mode

Code function: recognize the following gestures.

Note: the clockwise and anti-clockwise gesture detection requires at least two repeated motions.

The available gestures in fast detection mode:

Gesture Code Gesture Description
1 Right
2 Left
4 Up
8 Down
16 Forward
32 Backward
64 Clockwise
128 Anti-clockwise
256 Wave(Quickly)
/*!
 * @file GestureRecognize_HighRate.ino
 * @brief Present the 9 built-in gestures data the sensor supports. 
 * @n Wave your hand above the sensor (within 0~20cm), it can recognize 9 kinds of gestures: move up, down, left, right, forward,
 * @n backward, clockwise, anti-clockwise, wave.
 * @n For more usages of the sensor, refer to the description about setGestureHighRate in function setup.
 *
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author      Alexander(ouki.wang@dfrobot.com)
 * @version  V1.0
 * @date  2019-07-16
 * @get from https://www.dfrobot.com
 * @url https://github.com/DFRobot/DFRobot_PAJ7620U2
 */

#include <DFRobot_PAJ7620U2.h>

DFRobot_PAJ7620U2 paj;

void setup()
{
  Serial.begin(115200);
  delay(300);
  Serial.println("Gesture recognition system base on PAJ7620U2");
  while(paj.begin() != 0){
    Serial.println("initial PAJ7620U2 failure! Please check if all the connections are fine, or if the wire sequence is correct?");
    delay(500);
  }
  Serial.println("PAJ7620U2 init completed, start to test the gesture recognition function");

  /*Set fast detection mode 
   *If the parameter is set to false, the module enters slow detection mode, and it detects one gesture every 2s. We have integrated
   *some gestures inside the module to make it convenient for beginners.
   *The slow mode can recognize 9  basic gestures and 4 expanded gestures: move left, right, up, down, forward, backward, clockwise, 
   *counter-clockwise, wave, slowly move left and right, slowly move up and down, slowly move forward and backward, 
   *wave slowly and randomly.
   *
   *
   *
   *If the parameter is set to true, the module enters fast detection mode. 
   *The fast mode can recognize 9 gestures: move left, right, up, down, forward, backward, clockwise, counter-clockwise, wave
   *To detect the combination of these gestures, like wave left, right and left quickly, users needs to design their own algorithms logic.
   *Since users only use limited gestures in this mode, we are not going to integrate too much expanded gestures in the library. 
   *If necessary, you can complete the algorithm logic in the ino file by yourself.
   */
  paj.setGestureHighRate(true);

}

void loop()
{
  /* Read gesture number(return eGesture_t enumerated type)
   * eGestureNone  eGestureRight  eGestureLeft  eGestureUp  eGestureDown  eGestureForward
   * eGestureBackward  eGestureClockwise  eGestureAntiClockwise  eGestureWave  eGestureWaveSlowlyDisorder
   * eGestureWaveSlowlyLeftRight  eGestureWaveSlowlyUpDown  eGestureWaveSlowlyForwardBackward
   */
  DFRobot_PAJ7620U2::eGesture_t gesture = paj.getGesture();
  if(gesture != paj.eGestureNone ){
   /* Get the string descritpion corresponding to the gesture number.
    * The string description could be 
    * "None","Right","Left", "Up", "Down", "Forward", "Backward", "Clockwise", "Anti-Clockwise", "Wave",
    * "WaveSlowlyDisorder", "WaveSlowlyLeftRight", "WaveSlowlyUpDown", "WaveSlowlyForwardBackward"
    */
    String description  = paj.gestureDescription(gesture);//Convert gesture number into string description
    Serial.println("--------------Gesture Recognition System---------------------------");
    Serial.print("gesture code        = ");Serial.println(gesture);
    Serial.print("gesture description  = ");Serial.println(description);
    Serial.println();
  }
}         

Expected Results

Serial print the code and description of 9 gestures.

Result

Slow Detection Mode

Note: the default samping time in slow mode is 2s, so you need to wait for 1s when completed one detection.

The available gestures in slow detection mode:

Gesture Code Gesture Description
1 Right
2 Left
3 WaveSlowlyLeftRight
4 Up
8 Down
12 WaveSlowlyUpDown
16 Forward
32 Backward
48 WaveSlowlyForwardBackward
64 Clockwise
128 Anti-clockwise
256 Wave(quickly)
512 WaveSlowlyDisorder
#include <DFRobot_PAJ7620U2.h>

/*!
 * @file GestureRecognize_LowRate.ino
 * @brief Present the 9 built-in gestures the sensor supports and 4 extended gestures in the slow mode.  
 * @n Wave you hand above the sensor(within 0~20cm), it can detect: move left, right, up, down, forward, backward, clockwise, 
 * @n anti-clockwise, wave, slowly move left and right, slowly move up and down, slowly move forward and backward, wave randomly and slowly.
 * @n For more usages of the sensor, refer to the description about setGestureLowRate in function setup.  
 *
 * @copyright   Copyright (c) 2010 DFRobot Co.Ltd (https://www.dfrobot.com)
 * @licence     The MIT License (MIT)
 * @author      Alexander(ouki.wang@dfrobot.com)
 * @version  V1.0
 * @date  2019-07-16
 * @get from https://www.dfrobot.com
 * @url https://github.com/DFRobot/DFRobot_PAJ7620U2
 */

#include <DFRobot_PAJ7620U2.h>

DFRobot_PAJ7620U2 paj;

void setup()
{
  Serial.begin(115200);
  delay(300);
  Serial.println("Gesture recognition system base on PAJ7620U2");
  while(paj.begin() != 0){
    Serial.println("initial PAJ7620U2 failure! Please check if all the connections are fine, or if the wire sequence is correct?");
    delay(500);
  }
  Serial.println("PAJ7620U2init completed, start to test the gesture recognition function");

  /*Set fast detection mode 
   *If the parameter is set to false, the module enters slow detection mode, and it detects one gesture every 2s. We have integrated 
   *some gestures inside the module to make it convenient for beginners.
   *The slow mode can recognize 9  basic gestures and 4 expanded gestures: move left, right, up, down, forward, backward, clockwise, 
   *counter-clockwise, wave, slowly move left and right, slowly move up and down, slowly move forward and backward,
   *wave slowly and randomly. 
   *
   *
   *
   *If the parameter is set to true, the module enters fast detection mode. 
   *The fast mode can recognize 9 gestures: move left, right, up, down, forward, backward, clockwise, counter-clockwise, wave.
   *To detect the combination of these gestures, like wave left, right and left quickly, users needs to design their own
   *algorithms logic.
   *Since users only use limited gestures in this mode, we are not going to integrate too much expanded gestures in the library.
   *If necessary, you can complete the algorithm logic in the ino file by yourself.
   */
  paj.setGestureHighRate(false);

}

void loop()
{
  /* Read gesture number(return eGesture_t enumerated type)
   * eGestureNone  eGestureRight  eGestureLeft  eGestureUp  eGestureDown  eGestureForward
   * eGestureBackward  eGestureClockwise  eGestureAntiClockwise  eGestureWave  eGestureWaveSlowlyDisorder
   * eGestureWaveSlowlyLeftRight  eGestureWaveSlowlyUpDown  eGestureWaveSlowlyForwardBackward
   */
  DFRobot_PAJ7620U2::eGesture_t gesture = paj.getGesture();
  if(gesture != paj.eGestureNone ){
   /* Get the string descritpion corresponding to the gesture number.
    * The string description could be 
    * "None","Right","Left", "Up", "Down", "Forward", "Backward", "Clockwise", "Anti-Clockwise", "Wave",
    * "WaveSlowlyDisorder", "WaveSlowlyLeftRight", "WaveSlowlyUpDown", "WaveSlowlyForwardBackward"
    */
    String description  = paj.gestureDescription(gesture);//Convert gesture number into string description
    Serial.println("--------------Gesture Recognition System---------------------------");
    Serial.print("gesture code        = ");Serial.println(gesture);
    Serial.print("gesture description  = ");Serial.println(description);
    Serial.println();
  }
}

Expected Result

Serial print the code and description of 13 gestures:

Result

FAQ

For any questions, advice or cool ideas to share, please visit the DFRobot Forum

More Documents