(1/2) Switching LEDs using Gesture Sensor AP05-9960 module

Overview

A Gesture Sensor AP05-9960 module is a nifty device that has 4 integrated sensors : RGB, Ambient Light, Proximity ,and Gesture.

For this first mini-project, 4 LEDs will be switched on via SWIPE UP, DOWN, LEFT, RIGHT gestures.

Hardware Used

Software Used

  • Arduino IDE

Libraries Used

Adafruit Gesture Sensor Library is used for ease of implementation.

Application Description

For this particular Gesture model, A Bi-directional Logic Level Converter is not needed since it has a built-in 3.3V Regulator, 662k. Double check your Gesture Sensor datasheet if it has an onboard regulator, otherwise you might end up damaging the module.

If you are using the standard Arduino Uno R3, the SDA is connected to the A5 pin, SCL is connected to the A4 pin. In this particular project, the Robotdyn has a dedicated SDA and SCL pin above the AREF pin.

  • VCC = Voltage
  • GND = Ground
  • INT = External Interrupt pin. Usually Active LOW.
  • SDA = I2C Data
  • SCL = I2C Clock

To enable the gesture sensing, put your hand close the sensor (atleast a few centimeters)  for a few seconds. Gesture sensing is limited to swipes in four major directions : up, down, left, and right.

Set-up the Hardware

Code

 

/***************************************************************************
  This is a library for the APDS9960 digital proximity, ambient light, RGB, and gesture sensor

  This sketch puts the sensor in gesture mode and decodes gestures.
  To use this, first put your hand close to the sensor to enable gesture mode.
  Then move your hand about 6" from the sensor in the up -> down, down -> up, 
  left -> right, or right -> left direction.

  Designed specifically to work with the Adafruit APDS9960 breakout
  ----> http://www.adafruit.com/products/3595

  These sensors use I2C to communicate. The device's I2C address is 0x39

  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing products
  from Adafruit!

  Written by Dean Miller for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include "Adafruit_APDS9960.h"
Adafruit_APDS9960 apds;

const int pinUp=8, pinDown=9, pinLeft=10, pinRight=11;
// the setup function runs once when you press reset or power the board
void setup() {
  pinMode(pinUp, OUTPUT);
  pinMode(pinDown, OUTPUT);
  pinMode(pinLeft, OUTPUT);
  pinMode(pinRight, OUTPUT);

  Serial.begin(115200);
  if(!apds.begin()){
    Serial.println("failed to initialize device! Please check your wiring.");
  }
  else Serial.println("Device initialized!");

  //gesture mode will be entered once proximity mode senses something close
  apds.enableProximity(true);
  apds.enableGesture(true);
}

// the loop function runs over and over again forever
void loop() {
  //read a gesture from the device
    uint8_t gesture = apds.readGesture();
    if(gesture == APDS9960_DOWN){
      digitalWrite(pinDown, HIGH);
    }else if(gesture == APDS9960_UP){
      digitalWrite(pinUp, HIGH);
    }else if(gesture == APDS9960_LEFT) {
      digitalWrite(pinLeft, HIGH);
    }else if(gesture == APDS9960_RIGHT){
      digitalWrite(pinRight, HIGH);
    }
}

 

Code Breakdown

 

#include "Adafruit_APDS9960.h" 
Adafruit_APDS9960 apds;

const int pinUp=8, pinDown=9, pinLeft=10, pinRight=11;

The code starts off importing the “Adafruit_APDS9960.h” library to be used in this mini-project. After importing, the library will be declared. The last line initializes the LED pins to be lit up when it registers a gesture.

apds.enableProximity(true); 
apds.enableGesture(true);

As the name implies, it enables the proximity and gestures sensors. The proximity sensor is needed to enter gesture mode.

uint8_t gesture = apds.readGesture();
    if(gesture == APDS9960_DOWN){
      digitalWrite(pinDown, HIGH);
    }else if(gesture == APDS9960_UP){
      digitalWrite(pinUp, HIGH);
    }else if(gesture == APDS9960_LEFT) {
      digitalWrite(pinLeft, HIGH);
    }else if(gesture == APDS9960_RIGHT){
      digitalWrite(pinRight, HIGH);
    }

When there is a gesture being made, it is converted into a value which is recognizable by the microcontroller. In this case, readGesture() fetches the gestured being made and stores it into the variable “gesture”.  Basically, the IF ELSE statements checks whether the variable “gesture” is equal to the gesture being made, and lights the pin accordingly.

Conclusion

The Gesture sensor can sense motion and interpret them as gestures. It works by a using four directional photodiodes to sense the reflected IR light (the violet light shown in the picture below!) to convert gestures into computer readable information.

References

https://learn.adafruit.com/adafruit-apds9960-breakout/arduino-wiring-and-test

The post (1/2) Switching LEDs using Gesture Sensor AP05-9960 module appeared first on CreateLabz.

Apds-9960ArduinoColor sensorGestureGesture sensorKnowledgebaseLight sensorProximity sensor

Leave a comment

All comments are moderated before being published