Microbit and VCNL4010 proximity and ambient light sensor Arduino example

In this article we look at another acceleration sensor – this time its the VCNL4010 and we will connect it to our Microbit and see what it can do

First lets take a look at the sensor in question, this is from the datasheet

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

Once again for ease of use I connect an expansion board to the microbit, I feel this makes it easier to connect to a sensor like the one pictured above using connecting wire

Name Link
Microbit BBC Micro:bit Micro-Controller with Motion Detection, Compass, LED Display and Bluetooth
VCNL4010 Multiple Function Sensor Development Tools Proximity/Light Sensor VCNL4000 (1 piece)
Connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire
expansion board Microbit expansion board

Schematic/Connection

microbit and VCNL4010
microbit and VCNL4010

Code Example

This uses the library from https://github.com/adafruit/Adafruit_VCNL4010

This is the default example

#include <Wire.h>
#include "Adafruit_VCNL4010.h"
 
Adafruit_VCNL4010 vcnl;
 
void setup() 
{
  Serial.begin(9600);
  Serial.println("VCNL4010 test");
 
  if (! vcnl.begin())
  {
    Serial.println("Sensor not found :(");
    while (1);
  }
  Serial.println("Found VCNL4010");
}
 
 
void loop() 
{
   Serial.print("Ambient: "); 
   Serial.println(vcnl.readAmbient());
   Serial.print("Proximity: ");
   Serial.println(vcnl.readProximity());
   delay(100);
}

Output

Open the serial monitor and you should see something like this

VCNL4010 test
Found VCNL4010
Ambient: 427
Proximity: 2384
Ambient: 594
Proximity: 2374
Ambient: 592
Proximity: 2375
Ambient: 596
Proximity: 2375
Ambient: 598
Proximity: 2380
Ambient: 582
Proximity: 2409

Links

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