Arduino library 路 Sensors

Adafruit VEML7700: lux across a wide range

The VEML7700 is Vishay鈥檚 ambient light sensor, a 16-bit count weighted to match how the eye sees brightness. It spans dim rooms to daylight, but no single setting covers the whole range: the gain (1/8, 1/4, 1 or 2) and the integration time (25 to 800 ms) decide both how fine each count is and where the count tops out. Adafruit鈥檚 library, version 2, handles its registers at the fixed address 0x10.

Built in on Mokxi: #include <Adafruit_VEML7700.h> and it builds, with nothing to install. Free, and no account needed.

What Adafruit VEML7700 does

begin() picks the least sensitive pair, gain 1/8 and 100 ms, where one count is about 0.54 lux, which suits a lit room. readLux() multiplies the count by the resolution for the current setting; the finest is 0.0042 lux per count at gain 2 and 800 ms. In bright light the sensor鈥檚 response bends, and VEML_LUX_CORRECTED applies Vishay鈥檚 correction for it, while VEML_LUX_AUTO steps the gain and time by itself until the count lands in a useful range.

Compared with the BH1750, which has its own page, the VEML7700 adds a white channel, interrupt thresholds and power-saving modes, at the cost of more settings to understand. In Mokxi the veml7700 part follows the high-light curve that the corrected reading undoes, so the example prints a plain and a corrected lux. The white channel reads the same count as ALS there, since the slider has no spectrum.

Library Manager nameAdafruit VEML7700
AuthorAdafruit
Include#include <Adafruit_VEML7700.h>
Boardsevery board Mokxi compiles for but ATtiny85
In the simulatorSimulated: it runs against the part the way it does on the bench.
Parts it drivesAmbient light, VEML7700

Install it

It builds on every board Mokxi compiles for but ATtiny85.

In Mokxi it is built in: #include <Adafruit_VEML7700.h> and the sketch compiles, with no download, no zip and no Library Manager.

On a real board, install "Adafruit VEML7700" by Adafruit from the Arduino IDE鈥檚 Library Manager (Sketch, Include Library, Manage Libraries), or add Adafruit VEML7700 to lib_deps in PlatformIO. Mokxi follows the calls of release 2.1.6, so a sketch written here builds there too.

What to know in the simulator: Resolution 0.0042 lux a count at gain x2 and 800 ms, from the current datasheet. The part follows the high-light curve the corrected readings undo; the white channel reads the same count as ALS, since the slider has no spectrum.

ESP32-C3 路 Arduino Uno 路 Arduino Nano 路 Arduino Mega 2560 路 Arduino Leonardo 路 SparkFun Pro Micro 路 Arduino Micro 路 ESP32-C6 路 Raspberry Pi Pico 路 Raspberry Pi Pico W 路 Seeed XIAO SAMD21 路 STM32 路 STM32 Nucleo-F411RE 路 STM32 Blue Pill 路 micro:bit V2 路 Arduino Uno R4 路 ESP32 DevKit 路 ESP32-S3-DevKitC-1 路 ESP8266 NodeMCU 路 Arduino Pro Mini 3.3 V 路 Seeed XIAO ESP32-C3 路 ESP32-C3 SuperMini 路 Seeed XIAO ESP32-C6 路 ESP32-DevKitC V4 路 LOLIN32 Lite 路 Wemos D1 R32 路 Cheap Yellow Display 路 TTGO T-Display 路 Seeed XIAO ESP32-S3 路 Arduino Nano ESP32 路 Arduino Nano RP2040 Connect 路 Seeed XIAO RP2040 路 Waveshare RP2040-Zero 路 Arduino Uno R4 WiFi

The calls you will use

In the order a sketch meets them.

Adafruit_VEML7700 veml = Adafruit_VEML7700()

Creates the driver.

veml.begin()

Checks the chip answers at 0x10, sets gain 1/8 and 100 ms and powers it on. Returns false when it is missing.

veml.readLux()

Lux at the current setting, waiting two integration times so the count is fresh. VEML_LUX_NORMAL_NOWAIT skips the wait.

veml.readLux(VEML_LUX_AUTO)

Chooses gain and integration time for the light it finds, correcting in bright light. Slower, since it may take several readings.

veml.setGain(VEML7700_GAIN_2)

Sets the gain; getGainValue() returns it as a number, such as 0.125.

veml.setIntegrationTime(VEML7700_IT_800MS)

Sets how long each count gathers light; getIntegrationTimeValue() returns it in ms.

veml.readALS()

The raw ambient light count. readWhite() reads the white channel.

veml.setHighThreshold(20000)

A raw count that trips the interrupt, with setLowThreshold() for the other edge. interruptEnable(true) arms it and interruptStatus() says which edge was crossed.

veml.powerSaveEnable(true)

Adds idle time between measurements to cut current; setPowerSaveMode() picks how long.

Example: Lux from a VEML7700, plain and corrected

On the Arduino Uno R3. It runs in the browser exactly as printed.

sketch.ino 路 Arduino Uno R3
#include "Adafruit_VEML7700.h"

Adafruit_VEML7700 veml = Adafruit_VEML7700();

void setup() {
  Serial.begin(115200);
  if (!veml.begin()) {
    Serial.println("Sensor not found");
    while (1);
  }
  Serial.println("Sensor found");
  Serial.print("Gain x");
  Serial.print(veml.getGainValue(), 3);
  Serial.print(", ");
  Serial.print(veml.getIntegrationTimeValue());
  Serial.println(" ms");
}

void loop() {
  Serial.print("raw ALS: ");
  Serial.println(veml.readALS(true));
  Serial.print("lux: ");
  Serial.println(veml.readLux());
  Serial.print("corrected lux: ");
  Serial.println(veml.readLux(VEML_LUX_CORRECTED));
  delay(500);
}

Wiring

  • Arduino Uno R3 A4 to Ambient light, VEML7700 SDA
  • Arduino Uno R3 A5 to Ambient light, VEML7700 SCL
  • Arduino Uno R3 5V to Ambient light, VEML7700 VIN
  • Arduino Uno R3 GND to Ambient light, VEML7700 GND

Open it in the editor, wired and ready to run

Common errors and how to fix them

Sensor not found

begin() got no reply at 0x10. Check the two bus wires and VIN, and that nothing else on the bus claims 0x10.

Lux stops rising around 35000 in bright light

At gain 1/8 and 100 ms the count saturates at 65535, about 35000 lux. Shorten the integration time to 25 ms, or use VEML_LUX_AUTO, which also applies the bright-light correction.

A dark room reads 0 lux

At the default setting each count is about 0.54 lux, so anything dimmer rounds to zero. Raise the gain to 2 and the time to 800 ms, or let VEML_LUX_AUTO choose.

loop() becomes slow after setting 800 ms

A waiting readLux() waits two integration times, 1.6 seconds at that setting. Use VEML_LUX_NORMAL_NOWAIT and read less often, or pick a shorter time.

Questions and answers

Should I use plain or corrected lux?

Corrected, once the light gets bright: it undoes the sensor鈥檚 nonlinear response there. The example prints both so you can see the gap at 300 lux.

Why does the example print 292 and then about 300 lux?

The part is set to 300 lux and follows the sensor鈥檚 high-light curve, so the plain reading is a little low and the corrected one recovers it.

Projects that use Adafruit VEML7700

Built-in projects that include it. Each page has the full sketch and opens in the editor, already wired.

Try Adafruit VEML7700 without installing anything

Open the example, change the sketch, and keep your version in a free account.