Translate

Modul dan Sensor Gesture Tangan APDS 9960

Modul dan Sensor Gesture Tangan APDS 9960

Mau Beli ??
Harga = Rp. 875.000,00


             Kali ini saya mau menjelaskan mengenai modul baru keluaran september yaitu Y-GESTURE APDS yang mana memiliki fitur utama pendeteksi gerakan tangan, spesifikasi gerakan tangan yang dideteksi yaitu ada enam arah, ke atas, bawah, kiri, kanan, jauh dan dekat. Modul ini menggunakan mikrokontroller ATMEGA328 sebagai penerjemah output sensor APDS 9960, sehingga keluaran dari modul ini adalah data serial berupa tulisan UP-DOWN-LEFT-RIGHT-NEAR-FAR dan juga ada LED yang akan menyala mewakili dari gerakan tangan yang terdeteksi. Untuk aplikasinya yaitu untuk kontrol slide presentasi menggunakan gesture tangan, kontrol robot atau berkaki, pengatur arah gerak motor servo, pengatur arah gerak motor DC dan lainnya.   



 a. Skema Hardware






 b. Sensor APDS 9960






 c. Program Y-GESTURE APDS

#include <Wire.h>
#include <SparkFun_APDS9960.h>

// Pins
#define APDS9960_INT    2 // Needs to be an interrupt pin

// Constants

// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;

int merah1 = 10;
int merah2 = 12;
int kuning = 8;
int hijau = 9;
int biru = 11;
int putih = 13;


void setup() {
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(11, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(13, OUTPUT);
  pinMode(A0, OUTPUT);
 
  // Set interrupt pin as input
  pinMode(APDS9960_INT, INPUT);

  // Initialize Serial port
  Serial.begin(9600);
  Serial.println();
  Serial.println(F("--------------------------------"));
  Serial.println(F("Y-GESTURE APDS - 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");
        digitalWrite(8, LOW);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(13, HIGH);
        digitalWrite(A0, HIGH);
      
        break;
      case DIR_DOWN:
        Serial.println("DOWN");
        digitalWrite(8, HIGH);
        digitalWrite(9, LOW);
        digitalWrite(10, HIGH);
        digitalWrite(11, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(13, HIGH);
        digitalWrite(A0, HIGH);
        break;
      case DIR_LEFT:
        Serial.println("LEFT");
        digitalWrite(8, HIGH);
        digitalWrite(9, HIGH);
        digitalWrite(10, LOW);
        digitalWrite(11, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(13, HIGH);
        digitalWrite(A0, HIGH);
        break;
      case DIR_RIGHT:
        Serial.println("RIGHT");
        digitalWrite(8, HIGH);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, LOW);
        digitalWrite(12, HIGH);
        digitalWrite(13, HIGH);
        digitalWrite(A0, HIGH);
        break;
      case DIR_NEAR:
        Serial.println("NEAR");
        digitalWrite(8, HIGH);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, HIGH);
        digitalWrite(12, LOW);
        digitalWrite(13, HIGH);
        digitalWrite(A0, LOW);
        break;
      case DIR_FAR:
        Serial.println("FAR");
        digitalWrite(8, HIGH);
        digitalWrite(9, HIGH);
        digitalWrite(10, HIGH);
        digitalWrite(11, HIGH);
        digitalWrite(12, HIGH);
        digitalWrite(13, LOW);
        digitalWrite(A0, HIGH);
        break;
      default:
        Serial.println("NONE");
    }
  }
}





 d. VIDEO HASILNYA











No comments:

Post a Comment