In this article we connect a VCNL4010 to a Raspberry Pi Pico running Circuitpython
Sensor Information
First lets look at some information about the sensor
The VCNL4010 is a fully integrated proximity and ambient light sensor. Fully integrated means that the infrared emitter is included in the package. It has 16 bit resolution. It includes a signal processing IC and features standard I2C communication interface. It features an interrupt function.
PROXIMITY FUNCTION
• Built-in infrared emitter and photo-pin-diode for proximity
function
• 16 bit effective resolution for proximity detection range
ensures excellent cross talk immunity
• Programmable LED drive current from 10 mA to 200 mA in
10 mA steps
• Excellent ambient light suppression by modulating the
infrared signal
• Proximity distance up to 200 mm
AMBIENT LIGHT FUNCTION
• Built-in ambient light photo-pin-diode with close-tohuman-eye sensitivity
• 16 bit dynamic range from 0.25 lx to 16 klx
• 100 Hz and 120 Hz flicker noise rejection
FEATURES
• Integrated modules: infrared emitter (IRED), ambient light sensor (ALS-PD), proximity sensor (PD), and signal conditioning IC
• Interrupt function
• Supply voltage range VDD: 2.5 V to 3.6 V
• Supply voltage range IR anode: 2.5 V to 5 V
• Communication via I2C interface
• I2C Bus H-level range: 1.7 V to 5 V
• Low stand by current consumption: 1.5 μA
Parts Required
Name | Link |
Pico | Raspberry Pi Pico Development Board |
VCNL4010 | Proximity/Light Sensor VCNL4010 |
Connecting cables | Aliexpress product link |
Schematic/Connection
I used the Adafruit VCNL4010 sensor
Black for GND
Red for V+
Blue for SDA
Yellow for SCL
So color coded for ease of use, this layout shows a connection to the module
Code Example
I used Thonny for development
The following is based on a library , I copied the adafruit_vcnl4010.mpy library for this device to the lib folder on my Feather M0 Express – https://circuitpython.org/libraries
This is the basic example which comes with the library
[codesyntax lang=”python”]
import time import board import adafruit_vcnl4010 import busio # Create sensor object, communicating over the board's default I2C bus i2c = busio.I2C(scl=board.GP1, sda=board.GP0) # uses board.SCL and board.SDA sensor = adafruit_vcnl4010.VCNL4010(i2c) # You can optionally adjust the sensor LED current. The default is 200mA # which is the maximum value. Note this is only set in 10mA increments. # sensor.led_current_mA = 120 # Set 120 mA LED current # You can also adjust the measurement frequency for the sensor. The default # is 390.625 khz, but these values are possible to set too: # - FREQUENCY_3M125: 3.125 Mhz # - FREQUENCY_1M5625: 1.5625 Mhz # - FREQUENCY_781K25: 781.25 Khz # - FREQUENCY_390K625: 390.625 Khz (default) # sensor.frequency = adafruit_vcnl4010.FREQUENCY_3M125 # 3.125 Mhz # Main loop runs forever printing the proximity and light level. while True: proximity = sensor.proximity # Proximity has no units and is a 16-bit # value. The LOWER the value the further # an object from the sensor (up to ~200mm). print("Proximity: {0}".format(proximity)) ambient_lux = sensor.ambient_lux print("Ambient light: {0} lux".format(ambient_lux)) time.sleep(1.0)
[/codesyntax]
Output
Here is what I saw in Thonny REPL window
Proximity: 2384
Ambient light: 41.75 lux
Proximity: 2388
Ambient light: 42.0 lux
Proximity: 16056
Ambient light: 1.25 lux
Proximity: 65535
Ambient light: 0.0 lux
Proximity: 65535
Ambient light: 0.0 lux