Black Friday Offer 🔥 Use code BLKFRI at checkout to get 15% OFF on orders above €60!
CodeCell includes an onboard VCNL4040 proximity sensor for touchless object detection and depth-based gestures. You can easily read proximity values using the CodeCell library’s built-in function:
uint16_t proximity = myCodeCell.Light_ProximityRead();
This function returns a numerical value representing how close an object is to the sensor. Higher values indicate a closer object. You can use this reading to trigger LEDs, motors, or interactive effects in real-time.

The VCNL4040 emits infrared light and measures its reflection to estimate distance (up to ~20 cm). It communicates over I²C and is fully handled by the CodeCell Library, allowing you to focus on interaction logic instead of low-level sensor control.
Turns the LED red when an object is close, and green when clear. Adjust the sensitivity using the DISTANCE_RANGE value.
#include <CodeCell.h>
CodeCell myCodeCell;
#define DISTANCE_RANGE 100U // Proximity trigger threshold (higher = requires closer object)
void setup() {
Serial.begin(115200); // Start USB serial at 115200 baud
myCodeCell.Init(LIGHT); // Enable light + proximity sensing
myCodeCell.LED_SetBrightness(0); // Turn off default LED breathing animation
}
void loop() {
if (myCodeCell.Run(1)) { // Run the CodeCell service loop at 1 Hz
// Read proximity; values above DISTANCE_RANGE mean "object detected / close"
if (myCodeCell.Light_ProximityRead() > DISTANCE_RANGE) {
myCodeCell.LED(0xFF, 0x00, 0x00); // Red: proximity detected
} else {
myCodeCell.LED(0x00, 0xFF, 0x00); // Green: no proximity detected
}
}
}
Maps proximity readings into gesture zones (NEAR, MID, FAR, NONE) and sets LED colors for each state. It also prints live data to the Serial Monitor for debugging or visualization.
#include <CodeCell.h>
CodeCell myCodeCell;
// Thresholds for gesture zones (tweak as needed)
const uint16_t NEAR_THRESHOLD = 700;
const uint16_t MID_THRESHOLD = 100;
const uint16_t FAR_THRESHOLD = 10;
void setup() {
Serial.begin(115200); // Start USB serial at 115200 baud
myCodeCell.Init(LIGHT); // Enable onboard light + proximity sensing
myCodeCell.LED_SetBrightness(0); // Turn off default LED breathing animation
Serial.println(">> Depth Gesture Demo Started");
}
void loop() {
if (myCodeCell.Run(2)) { // Run at 2 Hz
uint16_t proximity = myCodeCell.Light_ProximityRead();
// Print raw sensor value
Serial.print("Proximity: ");
Serial.print(proximity);
Serial.print(" | Gesture: ");
// Classify depth gesture
if (proximity > NEAR_THRESHOLD) {
Serial.println("NEAR");
myCodeCell.LED(0xFF, 0x00, 0x00); // Red LED for near
} else if (proximity > MID_THRESHOLD) {
Serial.println("MID");
myCodeCell.LED(0xFF, 0xA5, 0x00); // Orange LED for mid
} else if (proximity > FAR_THRESHOLD) {
Serial.println("FAR");
myCodeCell.LED(0x00, 0x00, 0xFF); // Blue LED for far
} else {
Serial.println("NONE");
myCodeCell.LED(0x00, 0x00, 0x00); // LED off for no hand
}
}
}
DISTANCE_RANGE, NEAR_THRESHOLD, MID_THRESHOLD, and FAR_THRESHOLD to fit your setup.Join our Community ~ Be the first to know about new products and get exciting deals!
© 2025 Microbots.