APDS-9960 Gesture Sensor pẹlu Arduino
Sensọ APDS-9960 gesture ngbani fun wiwa awọn ọwọ gestures bii swipes ati isunmọ. Ninu ẹkọ yii, a yoo ṣe afihan bi a ṣe le sopọ APDS-9960 si Arduino ati ki o ṣe eto rẹ lati da awọn ọwọ mọ. Abajade yoo jẹ eto ti o rọrun ti o le rii awọn iṣipopada ati ṣe ijabọ wọn nipasẹ atẹle serial. Itọsọna yii yoo ran ọ lọwọ lati loye okun ati koodu ti o nilo lati bẹrẹ pẹlu sensọ gesture. (ninu fidio ni 00:30)
Ohun elo Ti Ṣalaye
APDS-9960 jẹ sensọ ti o ni ọpọlọpọ iṣẹ ti o ṣajọpọ imọ awọ RGB, imọ ina ibaramu, imọ isunmọ, ati awọn agbara wiwa gesture. O ṣe ibaraẹnisọrọ pẹlu Arduino nipasẹ I2C, eyiti o gba laaye fun isopọpọ irọrun pẹlu okun ti o kere ju. Sensọ naa n ṣiṣẹ nikan ni 3.3V, ti o jẹ ki o ṣe pataki lati rii daju awọn ipele folti to tọ lati yago fun ibajẹ ẹrọ naa. Ninu ikole yii, a yoo lo Arduino lati ka data gesture. Sensọ naa njade alaye gesture nipasẹ awọn idilọwọ, eyiti o gba Arduino laaye lati dahun ni kiakia si awọn iṣipopada ọwọ. Isopọpọ APDS-9960 pẹlu Arduino ṣii ọpọlọpọ awọn aye fun awọn iṣẹ akanṣe ibaraenisepo, pẹlu awọn ẹrọ ti a ṣakoso nipasẹ gesture.Awọn Alaye Datasheet
| Olupese | Broadcom |
|---|---|
| Nọmba apakan | APDS-9960 |
| Folti Logic/IO | 2.7 - 3.6 V |
| Folti ipese | 3.3 V |
| Iwọn iṣelọpọ (fun ikanni) | 1 mA |
| Iwọn giga (fun ikanni) | 10 mA |
| Itọsọna igbohunsafẹfẹ PWM | 100 Hz |
| Awọn ipele ila-ọna titẹ sii | 0.3 x VDD (low), 0.7 x VDD (high) |
| Idinku folti / RDS(on) / saturation | 0.5 V max |
| Awọn opin igbona | -40 to +85 °C |
| Package | 6-pin LGA |
| Awọn akọsilẹ / awọn iyatọ | Ṣe atilẹyin ibaraẹnisọrọ I2C |
- Rii daju pe folti ipese ko kọja 3.6 V lati ṣe idiwọ ibajẹ.
- Lo awọn resistors fifa soke lori awọn laini I2C fun ibaraẹnisọrọ igbẹkẹle.
- Jeki sensọ kuro ni imọlẹ oorun taara fun awọn kika deede.
- Rii daju pe o ti bẹrẹ sensọ naa ni deede ninu koodu.
- Ṣayẹwo awọn asopọ okun lati yago fun awọn titẹ sii ti o ṣan.
Awọn Ilana Okun

Awọn Apeere Koodu & Itọsọna
Koodu ti a pese ṣe ipilẹṣẹ sensọ APDS-9960 ati ṣeto Arduino lati ka awọn gesture. Eyi ni apeere kukuru ti iṣẹ setup:void setup() {
pinMode(APDS9960_INT, INPUT);
Serial.begin(9600);
attachInterrupt(0, interruptRoutine, FALLING);
if ( apds.init() ) {
Serial.println(F("APDS-9960 initialization complete"));
}
}
Ninu apakan yii, a ṣe ipilẹṣẹ atẹle serial ati ṣeto pinni idilọwọ. Sensọ naa ti bẹrẹ, ati pe a tẹ ifiranṣẹ ijẹrisi si console.
Nigbamii, a ṣayẹwo awọn gesture ninu iṣẹ loop:
void loop() {
if( isr_flag == 1 ) {
detachInterrupt(0);
handleGesture();
isr_flag = 0;
attachInterrupt(0, interruptRoutine, FALLING);
}
}
Nibi, loop naa n ṣayẹwo awọn gesture nigbagbogbo. Nigbati a ba rii gesture, a ṣe idilọwọ idilọwọ, ati pe a pe iṣẹ `handleGesture` lati ṣe ilana gesture naa.
Nikẹhin, iṣẹ `handleGesture` ṣe ilana awọn gesture ti a rii:
void handleGesture() {
if ( apds.isGestureAvailable() ) {
switch ( apds.readGesture() ) {
case DIR_UP:
Serial.println("UP");
break;
case DIR_DOWN:
Serial.println("DOWN");
break;
// Awọn ọran afikun...
}
}
}
Ninu iṣẹ yii, a ka gesture naa, ati pe a ṣe iṣe ti o baamu da lori itọsọna ti a rii. Eyi gba laaye fun iṣakoso ibaraenisepo da lori awọn iṣipopada ọwọ.
Fun oye pipe ti koodu naa, jọwọ tọka si eto kikun ti a kojọpọ ni isalẹ nkan naa.
Ifihan / Ohun Ti O Ṣe Reti
Nigbati eto ba ti pari, o le reti pe Arduino yoo ka awọn gesture ati ṣe afihan itọsọna ti a rii lori atẹle serial. Awọn idanwo ti o rọrun pẹlu gbigbe ọwọ rẹ soke, isalẹ, osi, tabi ọtun ni iwaju sensọ. Ti ohun gbogbo ba ti sopọ ni deede, o yẹ ki o rii iṣelọpọ ti o baamu lori atẹle serial, ti o jẹrisi idanimọ gesture. Ṣọra fun awọn titẹ sii ti o ṣan, nitori wọn le ja si awọn kika aiṣedeede (ninu fidio ni 05:20).Awọn Akoko Fidio
- 00:00 - Ifihan
- 01:15 - Akopọ Ohun elo
- 03:00 - Awọn Ilana Okun
- 04:30 - Itọsọna Koodu
- 06:15 - Ifihan

1-Code for an APDS-9960 gesture sensor for Arduino
Ede: C++
/*
* Code for APDS-9960 Gesture sensor for Arduino
* This code is to detect gestures of your hand, either moving it up, down, left, or right; other gestures.
* can be detected and used to control something else.
* Watch the APDS-9960 Gesture sensor video https://youtu.be/qzSgZV_fbxI
* Get this code from https://robojax.com
* Code used in video by Ahmad Shamshiri for Robojax.com
* on December 31, 2016, at 6:53 AM in Ajax, Ontario, Canada
* Permission granted to share this code, given that this
* note is kept with the code.
* Disclaimer: this code is "AS IS" and for educational purposes only.
GestureTest.ino
APDS-9960 RGB and Gesture Sensor
Shawn Hymel @ SparkFun Electronics
May 30, 2014
https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor
Tests the gesture sensing abilities of the APDS-9960. Configures
APDS-9960 over I2C and waits for gesture events. Calculates the
direction of the swipe (up, down, left, right) and displays it
on a serial console.
To perform a NEAR gesture, hold your hand
far above the sensor and move it close to the sensor (within 2
inches). Hold your hand there for at least 1 second and then move it
away.
To perform a FAR gesture, hold your hand within 2 inches of the
sensor for at least 1 second and then move it away (out of
range) of the sensor.
Hardware Connections:
IMPORTANT: The APDS-9960 can only accept 3.3V!
Arduino Pin APDS-9960 Board Function
3.3V VCC Power
GND GND Ground
A4 SDA I2C Data
A5 SCL I2C Clock
2 INT Interrupt
Resources:
Include Wire.h and SparkFun_APDS-9960.h
Development environment specifics:
Written in Arduino 1.0.5
Tested with SparkFun Arduino Pro Mini 3.3V
This code is beerware; if you see me (or any other SparkFun
employee) at the local, and you've found our code helpful, please
buy us a round!
Distributed as-is; no warranty is given.
***************************************************************
*/
#include <Wire.h>
#include <SparkFun_APDS9960.h>
Servo myservo; // create servo object to control a servo
// Pins
#define APDS9960_INT 2 // Needs to be an interrupt pin
// Constants
// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;
void setup() {
// Set interrupt pin as input
pinMode(APDS9960_INT, 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");
}
}
}
2-Source code for controlling a servo with your hand
Ede: C++
/****************************************************************
Modified for RoboJax by A.B.S. on May 09, 2017
in Ajax, Ontario, Canada. www.RoboJax.com
Original Source:
APDS-9960 RGB and Gesture Sensor
Shawn Hymel @ SparkFun Electronics
May 30, 2014
https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor
Distributed as-is; no warranty is given.
****************************************************************/
#include <Wire.h>
// added by RoboJax
#include <Servo.h>
#include <SparkFun_APDS9960.h>
Servo myservo; // create servo object to control a servo // added by RoboJax
// Pins
#define APDS9960_INT 2 // Needs to be an interrupt pin
// Constants
// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;
void setup() {
myservo.attach(9); // attaches the servo on pin 9 to the servo object
// Set interrupt pin as input
pinMode(APDS9960_INT, 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");
myservo.write(180); // added by RoboJax
break;
case DIR_RIGHT:
Serial.println("RIGHT");
myservo.write(0); // added by RoboJax
break;
case DIR_NEAR:
Serial.println("NEAR");
break;
case DIR_FAR:
Serial.println("FAR");
break;
default:
Serial.println("NONE");
}
}
}
Ohun ti o le nilo
-
Amazon
-
eBay
-
AliExpressPurchase APDS-9960 gesture sensor from AliExpresss.click.aliexpress.com
Orisun & itọkasi
Ko si awọn orisun sibẹsibẹ.
Fáìlìs📁
Awọn faili miiran
-
APDS9960 Iwe alayeeleyi ni iwe alaye fun APDS9960 chip. wo iwe yi lati kẹkọọ diẹ sii nipa rẹ.
robojax-gesture-APDS9960_datasheet.pdf0.89 MB -
APDS9960 Gesture LibraryArduino library for the APDS9960 gesture, proximity, and color sensor. Provides functions to initialize the sensor, read gesture data, and configure detection thresholds. Supports I2C interface and operates at 3.3V.
robojax-APDS9960-gesture-library.zip0.30 MB -
APDS9960 Gesture DatasheetDatasheet for the APDS9960 digital proximity, ambient light, RGB and gesture sensor. Features I2C interface, gesture detection with directional output, and operates at 2.4-3.6V.
robojax-APDS9960-gesture-datasheet.pdf0.89 MB -