Arduino(12): Proximity and Attitude Sensing Module APDS-9930

When I purchased this module on the Internet, the seller mistakenly sold me APDS-9930 as APDS-9960. Because there is no model number 9930 or 9960 on the module, I tried to test the gesture sensing program, but it was unsuccessful. . Later, I checked the data and found that the two modules are almost the same. The only difference is that the gesture sensing function can work normally after switching to the APDS-9930 program. I bought the APDS-9960 to control the arrow direction of the LED lights with gesture sensing, but I can’t do it temporarily due to a module error. Just take this opportunity to learn about the function and usage of APDS-9930 proximity and attitude sensing module. Another article will implement the APDS-9960 RGB non-contact gesture detection and sensing function.


APDS-9930 is an ambient light sensor (ALS) with I2C interface and a proximity sensor with IR LED, in a single 8-pin package. The ambient light sensor uses dual photodiodes to approximate the response of the human eye with a low illumination performance of 0.01 lux. This high sensitivity allows the device to operate behind darkened glass. The proximity sensor can detect objects up to 100 mm in size. From bright sunlight to dark rooms, the proximity detection function can operate normally. A micro-optical lens is added in the module, which can efficiently send and receive infrared energy, thereby reducing the total power consumption.
APDS-9930 specifications:
  • Optical module integrating ALS, infrared LED and proximity detector
  • Ambient Light Sensing (ALS, Ambient Light Sensing) approximates the visual response of the human eye
  • Programmable interrupt function with upper and lower thresholds
  • Up to 16-bit resolution
  • High sensitivity of operation behind dark glass
  • 0.01lux low lumen performance
  • Proximity detection is fully calibrated to 100 mm detection
  • The program range is from 2.7 milliseconds to more than 8 seconds
  • Provide dedicated interrupt pins

[Install APDS9930 Library]

APDS9930 library is used to read data from APDS-9930 ambient light and proximity sensor. This implementation requires the following libraries to be installed:

[Material]

  • Arduino Uno x 1
  • APDS-9930 color, non-contact gesture detection sensor module x1
  • LED x 1
  • Connection wire x 4

[Wiring diagram]

Arduino UnoAPDS-9930其他
3.3VVCC-
GNDGND-
A5SCL-
A4SDA-
GND-接LED負極
D10-接LED正極




[Code]

The following is a reference example in the Depau/APDS9930 library. When an object is close to the APDS-9930 sensor, the LED light connected to D10 will detect when the object is approaching, the LED light will dim, and when it is far away from the sensor, the LED The light turns on.
/****************************************************************
AmbientLightLED.ino
Source:Depau/APDS9930
****************************************************************/

#define PWM_LED_PIN       10
#define DUMP_REGS

#include <Wire.h>
#include <APDS9930.h>

// Global Variables
APDS9930 apds = APDS9930();
float ambient_light = 0; // can also be an unsigned long
uint16_t ch0 = 0;
uint16_t ch1 = 1;
float max_light = 0;

void setup() {
  //analogReference(EXTERNAL);
  pinMode(PWM_LED_PIN, OUTPUT);
  
  // Initialize Serial port
  Serial.begin(9600);
  Serial.println();
  Serial.println(F("--------------------------------"));
  Serial.println(F("APDS-9930 - Ambient light sensor"));
  Serial.println(F("--------------------------------"));
  
  // Initialize APDS-9930 (configure I2C and initial values)
  if ( apds.init() ) {
    Serial.println(F("APDS-9930 initialization complete"));
  } else {
    Serial.println(F("Something went wrong during APDS-9930 init!"));
  }
  
  // Start running the APDS-9930 light sensor (no interrupts)
  if ( apds.enableLightSensor(false) ) {
    Serial.println(F("Light sensor is now running"));
  } else {
    Serial.println(F("Something went wrong during light sensor init!"));
  }

#ifdef DUMP_REGS
  /* Register dump */
  uint8_t reg;
  uint8_t val;

  for(reg = 0x00; reg <= 0x19; reg++) {
    if( (reg != 0x10) && \
        (reg != 0x11) )
    {
      apds.wireReadDataByte(reg, val);
      Serial.print(reg, HEX);
      Serial.print(": 0x");
      Serial.println(val, HEX);
    }
  }
  apds.wireReadDataByte(0x1E, val);
  Serial.print(0x1E, HEX);
  Serial.print(": 0x");
  Serial.println(val, HEX);
#endif

  // Wait for initialization and calibration to finish
  delay(500);
}

void loop() {
  
  // Read the light levels (ambient, red, green, blue)
  if (  !apds.readAmbientLightLux(ambient_light) ||
        !apds.readCh0Light(ch0) || 
        !apds.readCh1Light(ch1) ) {
    Serial.println(F("Error reading light values"));
  } else {
    Serial.print(F("Ambient: "));
    Serial.print(ambient_light);
    Serial.print(F("  Ch0: "));
    Serial.print(ch0);
    Serial.print(F("  Ch1: "));
    Serial.println(ch1);

    if ( ambient_light > max_light ) {
      max_light = ambient_light;
    }
    ambient_light = map(ambient_light, 0, max_light, 0, 1023); //將測得的值換算成1023的比例給D10 PWM
    analogWrite(PWM_LED_PIN, ambient_light);
  }
  
  // Wait 1 second before next reading
  delay(100);
}

[Result]




[Reference]


Post a Comment

Previous Post Next Post