SEN0187

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
Download and install the RGB and Gesture Sensor Library:
Click to download library files
https://github.com/Arduinolibrary/DFRobot_RGB_and_gesture_sensor/raw/master/SparkFun_APDS
9960.zip
Arduino Library Installation Tutorial https://www.arduino.cc/en/Guide/Libraries#.UxU8mdzF9H0
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
1 #include <Wire.h>
2 #include <APDS9960.h>
3
4 // Pins
5 #define APDS9960_INT 2 // Needs to be an interrupt pin
6
7 APDS9960 apds = APDS9960();
8 int isr_flag = 0;
9
10 void setup() {
11
12 // Initialize Serial port
13 Serial.begin(9600);
14 Serial.println();
15 Serial.println(F("--------------------------------"));
16 Serial.println(F("APDS-9960 - GestureTest"));
17 Serial.println(F("--------------------------------"));
18
19 // Initialize interrupt service routine
20 attachInterrupt(0, interruptRoutine, FALLING);
21
22 // Initialize APDS-9960 (configure I2C and initial values)
23 if ( apds.init() ) {
24 Serial.println(F("APDS-9960 initialization complete"));
25 } else {
26 Serial.println(F("Something went wrong during APDS-9960 init!"));
27 }
28
29 // Start running the APDS-9960 gesture sensor engine
30 if ( apds.enableGestureSensor(true) ) {
31 Serial.println(F("Gesture sensor is now running"));
32 } else {
33 Serial.println(F("Something went wrong during gesture sensor init!"));
34 }
35 }
36
37 void loop() {
38 if( isr_flag == 1 ) {
39 handleGesture();
40 if(digitalRead(APDS9960_INT) == 0){
41 apds.init();
42 apds.enableGestureSensor(true);
43 }
44
45 isr_flag = 0;
46 }
47 }
48
49 void interruptRoutine() {
50 isr_flag = 1;
51 }
52
53 void handleGesture() {
54 if ( apds.isGestureAvailable() ) {
55 switch ( apds.readGesture() ) {
56 case DIR_UP:
57 Serial.println("UP");
58 break;
59 case DIR_DOWN:
60 Serial.println("DOWN");
61 break;
62 case DIR_LEFT:
63 Serial.println("LEFT");
64 break;
65 case DIR_RIGHT:
66 Serial.println("RIGHT");
67 break;
68 case DIR_NEAR:
69 Serial.println("NEAR");
70 break;
71 case DIR_FAR:
72 Serial.println("FAR");
73 break;
74 default:
75 Serial.println("NONE");
76 }
77 }

SEN0187

Mfr. #:
Manufacturer:
DFRobot
Description:
Distance Sensor Modules RGB and Gesture Sensor
Lifecycle:
New from this manufacturer.
Delivery:
DHL FedEx Ups TNT EMS
Payment:
T/T Paypal Visa MoneyGram Western Union

Products related to this Datasheet