Qwiic Proximity Sensor (VCNL4040) Hookup Guide

Pages
Favorited Favorite 1

Arduino Examples

Note: This section is an example of using the Qwiic Proximity Sensor and the RedBoard Qwiic with the Arduino IDE. It is not intended to be a guide for using I2C devices with the Arduino IDE.

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.

Serial output of proximity values

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.

Serial output of proximity detection

This example also allows the proximity sensor to work as a dual purpose photogate.

Hot wheels car triggering proximity sensor

A Hot WheelsTM car triggering proximity sensor.
(*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.

Serial output of ambient light values

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.

Serial output of all values

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.