This is the VCNL4200 a highly sensitive long distance proximity IR and ambient light sensor (ALS) on i2C designed by VISHAY SEMICONDUCTORS. This device is pack into package that combined IRED and ALS Photodiodes, amplifiers, and analog to digital converting circuit into a single CMPS process. This device integrates 16bit high resolution ALS offers excellent sensing capabilities with sufficient selections to fulfill most applications whether a dark or high transparency lens design.
The VCNL4200 offers individual programmable high or low threshold interrupt features for the best utilization of resources and power saving on the microcontroller. For the 12bit and 16bit proximity sensing function this device has a built in smart cancellation scheme that eliminates background light issues and prevents false sensing of proximity due to ambient light noise the adaption of the FILTRON technology achieves the closest ambient light spectral sensitivity to real human eye responses.
VCNL4200 provides excellent temperature compensation for keeping the output stable. ALS (Ambient Light Sensor) and PS (Proximity Sensor) functions are both operated via i2C protocol and range of detection up to 1.5 meter & runs at 2.5v to 3.6v. The ALS (Ambient Light Sensor) has a selectable maximum detection range of 137/393/786 / 1573 LUX with a highest sensitivity of 0.003 LUX/STEP.
The VCNL4200 can be used in human presence detection, home and office appliance like printers, lightning, photocopier, robotics, collision detection, public buildings, home automation, building automation, automotive, parking space, clinical and laboratory appliances. Etc. Below example uses Arduino NANO. However it supports ESP8266, STM32, and AVR. For further readings please refer to datasheet bellow.
Required Components
- Arduino IDE | Atmel Studio | Energia
- Arduino PRO, FIO, NANO, UNO, MINI, MEGA, PRO MINI, LEO, BT, DUE, ETHERNET,LILYPAD, NodeMCU, Teensy Board, TeensyDuino, ESP8266 12, 12E, ESP32, LinkItOne, ESP8266 NodeMCU, ESPDuino, ATMEGA328 16/12, ATMEGA32u4 16/8/ MHz, ESP8266, MSP430 ,ATMEGA250 16 MHz, ATSAM3x8E, Note: The Diagram below is using NANO. (please refer to each MCU’s respective pin-outs & bus configurations)
- VCNL4200 Infrared Proximity & Light Sensor
- Capacitor (See below required values)
- Resistors (See below required values)
- P-Channel MOSFET
- Jumper Wire (Optional)
- Prototyping Board (This is optional you can just hookup directly to the MCU)
- PCB Designer (Circuit simulation to PCB Layout)
Wiring Guide
Source Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
#include "VCNL4200.h" //Download this library below VCNL4200 vcnl4200; // int vcnlSense = 0; int intrupt = 5; void setup() { Serial.begin(9600); while (!Serial); Serial.println("14CORE | VCN14200 Proximity Sensor Test Code"); Serial.orintln("Initializing................................"); delay(4000); if (vcnl4200.exists()) { Serial.println("ERROR > Device not found............"); vcnl4200.initialize(); Serial.println("READING > VCNL4200 Please wait......"); } pinMode(intrupt, INPUT); //INPUT Value pinMode(13, OUTPUT); //OUTPUT Indicator } void loop() { Serial.print("PROXIMITY VALUE > "); Serial.println(vcnl4200.getProximity()); Serial.print("ALS LIGHT VALUE > "); Serial.println(vcnl4200.getAmbient()); //Check interrupt pin vcnlSense = digitalRead(intrupt); // INT Pin (Interrupt Pin) //Set LED to interrupt pin HIGH/LOW Serial.print("High Interrupt: "); Serial.println(vcnl4200.getProxHighInterrupt()); Serial.print("Low interrupt: "); Serial.println(vcnl4200.getProxLowInterrupt()); if (vcnlSense == HIGH) { Serial.println("INT (Interrupt is false) "); digitalWrite(13, LOW); } else { Serial.println("INT (Interrupt true then flag > "); Serial.print(vcnl4200.getInterruptFlag()); digitalWrite(13, HIGH); } Serial.println(); Serial.println("________________________________________"); delay(2000); } |
Hi,
I am using the same library to test VCNL4200 board using Arduino Mega2560. The ALS register is changing the value as light conditions vary but proximity is 0 continuously.
I will be thankful if anyone can help.