====== LamaPLC: APDS - Avago ALS and proximity detection sensors with I²C communication ====== {{ :sensor:apds_9960_1.png?120|APDS-9960}} The Avago APDS-9900, APDS-9930, and APDS-9960 are a series of integrated optical sensor modules that primarily offer ambient light sensing (ALS) and proximity detection, with the APDS-9960 adding advanced gesture recognition and RGB color sensing. **Feature Comparison** ^Feature^Avago APDS-9900^Avago APDS-9930^Avago APDS-9960| |Type|Approximates Human Eye Response|Approximates Human Eye Response|Ambient Light and RGB Color Sensing, Proximity Sensing, and Gesture Detection in an Optical Module| |Ambient Light Sensing (ALS)|Yes (Clear & IR channels)|Yes (Clear & IR channels)|Yes (RGBC - Red, Green, Blue, Clear)| |Proximity Detection|Yes|Yes (calibrated to 100mm)|Yes (calibrated to 100mm)| |Gesture Detection|No|No|Yes (Up, Down, Left, Right, etc.)| |RGB Color Sensing|No|No|Yes| |Interface|I²C|I²C|I²C| |Operating Voltage|2.5V – 3.6V|2.2V – 3.6V|2.4V – 3.6V| |Key Application|Simple light/proximity in phones|Power-saving display management|HMI, robotics, complex touchless control| Communication: I²C communication, default address: 0x39 {{page>:tarhal}} ==== Arduino wiring ==== ^Pin^Name^Function| |VL|LED Power|Optional power for the IR LED (if not jumpered to VCC). Usually 3.0V – 4.5V| |VCC|Power|2.4V to 3.6V. (Note: Use 3.3V for Arduino; 5V will damage the chip without a regulator)| |GND|Ground|0V Reference| |SCL|I²C Clock|Serial clock line for I²C communication| |SDA|I²C Data|Serial data line for I²C communication| |INT|Interrupt|Active Low. Goes LOW when a gesture or proximity event is triggered. For gesture sensing, it is highly recommended to connect the INT pin to a hardware interrupt pin (e.g., Digital Pin 2 on Arduino) to ensure the sensor's FIFO buffer is read immediately when data is ready.| ==== Arduino code ==== FOr APDS-9960 running on an Arduino, the SparkFun APDS-9960 Library "SparkFun APDS9960" is the industry standard. #include #include #define APDS9960_INT 2 // Must be an interrupt pin SparkFun_APDS9960 apds = SparkFun_APDS9960(); volatile bool isr_flag = false; void setup() { Serial.begin(9600); pinMode(APDS9960_INT, INPUT); // Initialize interrupt service routine attachInterrupt(digitalPinToInterrupt(APDS9960_INT), interruptRoutine, FALLING); if (apds.init()) { Serial.println(F("APDS-9960 initialization complete")); } else { Serial.println(F("Something went wrong during APDS-9960 init!")); } // Start sensor gesture 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) { detachInterrupt(digitalPinToInterrupt(APDS9960_INT)); handleGesture(); isr_flag = false; attachInterrupt(digitalPinToInterrupt(APDS9960_INT), interruptRoutine, FALLING); } } void interruptRoutine() { isr_flag = true; } 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"); } } } ===== I²C topics on lamaPLC ===== {{topic>i2c}} \\ \\ {{tag>Avago APDS-9900 APDS-9930 APDS-9960 ALS proximity detection gesture_recognition gesture i2c communication sensor arduino code}} This page has been accessed for: Today: {{counter|today}}, Until now: {{counter|total}}