Introduction

The sensor module uses the APDS-9960 chip, this is a single 8 pin package digital RGB, ambient light, short and gesture sensor device. The device is compatible with I2C interface, with an interruput pin. And short-range and gestures are measured with infrared LED. RGB and environmental light perception measurement function could work under a variety of light conditions, such as covering by a variety of damping materials including a piece of dark glass. In addition, the integrated UV-IR shading filter can realize ambient light and color temperature detecting.

Specification

Layout

RGB and Gesture Sensor OPSITIVE RGB and Gesture Sensor REVERSE
名称 功能描述
SDA I2C DATA PORT
SCL I2C CLOCK PORT
GND GND
VCC VCC
INT Interrupt Output

Tutorial

We will use a simple example to teach you how to use the gesture Sensor. Our goal is to make the sensor to detect gestures up and down around the waving.

Requirements

Connection Diagram

SEN0187-CONNECT.png

Sensor Pin UNO Pin
VCC 5V
GND GND
SCL SCL
SDA SDA
INT 2

How to use

In this section, we will use a simple experiment to teach you how to use our gesture sensor. Our goal is to get the sensor detect the gesture UP, DOWN, left and right. Here we begin.

Codes download

Click to download library files Arduino Library Installation Tutorial Next, we need to open the ARDUINO IDE, and copy the following simple code to the IDE window. Then select the right serial port and board (Arduino UNO). Wave your hand in front of the sensor, see what happen on the serial port.

Sample Code

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

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

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("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 ) {
    handleGesture();
      if(digitalRead(APDS9960_INT) == 0){
      apds.init();
      apds.enableGestureSensor(true);
    }

    isr_flag = 0;
  }
}

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

Other functions

This sensor not only support gesture recognition, but also the range, ambient light and RGB color detecting. The specific examples can be found in the library EXAMPLES folder. so you can also develop other application according to your requirement.

Protocol/Library Explanation

I2C Protocol

Trouble Shooting

Any question and more cool ideas to share, please visit DFRobot Forum

More

Schematic APDS9960 DataSheet Arduino library

DFshopping_car1.png Get SEN0187 RGB and Gesture Sensor from DFRobot Store or DFRobot Distributor.