APDS-9960 RGB and Gesture Sensor Module

From Wiki
Jump to: navigation, search

Introduction

APDS-9960 1.jpg APDS-9960 2.jpg
The RGB and Gesture Sensor is a small breakout board with a built in APDS-9960 sensor that offers ambient light and color measuring, proximity detection, and touchless gesture sensing. With this RGB and Gesture Sensor, you are able to control a computer, microcontroller, robot, and so on. It is the same sensor as Samsung Galaxy S5 uses and it is probably one of the best gesture sensors with this price on the market.

APDS-9960

It has many functions, including gesture detection, approaching detection, digital ambient light sensing and so on. It uses an 8-pin package and can be a digital RGB, an ambient light, a short range or a gesture sensing equipment. The device has many ports compatible with I2C, in different colors: red, green, blue, clear (RGBC). The short range and the gesture sensing have infrared LEDs. RGB and ambient light sensing can detect the intensity of light under many light conditions, through many vibration-absorptive materials and the deep tinted window. Besides, integrated UV-IR blocking filter can sense the ambient light and correlated colour temperature accurately.
APDS-9960 3.jpg
APDS-9960 4.jpg

  • Main Features
  • Type: GY-APDS9960-3.3
  • Chip: APDS-9960
  • Power Supply Voltage: 3.3V
  • Communication Mode: IIC communication protocol
  • Size: 20mm x 15.3mm

Pin Description

Pin Description
VL Optional power to the IR LED if PS jumper is disconnected Must be 3.0 – 4.5V
GND Connect to ground.
VCC Used to power the APDS-9960 sensor. Must be 2.4 – 3.6
SDA I²C data
SCL I²C clock
IN External interrupt pin. Active LOW on interrupt event

Working Principle

Gesture detection utilizes four directional photodiodes to sense reflected IR energy (sourced by the integrated LED) to convert physical motion information (i.e. velocity, direction and distance) to a digital information. 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 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.
File:APDS-9960 5.jpg

Experimental Procedures for Arduino

Step 1: Connect the circuit:
APDS-9960 6.jpg
Step 2: Compile and upload the code.

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


// Constants

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

void setup() {

  // Set interrupt pin as input
  pinMode(2, INPUT);

  // 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");
    }
  }
}

After the upload of code is done, please open the serial port, place a gesture on the module, and the serial port will output the gesture you have done.