Qwiic Proximity Sensor (VCNL4040) Hookup Guide
Please use the following links and the internet for a better understanding of I2C and how it works in the Arduino IDE:
Example 1: Proximity Readings
This example outputs the IR Proximity Value from the VCNL4040 sensor in the Serial Monitor.
Despite being a qualitative sensor, you will notice that the output does vary with the distance of the object, surface color, and reflectivity. You can also use this setting to estimate the field of view of the sensor. The maximum output value is 65535, closest to the sensor, and the minimum (0-1) being the furthest the sensor can read.
Example 2: Is Something There
This example takes an initial reading at power on. If the reading changes by a significant amount the sensor prints that something is present in the Serial Monitor.
This example also allows the proximity sensor to work as a dual purpose photogate.
(*The speed of the Gif is slowed down for you to see the output in the Serial Monitor.)
There is a slight delay in the serial output from the microcontroller (few frames); however, this is exaggerated due to how the image is slowed down.
Example 3: Ambient Light
This example outputs ambient light readings to the terminal.
Again the sensor is qualitative, but you can test how the angle of incident from the light source affects the sensor readings.
Example 4: All Readings
This example outputs IR, ambient and white light readings to the terminal. Along with proximity and ambient light sensing the VCNL4040 has a 'white light' sensor as well.
Example 5: Advanced Settings
This example shows how to use different Wire ports, fast I2C, and various advanced settings that are supported by the library. Please, refer to the datasheet and library functions listed above for more details.