APDS-9960 Gesture Sensor with Arduino

APDS-9960 Gesture Sensor with Arduino

The APDS-9960 gesture sensor allows for the detection of hand gestures such as swipes and proximity. In this tutorial, we will demonstrate how to connect the APDS-9960 to an Arduino and program it to recognize gestures. The outcome will be a simple setup that can detect movements and report them via the serial monitor. This guide will help you understand the wiring and code needed to get started with the gesture sensor. (in video at 00:30)
APDS-9960 gesture sensor module -1

Hardware Explained

The APDS-9960 is a versatile sensor that combines RGB color sensing, ambient light sensing, proximity sensing, and gesture detection capabilities. It communicates with the Arduino via I2C, which allows for easy integration with minimal wiring. The sensor only operates at 3.3V, making it essential to ensure proper voltage levels to avoid damaging the device. In this build, we will use the Arduino to read gesture data. The sensor outputs gesture information through interrupts, which allows the Arduino to respond promptly to hand movements. The integration of the APDS-9960 with the Arduino opens up many possibilities for interactive projects, including gesture-controlled devices.

Datasheet Details

ManufacturerBroadcom
Part numberAPDS-9960
Logic/IO voltage2.7 - 3.6 V
Supply voltage3.3 V
Output current (per channel)1 mA
Peak current (per channel)10 mA
PWM frequency guidance100 Hz
Input logic thresholds0.3 x VDD (low), 0.7 x VDD (high)
Voltage drop / RDS(on) / saturation0.5 V max
Thermal limits-40 to +85 °C
Package6-pin LGA
Notes / variantsSupports I2C communication

  • Ensure the supply voltage does not exceed 3.6 V to prevent damage.
  • Use pull-up resistors on the I2C lines for reliable communication.
  • Keep the sensor away from direct sunlight for accurate readings.
  • Make sure to initialize the sensor correctly in the code.
  • Check the wiring connections to avoid floating inputs.

Wiring Instructions

Arduino wiring for APDS9960 Gesture sensor
Arduino wiring for APDS9960 Gesture sensor
To wire the APDS-9960 to the Arduino, start by connecting the power. Use a red wire to connect the VCC pin of the APDS-9960 to the 3.3V pin on the Arduino. Next, connect the GND pin on the sensor to a ground pin on the Arduino using a black wire. Now, for the I2C communication, connect the SDA pin of the APDS-9960 to the Arduino's A4 pin. Similarly, connect the SCL pin to the A5 pin on the Arduino. Lastly, connect the INT pin of the sensor to pin 2 on the Arduino. This will allow the Arduino to respond to interrupts generated by the sensor.

Code Examples & Walkthrough

The provided code initializes the APDS-9960 sensor and sets up the Arduino to read gestures. Here is a brief excerpt of the setup function:
void setup() {
  pinMode(APDS9960_INT, INPUT);
  Serial.begin(9600);
  attachInterrupt(0, interruptRoutine, FALLING);
  if ( apds.init() ) {
    Serial.println(F("APDS-9960 initialization complete"));
  }
}
In this snippet, we initialize the serial monitor and set the interrupt pin. The sensor is initialized, and a confirmation message is printed to the console. Next, we check for gestures in the loop function:
void loop() {
  if( isr_flag == 1 ) {
    detachInterrupt(0);
    handleGesture();
    isr_flag = 0;
    attachInterrupt(0, interruptRoutine, FALLING);
  }
}
Here, the loop continuously checks for gestures. When a gesture is detected, the interrupt is disabled, and the `handleGesture` function is called to process the gesture. Finally, the `handleGesture` function processes the detected gestures:
void handleGesture() {
  if ( apds.isGestureAvailable() ) {
    switch ( apds.readGesture() ) {
      case DIR_UP:
        Serial.println("UP");
        break;
      case DIR_DOWN:
        Serial.println("DOWN");
        break;
      // Additional cases...
    }
  }
}
In this function, the gesture is read, and the corresponding action is taken based on the detected direction. This allows for interactive control based on hand movements. For a complete understanding of the code, please refer to the full program loaded below the article.

Demonstration / What to Expect

When the setup is complete, you can expect the Arduino to read gestures and display the detected direction on the serial monitor. Simple tests include moving your hand up, down, left, or right in front of the sensor. If everything is wired correctly, you should see the corresponding output on the serial monitor, confirming the gesture recognition. Be cautious of floating inputs, as they can lead to inconsistent readings (in video at 05:20).

Video Timestamps

  • 00:00 - Introduction
  • 01:15 - Hardware Overview
  • 03:00 - Wiring Instructions
  • 04:30 - Code Walkthrough
  • 06:15 - Demonstration
APDS-9960 gesture sensor -3

Images

APDS-9960 gesture sensor module -2
APDS-9960 gesture sensor module -2
APDS-9960 gesture sensor module -1
APDS-9960 gesture sensor module -1
APDS-9960 gesture sensor -3
APDS-9960 gesture sensor -3
Arduino wiring for APDS9960 Gesture sensor
Arduino wiring for APDS9960 Gesture sensor
1-Code for an APDS-9960 gesture sensor for Arduino
Language: C++
2-Source code for controlling a servo with your hand
Language: C++
Copied!

Resources & references

No resources yet.

Files📁

Other files