The APDS-9930 is a versatile sensor module that integrates both ambient light sensing (ALS) and proximity detection into a single compact package. This sensor is widely used in mobile devices, smart home automation, and various other applications where it is necessary to measure the intensity of ambient light or detect the presence of an object nearby. Its ability to adjust screen brightness based on environmental light conditions and to enable touchless gesture controls makes it a popular choice for enhancing user experience in consumer electronics.
Pin Number | Name | Description |
---|---|---|
1 | VDD | Power supply (2.4V to 3.6V) |
2 | GND | Ground connection |
3 | SCL | I2C clock line |
4 | SDA | I2C data line |
5 | INT | Interrupt output (active low) |
6 | VL | Optional IR LED power supply for proximity sensor |
To use the APDS-9930 in a circuit, connect the VDD pin to a power supply within the specified voltage range and the GND pin to the ground. The SCL and SDA pins should be connected to the corresponding I2C clock and data lines on a microcontroller, such as an Arduino UNO. If the proximity detection feature is used, an external IR LED can be powered through the VL pin.
#include <Wire.h>
#include <SparkFun_APDS9960.h> // Include the APDS-9960 library
// Instantiate an APDS-9960 object
SparkFun_APDS9960 apds = SparkFun_APDS9960();
void setup() {
Serial.begin(9600);
Wire.begin();
// Initialize APDS-9930 (configure I2C and initial values)
if (apds.init()) {
Serial.println("APDS-9930 initialization complete");
} else {
Serial.println("Something went wrong during APDS-9930 init!");
}
// Adjust the Proximity sensor gain
if (apds.setProximityGain(PGAIN_2X)) {
Serial.println("Proximity gain set to 2X");
}
// Start running the APDS-9930 proximity sensor (no interrupts)
if (apds.enableProximitySensor(false)) {
Serial.println("Proximity sensor is now running");
} else {
Serial.println("Something went wrong during sensor init!");
}
}
void loop() {
uint8_t proximity_data = 0;
// Read the proximity value
if (apds.readProximity(proximity_data)) {
Serial.print("Proximity: ");
Serial.println(proximity_data);
}
delay(250); // Wait for 250 milliseconds before next read
}
Q: Can the APDS-9930 be used outdoors? A: Yes, but direct sunlight may interfere with the ambient light readings. It's best to shield the sensor from direct light.
Q: How can I adjust the range of proximity detection? A: The range can be adjusted by changing the proximity sensor's gain settings through the provided library functions.
Q: What should I do if the sensor is not detected by the microcontroller? A: Check the wiring, ensure that the correct I2C address is used, and verify that the microcontroller's I2C interface is functioning properly.
Q: Is it necessary to use an external IR LED for proximity detection? A: The APDS-9930 has an integrated IR LED for proximity detection. The VL pin is optional and can be used to power an external IR LED if higher power is needed.
For further assistance, consult the APDS-9930 datasheet and the manufacturer's application notes.