Skip to main content

veml7700

High-accuracy ambient light sensing with the VEML7700 sensor via I2C for brightness control and daylight harvesting.

Overview

The veml7700 node reads ambient light intensity from the Vishay VEML7700 sensor via I2C. With a wide dynamic range and configurable gain and integration time, it delivers accurate lux readings from dim indoor environments to bright sunlight. Ideal for automatic display brightness, daylight harvesting, and smart lighting.

0-120k
Lux Range
16-bit
Resolution
I2C
Interface
3.3V
Power

Wiring (I2C)

Connection

VCC → 3.3V

GND → GND

SDA → GPIO 2 (Pin 3)

SCL → GPIO 3 (Pin 5)

Fixed address: 0x10

Gain & Integration

High gain + long integration: Best for dim light

Low gain + short integration: Best for bright light

Auto-ranging adjusts settings dynamically

Properties

Property Type Default Description
bus number 1 I2C bus number
address number 0x10 I2C address (fixed at 0x10)
gain string "1" "1", "2", "1/8", or "1/4"
integrationTime number 100 Integration time in ms: 25, 50, 100, 200, 400, 800
interval number 1000 Reading interval in milliseconds

Output

{
  "payload": {
    "lux": 542.3,
    "white": 610,
    "ambient": 542.3
  },
  "lux": 542.3,
  "white": 610,
  "ambient": 542.3,
  "timestamp": 1640000000000
}

Example: Automatic Display Brightness

Dynamically adjust display backlight based on ambient light to reduce eye strain and save power.

veml7700 function pwm
// Function node: Map lux to backlight brightness
var lux = msg.lux;

// Map lux range to brightness percentage (0-100)
var minLux = 1;
var maxLux = 10000;
var minBright = 5;   // Minimum 5% so screen is visible
var maxBright = 100;

// Logarithmic mapping for natural feel
var logLux = Math.log10(Math.max(lux, minLux));
var logMin = Math.log10(minLux);
var logMax = Math.log10(maxLux);

var brightness = minBright + (maxBright - minBright)
    * (logLux - logMin) / (logMax - logMin);
brightness = Math.max(minBright, Math.min(maxBright, brightness));

msg.payload = Math.round(brightness);
msg.topic = "display/backlight";

return msg;

Example: Daylight Harvesting

Adjust artificial lighting to maintain a target lux level, saving energy when natural light is available.

// Function node: Maintain 500 lux target
var lux = msg.lux;
var targetLux = 500;
var tolerance = 50;

var currentDimLevel = flow.get('dimLevel') || 50;
var adjustment = 0;

if (lux < targetLux - tolerance) {
    // Too dark, increase artificial light
    adjustment = Math.min(5, (targetLux - lux) / 50);
} else if (lux > targetLux + tolerance) {
    // Too bright, reduce artificial light
    adjustment = -Math.min(5, (lux - targetLux) / 50);
}

currentDimLevel = Math.max(0, Math.min(100, currentDimLevel + adjustment));
flow.set('dimLevel', currentDimLevel);

msg.payload = {
    measuredLux: lux,
    targetLux: targetLux,
    dimLevel: Math.round(currentDimLevel),
    saving: Math.round(100 - currentDimLevel) + "%"
};

return msg;

Use Cases

Display Auto-Brightness

Adjust screen backlight based on ambient lighting

Daylight Harvesting

Dim artificial lights when natural light is sufficient

Grow Light Control

Ensure plants receive consistent light levels

Security Lighting

Trigger outdoor lights based on ambient darkness

Related Nodes