Electronics

Distance Light Digital Sensor Ambient Proximity Sensor CJMCU-3216 AP3216 ALS/PS

AED 19.95

Low stock
1

Description

The CJMCU-3216 AP3216 is a digital ambient proximity sensor module that combines an ambient light sensor (ALS), a proximity sensor (PS), and an infrared (IR) LED in a compact package. It has a linear response over a dynamic range of 365/1460/5840/23360 and is suitable for use under clear or darkened glass. The proximity function is designed for near-field applications and can detect objects with a configurable zone controlled by registers. The device features an interrupt function to improve system efficiency and minimize false triggering. It has a built-in temperature compensation circuit, a wide operating temperature range, and supports an I2C interface. The sensor can be easily interfaced with Arduino through a small sketch, which accepts commands from the Serial Monitor or RoboRemo app. The sensor has several features to make it easy to configure, read, and plot data.

 

Package Includes:

  • 1 x CJMCU-3216 AP3216 Digital Ambient Proximity Sensor Module

 

Features:

  • Integrated ambient light sensor (ALS), proximity sensor (PS), and infrared (IR) LED in a single package
  • Multiple gain function with linear response over a dynamic range of 365/1460/5840/23360
  • Designed for use under clear or darkened glass and can detect low-reflection objects such as black hair
  • Proximity function targeted specifically towards near-field applications with configurable zone controlled by registers
  • Multiple proximity gain control, multiple IR LED current control, and 10-bit ADC output
  • Interrupt feature to improve system efficiency and minimize false triggering
  • Internal calibration and CMOS design to minimize device-to-device variations for ease of manufacturability
  • Built-in temperature compensation circuit
  • Wide operating temperature range (-30°C to +80°C)
  • Ambient light photo sensor with 16-bit effective linear output (0~65535) and four user-selectable dynamic ranges
  • Anti-flicker rejection (reject 50/60Hz), high sensitivity in darkened glass, and window loss compensation
  • Proximity detector with 10-bit effective linear output (0~1023) and four programmable IR LED current outputs
  • High ambient light suppression and cross-talk compensation
  • Connects over I2C bus for easy interfacing with microcontrollers
  • Compatible with Arduino UNO and other microcontrollers
  •           

 

Description:

The CJMCU-3216 AP3216 is a digital ambient proximity sensor module that combines an ambient light sensor (ALS), a proximity sensor (PS), and an infrared (IR) LED in a compact package. It is designed for use in a wide range of applications that require reliable detection of objects in close proximity to the sensor. The device provides a multiple gain function with a linear response over a dynamic range of 365/1460/5840/23360. It is well-suited for use under clear or darkened glass and can detect even low-reflection objects, such as black hair. The proximity function is targeted specifically towards near-field applications and can detect external objects with a simple configurable zone controlled by registers. The device has multiple proximity gain control, IR LED current control, and a 10-bit ADC output. The sensor supports an interrupt feature to improve system efficiency and has several features that help minimize false triggering. The AP3216C is designed to minimize device-to-device variations for ease of manufacturability. It has a built-in temperature compensation circuit and can operate in a wide temperature range (-30°C to +80°C). The ambient light photo sensor has a 16-bit effective linear output (0~65535) and four user-selectable dynamic ranges. It also has anti-flicker rejection (reject 50/60Hz), high sensitivity in darkened glass, and window loss compensation. The proximity detector has a 10-bit effective linear output (0~1023) and four programmable IR LED current outputs. It also has high ambient light suppression and cross-talk compensation. It is RoHS compliant. The sensor connects over an I2C bus, making it easy to interface with an Arduino or other microcontrollers.

 

Principle of Work:

The CJMCU-3216 AP3216 Ambient Proximity Sensor module contains an ambient light sensor (ALS), a proximity sensor (PS), and an infrared (IR) LED. The module works by emitting infrared light from the IR LED and then measuring the amount of light that is reflected back to the sensor. The ALS measures the amount of ambient light in the environment and produces a linear output based on the amount of light detected. The PS detects objects that are within a certain distance of the sensor and produces a linear output based on the proximity of the object. The IR LED emits infrared light that is reflected off objects in the sensor's field of view and detected by the PS. The module also includes several features to improve accuracy and reduce false triggers. These features include multiple gain control for both the ALS and PS, high ambient light suppression, and cross-talk compensation. The module also has an interrupt feature to improve system efficiency and minimize false triggering. The module connects over an I2C bus, allowing it to be easily interfaced with microcontrollers like Arduino. The module is compatible with Arduino UNO and other microcontrollers,

 

Pinout:

  • GND: Connect to ground
  • VCC: Connect to the positive terminal of the power supply (between 2.8V and 3.8V)
  • SDA: Connect to the I2C data line of the microcontroller
  • SCL: Connect to the I2C clock line of the microcontroller
  • INT: Interrupt output (active low).

 

Applications: 

  1. Mobile devices such as smartphones and tablets to adjust screen brightness based on ambient light conditions.
  2. Home automation systems to detect the presence of people and automatically turn on/off lights, air conditioning, and other appliances.
  3. Robotics and drones to detect objects and obstacles for collision avoidance and navigation.
  4. Automotive applications for automatic headlights, windshield wipers, and parking assist systems.
  5. Industrial automation systems for monitoring and controlling the presence of objects and materials on conveyors and assembly lines.
  6. Medical devices to measure and monitor light levels in diagnostic and therapeutic equipment.
  7. Gaming devices and toys for gesture recognition and object detection.
  8. Security systems for detecting the presence of people and intruders.

 

Circuit:

  • VCC to 3.3V pin of the Arduino Uno
  • GND to GND pin of the Arduino Uno
  • SDA to A4 pin of the Arduino Uno
  • SCL to A5 pin of the Arduino Uno
  • INT to digital pin 2 of the Arduino Uno
  • LED to digital pin 10 of the Arduino Uno

Note that if you're using an Arduino board that operates at 5V (such as the Arduino Uno), you'll need to use a logic-level converter or voltage divider to interface with the 3.3V AP3216 sensor module.

 

Library:

To install the AP3216_WE library on the Arduino IDE, follow these steps:

  1. Download the library from the GitHub repository: https://github.com/opensensinglab/ap3216_we
  2. Extract the downloaded zip file.
  3. Open the Arduino IDE and go to Sketch > Include Library > Add .ZIP Library.
  4. Select the extracted AP3216_WE library folder and click Open.
  5. The library will now be installed and ready to use.

Note: If you have any instances of the Arduino IDE open, you will need to restart them for the library to appear in the Sketch > Include Library menu.

Code:  

This code is a complete Arduino sketch that demonstrates how to use the AP3216_WE library to interface with the AP3216 sensor module. The AP3216 is a digital ambient light and proximity sensor that communicates via the I2C protocol.

#include "Wire.h"
#include "AP3216_WE.h"
byte interruptPin=2;
byte ledPin=10;
volatile bool event = false;

AP3216_WE myAP3216 = AP3216_WE();
// You can also pass a TwoWire object such as wire2:
// AP3216_WE myAP3216 = AP3216_WE(&wire2);

void setup() {
  pinMode(ledPin, OUTPUT);
  pinMode(interruptPin, INPUT);
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, FALLING);
  Serial.begin(9600);
  Wire.begin();
  myAP3216.init();
  myAP3216.setLuxRange(RANGE_20661);
  
  /*
   * Interrupts can be cleared manually if CLR_INT_MANUALLY (or 1) is chosen
   * Interrupts will be cleared by reading PS or ALS data if CLR_INT_BY_DATA_READ (or 0) is chosen
   */
  myAP3216.setIntClearManner(CLR_INT_MANUALLY);
  myAP3216.setPSThresholds(0, 200); // Outside this window an interrupt is triggered

  /*
   * Outside the following window (lux values) an interrupt is triggered. Ensure that 
   * you don't chose values outside the defined lux range (setLuxRange).
   */
  myAP3216.setALSThresholds(3, 500); // 
  myAP3216.setPSIntegrationTime(8);
  myAP3216.setPSInterruptMode(INT_MODE_ZONE);
  delay(1000);
}

void loop() {
/*
 * Uncomment the following lines if you want to see the measured values
 */
//  float als = myAP3216.getAmbientLight();
//  unsigned int prox = myAP3216.getProximity();
//  Serial.print("Lux: "); Serial.print(als);
//  Serial.print("  Proximity: "); Serial.println(prox);
  if(event){
    interruptAction();
  }
  /*
   * without the following delay you will not detect ALS and PS interrupts together. 
   */
  delay(1000); 
}

void interruptAction(){
  byte intType = NO_INT;
  intType = myAP3216.getIntStatus();
  
  switch(intType){
    case(ALS_INT):
      Serial.println("Ambient Light Interrupt!");
      break;
    case(PS_INT):
      Serial.println("Proximity Interrupt!");
      break;
    case(ALS_PS_INT):
      Serial.println("Ambient Light and Proximity Interrupt!");
      break;
    default:
      Serial.println("Something went wrong...");
      break;      
  }
  
  digitalWrite(ledPin, HIGH);
  delay(1000);
  digitalWrite(ledPin, LOW);
  
  intType = myAP3216.getIntStatus();
  myAP3216.clearInterrupt(intType);
  event = false;
}

void blink(){
  event = true;
}


The code starts by including the necessary libraries: Wire.h for I2C communication and AP3216_WE.h for interfacing with the sensor module. It then defines some variables: interruptPin and ledPin, which are connected to the interrupt and LED pins on the Arduino Uno board, respectively. It also defines a volatile boolean variable event, which is used to indicate whether an interrupt event has occurred. Next, the code creates an instance of the AP3216_WE class called myAP3216. This instance is used to interact with the sensor module. The setup() function is then called, which sets up the pins and interrupts, initializes the I2C communication, initializes the sensor module, and sets the thresholds and integration time for the sensor.

In the main loop of the program, the code checks if an interrupt event has occurred by checking the value of the event variable. If an interrupt has occurred, the code calls the interruptAction() function to handle the interrupt. The loop also includes a delay() function to ensure that ALS and PS interrupts can be detected together. The interruptAction() function reads the type of interrupt that occurred and prints a message to the serial monitor indicating which type of interrupt occurred. It also blinks the LED on the Arduino board for one second and then clears the interrupt.

Finally, the blink() function is called by the attachInterrupt() function in the setup() function. This function sets the event variable to true when an interrupt occurs on the interruptPin.

 

Technical Details:

  • Ambient light sensor:
    • four adjustable lux ranges
    • calibration function
  • proximity sensor (PS):
    • Range: 2 cm up to approx. 30 cm, depending on the settings
    • calibration function
    • four gain levels
    • adjustable measuring times
  • IR LED:
    • setting the number of pulses per measurement
    • setting the LED current
  • Interrupt function: for PS and ALS or both; active-low
  • continuous or single-shot measurements
  • supply voltage VCC and VLED: 2.4 – 3.6 volts
  • communication: I2C, address 0x1E (not variable)
  • power consumption:1.7 mA, measured for the AP3216_Continuous sketch using the circuit shown below (i.e. including level converter)
  • power down function

 

Resources:

 

Comparisons:

The CJMCU-3216 AP3216 Digital Ambient Proximity Sensor Module and the Distance Laser Measuring Module Time of Flight Tof VL53L0X are both sensor modules, but they have different sensing capabilities and use different technologies.

The CJMCU-3216 AP3216 module is a digital ambient light and proximity sensor that uses infrared (IR) technology to detect the proximity of an object up to a certain distance. It also measures ambient light levels and provides interrupt functionality based on threshold settings. It has a maximum proximity detection range of up to 100 mm and a maximum ambient light measurement range of up to 61,000 lux. On the other hand, the Distance Laser Measuring Module Time of Flight Tof VL53L0X uses time-of-flight (ToF) technology to measure distances up to several meters with high accuracy. It emits laser pulses and measures the time it takes for the pulse to reflect back from an object, allowing it to calculate the distance. It has a maximum range of up to 2 meters and a resolution of up to 1 mm.

In summary, the CJMCU-3216 AP3216 module is better suited for proximity sensing and ambient light measurements at relatively short distances, while the VL53L0X module is better suited for long-range distance measurements with high accuracy. The choice of which module to use would depend on the specific application requirements.