Home Circuitpython Adafruit Feather M0 and VCNL4010 proximity and ambient light sensor circuitpython example

Adafruit Feather M0 and VCNL4010 proximity and ambient light sensor circuitpython example

by shedboy71

In this example we connect a VCNL4010 integrated proximity and ambient light sensor to an Adafruit Feather M0 running Circuitpython

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
Adafruit Feather M0 Express Adafruit (PID 3403) Feather M0 Express – Designed for CircuitPython – ATSAMD21 Cortex M0
VCNL4010 Multiple Function Sensor Development Tools Proximity/Light Sensor VCNL4000 (1 piece)
Connecting cables Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Schematic/Connection

feather and vcnl4010 layout

feather and vcnl4010 layout

 

Code Example

I used Mu for development

The following is based on a library , I copied the TMP006 library to the lib folder to my Feather M0 Express – https://circuitpython.org/libraries

# Simple demo of the VCNL4010 proximity and light sensor.
# Will print the proximity and ambient light every second.
# Author: Tony DiCola
import time
 
import board
import busio
 
import adafruit_vcnl4010
 
 
# Initialize I2C bus and VCNL4010 module.
i2c = busio.I2C(board.SCL, 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)

Output

Here is what I saw in Mu REPL window

Ambient light: 41.75 lux
Proximity: 2484
Ambient light: 41.5 lux
Proximity: 2481
Ambient light: 40.5 lux
Proximity: 24073
Ambient light: 2.25 lux
Proximity: 2609
Ambient light: 33.75 lux
Proximity: 2434
Ambient light: 121.5 lux

 

Links

https://www.vishay.com/docs/83462/vcnl4010.pdf

 

 

You may also like

Leave a Comment