APDS-9960 Light Sensor

This documentation includes installation guidelines and sample code for your hardware.

Overall Info

The Broadcom APDS-9960 multifunctional sensor is capable of ambient light and RGB light sensing, proximity sensing, and gesture detection.

Sensor Connections

  • SCL: D12.

  • SDA: D11.

  • INT: D7.

  • POWER: 5V, VCC (+3.3V) and GND.

Specifications

APDS-9960's technical specifications are as follows:

  • IR LED Peak Wavelength: 950nm.

  • IR LED Spectrum Width: 30nm.

  • UV and IR Blocking filters.

  • 32 Dataset storage FIFO for gesture sensing.

Arduino Library

Turta_ALSGesture_Sensor library is responsible for reading sensor data.

To use the library on Arduino IDE, add the following #include statement to the top of your sketch.

#include <Turta_ALSGesture_Sensor.h>

Then, create an instance of the Turta_ALSGesture_Sensor class.

Turta_ALSGesture_Sensor als

Now you're ready to access the library by calling the als instance.

Initialization

To initialize the module, call the begin method.

begin()

This method configures the I2C bus and INT pin to read sensor data.

Basic Members

Read Ambient Light

Returns the ambient light value.

int readAmbientLight()
  • Parameters

    • None

  • Returns

    • Int: Ambient light value

Read Ambient and RGB Light

Returns the ambient and RGB light.

void readARGBLight(int a, int r, int g, int b)
  • Parameters

    • Int: a out

    • Int: r out

    • Int: g out

    • Int: b out

  • Returns

    • None

Read Proximity

Returns the raw proximity value.

short readProximity()
  • Parameters

    • None

  • Returns

    • Short: Proximity value

Examples

You can open the examples from Arduino IDE > File > Examples > Examples from Custom Libraries > Turta MKR Sensor Shield > ALS Gesture Sensor. There are two examples of this sensor.

ARGB

This application demonstrates reading ambient light and RGB light values from the sensor.

To run the example:

  1. Open the ARGB sketch from the examples menu.

  2. Select your Arduino MKR series board from the Tools > Board menu.

  3. Select your device's COM port from Tools > Port menu.

  4. Open Serial Monitor from Tools > Serial Monitor.

  5. Select 115.200 baud from the Serial Monitor's status bar.

  6. Upload the code to your device.

Sample Code

ARGB.ino
#include <Turta_ALSGesture_Sensor.h>

// Create ALS Gesture Sensor instance.
Turta_ALSGesture_Sensor als;

void setup() {
  // Initialize ALS Gesture Sensor.
  als.begin();

  // Configure serial port.
  Serial.begin(115200);
  delay(200);
}

void loop() {
  // Read ambient light.
  int resultA = als.readAmbientLight();
  Serial.print("Ambient light: ");
  Serial.println(resultA);

  // Read ARGB light.
  // A: Ambient, R: Red, G: Green, B: Blue light.
  int a, r, g, b;
  als.readARGBLight(a, r, g, b);
  Serial.print("A: ");
  Serial.print(a);
  Serial.print(", R: ");
  Serial.print(r);
  Serial.print(", G: ");
  Serial.print(g);
  Serial.print(", B: ");
  Serial.println(b);
  
  // Print an empty line.
  Serial.println("");

  // Delay 1000ms = 1 seconds.
  delay(1000);
}

Result

After the application is uploaded to the device, it writes ambient light and RGB light values to the Serial Monitor. The example output should be like this:

Ambient light: 156
A: 156, R: 52, G: 57, B: 51

The application runs forever until you clear it from memory.

Proximity

This application demonstrates reading proximity data from the sensor.

To run the example:

  1. Open the Proximity sketch from the examples menu.

  2. Select your Arduino MKR series board from the Tools > Board menu.

  3. Select your device's COM port from Tools > Port menu.

  4. Open Serial Monitor from Tools > Serial Monitor.

  5. Select 115.200 baud from the Serial Monitor's status bar.

  6. Upload the code to your device.

Sample Code

Proximity.ino
#include <Turta_ALSGesture_Sensor.h>

// Create ALS Gesture Sensor instance.
Turta_ALSGesture_Sensor als;

void setup() {
  // Initialize ALS Gesture Sensor.
  als.begin();

  // Configure serial port.
  Serial.begin(115200);
  delay(200);
}

void loop() {
  // Read proximity.
  short resultP = als.readProximity();
  Serial.print("Proximity: ");
  Serial.println(resultP);

  // Print an empty line.
  Serial.println("");

  // Delay 1000ms = 1 seconds.
  delay(1000);
}

Result

After the application is uploaded to the device, it writes proximity data to the Serial Monitor. The example output should be like this:

Proximity: 123

The application runs forever until you clear it from memory.

Troubleshooting

If you're experiencing difficulties while working with your device, please try the following steps.

Problem: When running with battery, proximity and gesture detection functions does not work. Cause: APDS-9960's LED power input requires a high amount of current to operate. Therefore the LED driver is connected to the 5V output of Arduino for proper operation. When you're using a battery, Arduino does not power the 5V output, so the LEDs does not lit. Solution: The proximity and gesture detection functionality does not work with battery power to protect Arduino from Voltage spikes. It is not a malfunction.

Last updated