Menu
Microbots
0
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • Modules & Parts
    • Tools & Gears
    • Robots & Displays
  • About
    • Our Story
    • Reach Out
    • FAQs
  • Sign in
  • English
  • Your Cart is Empty
Microbots
  • Learn
    • Getting Started
    • Maker Builds
    • Education
  • Shop
    • Modules & Parts
    • Tools & Gears
    • Robots & Displays
  • 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

50 reviews
Write a review
84%
(42)
4%
(2)
2%
(1)
4%
(2)
6%
(3)
21
46
B
CodeCell C6 Drive
Brandon

Awesome product with great tutorials and example code

G
MotorCell
Gerald Kendrick

Very happy with my MotorCell. I'm incorporating it into a prototype project that will hopefully result in me needing a few more!

User picture
A
CodeCell C6 Drive
Anonymous

Great product! Having the IMU, motor driver, and battery management directly on the board is incredibly handy for quick prototyping. Love it!

Improvement ideas:
- using an ESP32 other than the C6 to get more cores. On a single-core chip, WiFi tasks often interfere with real-time applications.
- adding two more motor drivers (with a slightly higher current rating) would be awesome for drone projects!
- I know the compactness of the board is a huge selling point and really optimised, but exposing a few more pins would be great. With the motor drivers already occupying 4 pins, having only 4 GPIOs left can be tight for complex projects (though I’m nitpicking, I’m really pushing this board to its limits!).

A
CodeCell C6
Anonymous

I use CodeCell C6, like all the Features, and compactness. The remote Link to the iPhone with some Controls for 2 Motors is just perfect for the job.

O
CodeCell C6 Drive
Odd_Jayy

This is one of my Favorite finds, this board has everything you need to make a quick and small robot, easy to set up and install. Perfect for beginners or a person who needs to save room in their build.

User picture
123