The PAJ7620 is a hand gesture sensor. The sensor contains a 30x30 infrared sensor matrix, which can pick up changes in light intensity. By measuring the time differences between these light changes in the matrix the device can estimate the gesture being made, somewhat similar to an optical mouse used upside down. To enable operation in the dark there is a small IR light souce. It uses the I²C bus to communicate with the microcontroller.

The PAJ7620 is capable of recognising 9 different gestures: up, down, left, right, forward, backward, clockwise, counter-clockwise, and wave. It recognises gestures between 5cm to 15cm with a view angle of 60° and its detection rate is 120 times per second.

PAJ7620 Gesture Sensor

Usage Guide

The official Arduino library is available either in the Arduino IDE Library Manager as “Gesture Paj7620” or can be downloaded from here.

Example Code

A minimal program recognizing the gestures is listed below. For reliable recognition it might be useful to repeat the reading. For instance, if a FORWARD gesture is not exactly aligned with the sensor it might be first recognized as a LEFT gesture. The next reading of the sensor can be used to determine the correct gesture.

 
#include <Wire.h>
#include "paj7620.h"
 
/*
Notice: When you want to recognize the Forward/Backward gestures, your gestures'
		reaction time must less than GES_ENTRY_TIME([+\qty{0.8}{\second}+]).
        You also can adjust the reaction time according to the actual circumstance.
*/
#define GES_REACTION_TIME	500
#define GES_ENTRY_TIME		800
#define GES_QUIT_TIME		1000
#define I2C_ADDRESS         0x43
#define I2C_ADDRESS2        0x44
 
void setup() {
	Serial.begin(115200);
	uint8_t error = paj7620Init();           // initialize Paj7620 registers
	if (error) {
		Serial.print("INIT ERROR,CODE: ");
		Serial.println(error);
	}
}
 
void loop() {
	uint8_t data = 0, data1 = 0, error;
	error = paj7620ReadReg(I2C_ADDRESS, 1, &data); // Read gesture result.
	if (!error)  {
		switch (data) {
			case GES_RIGHT_FLAG:
				Serial.println("Right");
				break;
			case GES_LEFT_FLAG:
				Serial.println("Left");
				break;
			case GES_UP_FLAG:
				Serial.println("Up");
				break;
			case GES_DOWN_FLAG:
				Serial.println("Down");
				break;
			case GES_FORWARD_FLAG:
				Serial.println("Forward");
				delay(GES_QUIT_TIME);
				break;
			case GES_BACKWARD_FLAG:
				Serial.println("Backward");
				delay(GES_QUIT_TIME);
				break;
			case GES_CLOCKWISE_FLAG:
				Serial.println("Clockwise");
				break;
			case GES_COUNT_CLOCKWISE_FLAG:
				Serial.println("anti-clockwise");
				break;
			default:
				paj7620ReadReg(I2C_ADDRESS2, 1, &data);
				if (data == GES_WAVE_FLAG) {
					Serial.println("wave");
				} else {
					Serial.print(".");
				}
				break;
		}
	}
	delay(100);
}

Troubleshooting