Search Code

APDS-9960 جیسیچر سینسر کے ساتھ آرڈینو

APDS-9960 جیسیچر سینسر کے ساتھ آرڈینو

APDS-9960 اشارتی سینسر ہاتھ کی اشاروں جیسے سوائپ اور قربت کا پتہ لگانے کی اجازت دیتا ہے۔ اس سبق میں، ہم APDS-9960 کو ایک آردوینو سے جوڑنے اور اشارے کو پہچاننے کے لیے پروگرام کرنے کا طریقہ دکھائیں گے۔ نتیجہ ایک سادہ سیٹ اپ ہوگا جو حرکات کا پتہ لگا سکتا ہے اور انہیں سیرئیل مانیٹر کے ذریعے رپورٹ کر سکتا ہے۔ یہ رہنما آپ کو اشارتی سینسر کے ساتھ شروع کرنے کے لیے درکار وائرنگ اور کوڈ سمجھنے میں مدد کرے گا۔ (ویڈیو میں 00:30 پر)

APDS-9960 gesture sensor module -1

ہارڈویئر کی وضاحت

APDS-9960 ایک ورسٹائل سینسر ہے جو RGB رنگ کی سینسنگ، ماحول کی روشنی کی سینسنگ، قربت کی سینسنگ، اور اشارہ شناخت کی صلاحیتوں کو یکجا کرتا ہے۔ یہ آردوینو کے ساتھ I2C کے ذریعے بات چیت کرتا ہے، جو کم وائرنگ کے ساتھ آسان انضمام کی اجازت دیتا ہے۔ سینسر صرف 3.3V پر کام کرتا ہے، اس لیے یہ ضروری ہے کہ صحیح وولٹیج کی سطح کو یقینی بنایا جائے تاکہ ڈیوائس کو نقصان سے بچایا جا سکے۔ اس تعمیر میں، ہم آردوینو کا استعمال اشارے کے ڈیٹا کو پڑھنے کے لیے کریں گے۔ سینسر اشارے کی معلومات انٹرپٹس کے ذریعے نکالتا ہے، جو آردوینو کو ہاتھ کی حرکات پر فوری ردعمل دینے کی اجازت دیتا ہے۔ APDS-9960 کا آردوینو کے ساتھ انضمام انٹرایکٹو پروجیکٹس کے لیے کئی امکانات کو کھولتا ہے، بشمول اشاروں سے کنٹرول ہونے والے آلات۔

ڈیٹا شیٹ کی تفصیلات

کارخانہ داربراڈکام
پارٹ نمبرAPDS-9960
لاجک/آئی او وولٹیج2.7 - 3.6 وی
سپلائی وولٹیج3.3 وی
آؤٹ پٹ کرنٹ (ہر چینل کے لیے)1 ملی امپر
چوٹی کا کرنٹ (فی چینل)10 mA
PWM فریکوئنسی کی رہنمائی100 ہرٹز
ان پٹ منطق کے تھریشولڈز0.3 x Vڈی ڈی(low), 0.7 x Vشیڈول ڈی ڈی(اونچا)
والیٹج ڈراپ / Rڈی ایس (آن)/ سچائی0.5 V زیادہ سے زیادہ
حرارتی حدود-40 سے +85 °C
پیکج6-پن LGA
نوٹس / مختلف اقسامI2C مواصلات کی حمایت کرتا ہے۔

  • یہ یقینی بنائیں کہ فراہم کردہ وولٹیج 3.6 V سے زیادہ نہ ہو تاکہ نقصان سے بچا جا سکے۔
  • I2C لائنوں پر قابل اعتماد مواصلات کے لیے پل-اپ ریزسٹرس کا استعمال کریں۔
  • سینسر کو درست پڑھائی کے لیے براہ راست دھوپ سے دور رکھیں۔
  • یقینی بنائیں کہ کوڈ میں سینسر کو صحیح طریقے سے شروع کیا گیا ہے۔
  • وکھری کنکشنز کو چیک کریں تاکہ تیرتے ان پٹس سے بچا جا سکے۔

بجلی کی تاروں کی ہدایات

Arduino wiring for APDS9960 Gesture sensor
Arduino wiring for APDS9960 Gesture sensor

APDS-9960 کو آردوئینو سے جوڑنے کے لیے، سب سے پہلے پاور کنیکٹ کریں۔ ایک سرخ تار استعمال کریں تاکہ APDS-9960 کے VCC پن کو آردوئینو کے 3.3V پن سے جوڑا جا سکے۔ اس کے بعد، سینسر کے GND پن کو ایک سیاہ تار کا استعمال کرتے ہوئے آردوئینو کے زمین پن سے جوڑیں۔ اب، I2C مواصلت کے لیے، APDS-9960 کے SDA پن کو آردوئینو کے A4 پن سے جوڑیں۔ اسی طرح، SCL پن کو آردوئینو کے A5 پن سے جوڑیں۔ آخر میں، سینسر کے INT پن کو آردوئینو کے پن 2 سے جوڑیں۔ یہ آردوئینو کو سینسر کی جانب سے پیدا ہونے والے مداخلتوں کا جواب دینے کی اجازت دے گا۔

کوڈ کے نمونے اور گائیڈ

دی گئی کوڈ APDS-9960 سینسر کو ابتدائی شکل دیتا ہے اور آرڈینو کو اشارے پڑھنے کے لیے ترتیب دیتا ہے۔ یہاں ترتیب کے فعل کا ایک مختصر اقتباس ہے:

void setup() {
  pinMode(APDS9960_INT, INPUT);
  Serial.begin(9600);
  attachInterrupt(0, interruptRoutine, FALLING);
  if ( apds.init() ) {
    Serial.println(F("APDS-9960 initialization complete"));
  }
}

اس کٹ میں، ہم سیریل مانیٹر کو شروع کرتے ہیں اور انٹرپٹ پن کو سیٹ کرتے ہیں۔ سینسر کو شروع کیا جاتا ہے، اور کنسول پر ایک تصدیقی پیغام پرنٹ کیا جاتا ہے۔ اس کے بعد، ہم لوپ فنکشن میں اشارات کی جانچ کرتے ہیں:

void loop() {
  if( isr_flag == 1 ) {
    detachInterrupt(0);
    handleGesture();
    isr_flag = 0;
    attachInterrupt(0, interruptRoutine, FALLING);
  }
}

یہاں، لوپ مسلسل اشاروں کی جانچ کرتا ہے۔ جب کوئی اشارہ دریافت ہوتا ہے تو انٹرپٹ کو بند کر دیا جاتا ہے، اور اشارے کو پروسیس کرنے کے لئے `handleGesture` فنکشن کو کال کیا جاتا ہے۔ آخر میں، `handleGesture` فنکشن دریافت شدہ اشاروں کا پروسیس کرتا ہے:

void handleGesture() {
  if ( apds.isGestureAvailable() ) {
    switch ( apds.readGesture() ) {
      case DIR_UP:
        Serial.println("UP");
        break;
      case DIR_DOWN:
        Serial.println("DOWN");
        break;
      // Additional cases...
    }
  }
}

اس فعالیت میں، اشارہ پڑھا جاتا ہے، اور پتہ لگائے گئے سمت کی بنیاد پر متعلقہ کارروائی کی جاتی ہے۔ یہ ہاتھ کی حرکتوں کی بنیاد پر انٹرایکٹو کنٹرول کی اجازت دیتا ہے۔ کوڈ کی مکمل تفہیم کے لیے، براہ کرم مضمون کے نیچے لوڈ کردہ مکمل پروگرام کا حوالہ دیں۔

APDS-9960 gesture sensor -3

ڈیماںٹریشن / کیا توقع رکھیں

جب ترتیب مکمل ہو جائے تو آپ Arduino سے اشارے پڑھنے اور سیرئیل مانیٹر پر شناخت شدہ سمت دکھانے کی توقع کر سکتے ہیں۔ سادہ ٹیسٹ میں شامل ہیں اپنے ہاتھ کو سینسر کے سامنے اوپر، نیچے، بائیں یا دائیں حرکت دینا۔ اگر سب کچھ صحیح طور پر وائرڈ ہے تو آپ سیرئیل مانیٹر پر متعلقہ آؤٹ پٹ دیکھیں گے، جو اشارے کی پہچان کی تصدیق کرے گا۔ تیرتے ان پٹس سے محتاط رہیں، کیونکہ یہ غیر مستقل ریڈنگ کا باعث بن سکتے ہیں (ویڈیو میں 05:20 پر)۔

ویڈیو کی نشانیوں کا وقت

  • 00:00- تعارف
  • 01:15- ہارڈ ویئر کا عمومی جائزہ
  • 03:00- وائرنگ ہدایات
  • 04:30- کوڈ کی وضاحت
  • 06:15- مظاہرہ

تصاویر

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
زبان: 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
زبان: 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");
    }
  }
}

آپ کو جن چیزوں کی ضرورت ہو سکتی ہے

وسائل اور حوالہ جات

ابھی تک کوئی وسائل نہیں۔

فائلیں📁

دیگر فائلیں

  • APDS9960 ڈیٹا شیٹ
    یہ APDS9960 چپ کے لیے ڈیٹا شیٹ ہے۔ اس فائل کو دیکھیں تاکہ اس کے بارے میں مزید جان سکیں۔
    robojax-gesture-APDS9960_datasheet.pdf 0.89 MB
  • APDS9960 Gesture Library
    Arduino 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.zip 0.30 MB
  • APDS9960 Gesture Datasheet
    Datasheet 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.pdf 0.89 MB
  • APDS-9960 Gesture sensor Library
    from Robojax.com
    robojax-gesture-APDS9960-Library.zip 0.30 MB