Home » ESP32 and VCNL4010 proximity and ambient light sensor example

ESP32 and VCNL4010 proximity and ambient light sensor example

by shedboy71
esp32 and VCNL4010 layout

In this article we look at the VCNL4010 which is an integrated proximity and ambient light sensor. We will look at some information on this sensor and how to connect it to an ESP32 with an example using the Arduino IDE.

First lets look at 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.

• Built-in infrared emitter and photo-pin-diode for proximity
• 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

• 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


• 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

About $8.99 for the sensor

Name Link
Connecting cables


This is another I2C sensor, so it's easy to connect to your ESP32 board. In the layout below you can see a Lolin32 connected to the sensor

esp32 and VCNL4010 layout

esp32 and VCNL4010 layout

Code Example

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

You can download and import it via the Arduino IDE or add it via the library manager

This is the default example

[codesyntax lang=”cpp”]

#include <Wire.h>
#include "Adafruit_VCNL4010.h"

Adafruit_VCNL4010 vcnl;

void setup() 
  Serial.println("VCNL4010 test");

  if (! vcnl.begin())
    Serial.println("Sensor not found :(");
    while (1);
  Serial.println("Found VCNL4010");

void loop() 
   Serial.print("Ambient: "); 
   Serial.print("Proximity: "); 




Open the serial monitor and you should see something like this

Proximity: 3628
Ambient: 76
Proximity: 5509
Ambient: 66
Proximity: 6417
Ambient: 63
Proximity: 7181
Ambient: 54
Proximity: 8347
Ambient: 53
Proximity: 9443
Ambient: 52






You may also like

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.