Menu
Microbots
0
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • ProtoBot
    • Modules & Parts
    • Tools & Gears
    • Coming Soon
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Sign in
  • English
  • Your Cart is Empty
Microbots
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • ProtoBot
    • Modules & Parts
    • Tools & Gears
    • Coming Soon
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Language

  • 0 0

CodeCell: Proximity Sensing

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.

How It Detects Proximity

CodeCell Proximity Sensing

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.

Example 1 – Proximity Trigger

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
    }
  }
}

Example 2 – Depth Gestures (Near / Mid / Far)

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
    }
  }
}

Customization Tips

  • Tune thresholds: Adjust DISTANCE_RANGE, NEAR_THRESHOLD, MID_THRESHOLD, and FAR_THRESHOLD to fit your setup.
  • Change feedback: Swap LED colors or use motors, servos, or buzzers for alternate cues.
  • Combine sensors: Pair proximity data with light or IMU readings for gesture-controlled lighting, robots, or smart interfaces.
  • Share:

Follow

Github

  • About
  • Software
  • Education
  • Contact
  • FAQs
  • Terms
  • Refund Policy
  • Privacy Policy

Join our Community ~ Be the first to know about new products and get exciting deals!

© 2026 Microbots.

★ Reviews

Let customers speak for us

68 reviews
Write a review
84%
(57)
6%
(4)
3%
(2)
3%
(2)
4%
(3)
63
21
C
CodeCell C3
Cloke74

Great piece of kit, had just what i needed to complete the project i had in mind. Shame shipping to the UK is so expensive, but appreciate this isn’t necessarily in the hands of MicroBots

A
CodeCell C6
Anonymous

I had an issue, got a red light, I used too much flux. Support said clean it, then the one sensor worked fine. I got the help and answer same day I provided a foto.

A
CodeCell C6 Drive
Anonymous

I think this is the best of the ESP offered, most versatile.

User picture
P
CodeCell C6
Prudhvi tej Chinimilli

Been testing the Microbots CodeCell C6 and honestly impressed with how much functionality they packed into such a tiny module. Great form factor for rapid prototyping wearable/embedded sensing applications. ESP32-C6 + IMU integration makes development much easier compared to building everything from scratch.

Still exploring battery optimization and compact LiPo options for our use case, but overall the platform is promising for low-cost real-time sensing systems. Excited to keep building with it.

F
CodeCell C6
Francisco Estivallet

Amazing hardware, my go to for compact projects.

User picture
123