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: Brightness Detection

CodeCell Light Sensing

CodeCell includes a built-in VCNL4040 light sensor that can precisely measure both ambient and white light. This sensor enables automatic brightness adjustment, energy-efficient lighting, and environment-aware feedback effects.

How It Detects Light

The VCNL4040 integrates a high-sensitivity photodiode and ADC to detect brightness across a wide range. It communicates via I²C and is fully managed by the CodeCell Library, so you can begin reading light levels with a single line of code.

Ambient vs. White Light Sensing

  • Ambient Light: Measures total brightness from all light sources, ideal for auto-dimming displays or day/night detection. Read it using:
    uint16_t ambient = myCodeCell.Light_AmbientRead();
    This function returns the combined light intensity from the environment, including sunlight and artificial light.
  • White Light: Focuses on daylight or LED-type light sources, useful for lighting control or color-sensitive applications. Read it using:
    uint16_t white = myCodeCell.Light_WhiteRead();
    This function isolates white light levels, making it ideal for brightness calibration or adaptive illumination.

Example – Auto-Dimming LED

This example continuously measures white light and adjusts the onboard LED brightness. The LED becomes brighter in strong light and dims as the room darkens. You can invert or tweak the effect to your preference.


#include <CodeCell.h>

CodeCell myCodeCell;

void setup() {
  Serial.begin(115200);             // Start USB serial at 115200 baud
  myCodeCell.Init(LIGHT);           // Enable onboard light/proximity sensing
  myCodeCell.LED_SetBrightness(0);  // Disable the default LED breathing animation
}

void loop() {
  if (myCodeCell.Run(10)) {         // Run loop at 10 Hz

    uint16_t brightness = (myCodeCell.Light_WhiteRead()) >> 3; // Map the raw white-light reading to an 8-bit-like range

    // Clamp to a usable LED range (1–254)
    if (brightness == 0U) {
      brightness = 1U;              // Prevent the LED from fully turning off
    } else if (brightness > 254U) {
      brightness = 254U;            // Cap to avoid over-driving
    }

    // Invert: uncomment to make darker room -> brighter LED
    // brightness = 255U - brightness;  // Invert

    Serial.println(brightness);      // Debug: scaled LED value
    myCodeCell.LED(0, 0, brightness); // Drive onboard LED (blue channel)
  }
}

Customization Tips

  • Adjust Sensitivity: Modify scaling or mapping to fine-tune brightness response.
  • Change LED Colors: Use myCodeCell.LED(r, g, b) for different visual feedback.
  • Combine Sensors: Mix light and proximity sensing for gesture-based or adaptive lighting effects.
  • Expand Outputs: Add external LEDs or NeoPixels for ambient feedback control.
  • 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

67 reviews
Write a review
85%
(57)
6%
(4)
1%
(1)
3%
(2)
4%
(3)
62
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