This module consists of ambient light , IR and proximity sensors. The detection distance is up to 100 mm. The APDS-9930 sensor measures the ambient light.
This sensor can also detect 0.01 Lux brightness in the dark. It can also be used behind dark glass like a mobile screen. For example, it turns off the touch screen during voice calls when your ear is close to the screen.
This sensor can be used to adjust the brightness of mobile backlight and the appropriate light response for various applications.
Circuit Diagram
Components Required
Arduino Uno - 1 no
LCD 16x2 I2C - 1 no
APDS-9930 - 1no
APDS-9930 Non-contact proximity and Ambient Light sensor
APDS-9930 is a digital I2C compatible interface ambient light sensor (ALS) and proximity sensor with IR LED in a single 8-pin package. The ambient light sensor utilizes dual photodiodes to approximate the human eye response with a low lux performance at 0.01 lux.
This high sensitivity allows for the device to operate behind a darkened glass. The proximity sensor is fully calibrated to detection of objects to 100 mm thus eliminating the need for factory calibration of the end equipment or sub-assembly. The proximity detection feature operates well from bright sunlight to dark rooms. The addition of the micro-optics lenses within the module, provide highly efficient transmission and reception of infrared energy which lowers overall power dissipation. In addition, an internal state machine provides the ability to put the device into a low power mode in between ALS and proximity measurements providing very low average power consumption
Specifications and Features :
Optical modules integrated with ALS, infrared LEDs and proximity detectors
Ambient Light Sensing (ALS)
Approximate human visual response
Programmable interrupt capability with upper and lower thresholds
Up to 16-bit resolution
High sensitivity operation behind dark glass
01lux low lumen performance
Proximity detection
Fully calibrated to 100 mm detection
Integrated infrared LED and synchronous LED driver
Eliminates factory calibration of the proximity sensor
Programmable wait timer
Wait state power consumption – 90μA typical
Programmable range from 2.7 ms to more than 8 seconds
I2C interface compatible
Up to 400kHz (I2C fast mode)
Dedicated interrupt pin
Sleep Mode Power – 2.2μA typical
Small package 3.94 (L) x 2.36 (W) x 1.35 (H) mm
Applications :
Adjustable light mobile phone back light
Notebook / display security
automatically enabled hands-free mode
Automatic menu pop up
Digital camera eye sensor
Installing the Arduino Library
LiquidCrystal_I2C.h : you need to Download and install the LiquidCrystal_I2C library.
You need to install the following library –Download This is an ambient light example, there are also proximity examples
Follow the next steps to install those libraries.
In your Arduino IDE, to install the libraries go to Sketch > Include Library > Add .ZIP library… and select the library you’ve just downloaded.
After installing the required libraries, copy the following code to your Arduino IDE.
Subscribe and Download code.
Arduino code:
#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;
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
void setup() {
//analogReference(EXTERNAL);
// 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);
// Wait for initialization and calibration to finish
delay(500);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
}
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);
lcd.setCursor(0,0);
lcd.print("amb Light:");
lcd.print(ambient_light);
lcd.setCursor(0,1);
lcd.print("ch0:");
lcd.print(ch0);
lcd.setCursor(8,1);
lcd.print("ch1:");
lcd.print(ch1);
}
// Wait 1 second before next reading
delay(1000);
}
After a successful upload, open the Serial Monitor at a baud rate of 9600. Press the “EN/RST” button on the Arduino Uno board and see the result in monitor.
Comments