Example Code for Arduino-Fast Detection Mode
Last revision 2026/01/12
This example demonstrates gesture recognition in fast detection mode.
Code function: recognize the following gestures.
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) |
Hardware Preparation
- DFRduino UNO R3 (or similar) x 1
- IO Expansion Shield x1
- Gravity: PAJ7620U2 Gesture Sensor
Software Preparation
- Arduino IDE
- Download and install the PAJ7620U2 Example Library. (About how to install the library?)
Wiring Diagram

Sample Code
/*!
* @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([email protected])
* @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();
}
}
Result
Serial print the code and description of 9 gestures.

Was this article helpful?
