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.
1
#include <Turta_ALSGesture_Sensor.h>
Copied!
Then, create an instance of the Turta_ALSGesture_Sensor class.
1
Turta_ALSGesture_Sensor als
Copied!
Now you're ready to access the library by calling the als instance.

Initialization

To initialize the module, call the begin method.
1
begin()
Copied!
This method configures the I2C bus and INT pin to read sensor data.

Basic Members

Read Ambient Light

Returns the ambient light value.
1
int readAmbientLight()
Copied!
    Parameters
      None
    Returns
      Int: Ambient light value

Read Ambient and RGB Light

Returns the ambient and RGB light.
1
void readARGBLight(int a, int r, int g, int b)
Copied!
    Parameters
      Int: a out
      Int: r out
      Int: g out
      Int: b out
    Returns
      None

Read Proximity

Returns the raw proximity value.
1
short readProximity()
Copied!
    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
1
#include <Turta_ALSGesture_Sensor.h>
2
3
// Create ALS Gesture Sensor instance.
4
Turta_ALSGesture_Sensor als;
5
6
void setup() {
7
// Initialize ALS Gesture Sensor.
8
als.begin();
9
10
// Configure serial port.
11
Serial.begin(115200);
12
delay(200);
13
}
14
15
void loop() {
16
// Read ambient light.
17
int resultA = als.readAmbientLight();
18
Serial.print("Ambient light: ");
19
Serial.println(resultA);
20
21
// Read ARGB light.
22
// A: Ambient, R: Red, G: Green, B: Blue light.
23
int a, r, g, b;
24
als.readARGBLight(a, r, g, b);
25
Serial.print("A: ");
26
Serial.print(a);
27
Serial.print(", R: ");
28
Serial.print(r);
29
Serial.print(", G: ");
30
Serial.print(g);
31
Serial.print(", B: ");
32
Serial.println(b);
33
34
// Print an empty line.
35
Serial.println("");
36
37
// Delay 1000ms = 1 seconds.
38
delay(1000);
39
}
Copied!
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:
1
Ambient light: 156
2
A: 156, R: 52, G: 57, B: 51
Copied!
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
1
#include <Turta_ALSGesture_Sensor.h>
2
3
// Create ALS Gesture Sensor instance.
4
Turta_ALSGesture_Sensor als;
5
6
void setup() {
7
// Initialize ALS Gesture Sensor.
8
als.begin();
9
10
// Configure serial port.
11
Serial.begin(115200);
12
delay(200);
13
}
14
15
void loop() {
16
// Read proximity.
17
short resultP = als.readProximity();
18
Serial.print("Proximity: ");
19
Serial.println(resultP);
20
21
// Print an empty line.
22
Serial.println("");
23
24
// Delay 1000ms = 1 seconds.
25
delay(1000);
26
}
Copied!
Result
After the application is uploaded to the device, it writes proximity data to the Serial Monitor. The example output should be like this:
1
Proximity: 123
Copied!
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 modified 2yr ago