Arduino Gesture Sensor APDS 9960

arduino-gesture-control

 

Gesture and Ambient light sensor APDS-9960 from Avago Technologies helps us to make simple and robust Gesture control project. The sensor utilizes four directional photo diodes to sense reflected IR light to convert physical motion Information to a Digital information (simply gesture info). The architecture of the gesture engine features automatic activation (based on Proximity engine results), ambient light subtraction, cross-talk cancelation, dual 8-bit data converters, power saving inter-conversion delay, 32-dataset FIFO, and interrupt-driven I2C-bus communication. The gesture engine accommodates a wide range of mobile device gesturing requirements  simple UP-DOWN-RIGHT-LEFT gestures or more complex gestures can be accurately sensed. Power consumption and noise are minimized with adjustable IR LED timing. (credit Avago Technologies).

Application Note

With this APDS 9960 sensor we can make interaction to Arduino, Microcontroller, Computer, robot etc.. with simple gesture swipe of your hand.

Sensor Breakout board Pinout

apds-9960-pinout

 

Arduino-APDS 9960 Hookup

arduino-apds-9960-hookup

Arduino Code

 

#include <Wire.h>
#include <SparkFun_APDS9960.h>

// Pins
#define APDS9960_INT    2 // Needs to be an interrupt pin

// Constants

// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;

void setup() {

  // Initialize Serial port
  Serial.begin(9600);
  Serial.println();
  Serial.println(F("--------------------------------"));
  Serial.println(F("SparkFun APDS-9960 - GestureTest"));
  Serial.println(F("--------------------------------"));

  // Initialize interrupt service routine
  attachInterrupt(0, interruptRoutine, FALLING);

  // Initialize APDS-9960 (configure I2C and initial values)
  if ( apds.init() ) {
    Serial.println(F("APDS-9960 initialization complete"));
  } else {
    Serial.println(F("Something went wrong during APDS-9960 init!"));
  }

  // Start running the APDS-9960 gesture sensor engine
  if ( apds.enableGestureSensor(true) ) {
    Serial.println(F("Gesture sensor is now running"));
  } else {
    Serial.println(F("Something went wrong during gesture sensor init!"));
  }
}

void loop() {
  if( isr_flag == 1 ) {
    detachInterrupt(0);
    handleGesture();
    isr_flag = 0;
    attachInterrupt(0, interruptRoutine, FALLING);
  }
}

void interruptRoutine() {
  isr_flag = 1;
}

void handleGesture() {
    if ( apds.isGestureAvailable() ) {
    switch ( apds.readGesture() ) {
      case DIR_UP:
        Serial.println("UP");
        break;
      case DIR_DOWN:
        Serial.println("DOWN");
        break;
      case DIR_LEFT:
        Serial.println("LEFT");
        break;
      case DIR_RIGHT:
        Serial.println("RIGHT");
        break;
      case DIR_NEAR:
        Serial.println("NEAR");
        break;
      case DIR_FAR:
        Serial.println("FAR");
        break;
      default:
        Serial.println("NONE");
    }
  }
}

Resources

APDS 9960 – Arduino Library

APDS 9960 – Datasheet 

3 Comments

  1. CL February 3, 2017 Reply
    • Franco February 18, 2017 Reply
      • Marko September 26, 2017 Reply

Add a Comment

Your email address will not be published. Required fields are marked *