VEML6040 → Light Sensor

 

The VEML6040 is a digital color sensor developed by Vishay. It measures red, green, blue, and white (RGBW) light intensity using photodiodes and provides digital output via the I²C interface.

 

VEML6040

VEML6040

Install via Library Manager (Recommended)

  1. Open the Arduino IDE.

  2. Go to SketchInclude LibraryManage Libraries...

  3. In the Library Manager, search for:

    VEML6040

  4. Look for a library like:

    • VEML6040 by thewknd
      or a similar name (e.g., Adafruit might also provide one).

  5. Click Install.

 

/*

The MIT License (MIT)

Copyright (c) 2015 thewknd

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

*/

#include "Wire.h"
#include "veml6040.h"

VEML6040 RGBWSensor;

void setup() {
  Serial.begin(9600);
  Wire.begin(2,0); 
  if(!RGBWSensor.begin()) {
    Serial.println("ERROR: couldn't detect the sensor");
    while(1){}
  }
   

    
  RGBWSensor.setConfiguration(VEML6040_IT_320MS + VEML6040_AF_AUTO + VEML6040_SD_ENABLE);
	
  delay(1500);
  Serial.println("Vishay VEML6040 RGBW color sensor auto mode example");
  Serial.println("CCT: Correlated color temperature in \260K");
  Serial.println("AL: Ambient light in lux");
  delay(1500);
}

void loop() {
  Serial.print("RED: ");
  Serial.print(RGBWSensor.getRed());  
  Serial.print(" GREEN: ");
  Serial.print(RGBWSensor.getGreen());  
  Serial.print(" BLUE: ");
  Serial.print(RGBWSensor.getBlue());  
  Serial.print(" WHITE: ");
  Serial.print(RGBWSensor.getWhite()); 
  Serial.print(" CCT: ");
  Serial.print(RGBWSensor.getCCT());  
  Serial.print(" AL: ");
  Serial.println(RGBWSensor.getAmbientLight()); 
  delay(400);
}

 

 

Measurement Method Range Unit Description
Red getRed() 0 to 65535 Raw value Light intensity on the red channel (no physical unit).
Green getGreen() 0 to 65535 Raw value Light intensity on the green channel.
Blue getBlue() 0 to 65535 Raw value Light intensity on the blue channel.
White getWhite() 0 to 65535 Raw value Total white light intensity (not a linear sum of RGB channels).
Correlated Color Temp. getCCT() ~2000 to ~10000 (or more) Kelvin (°K) Correlated Color Temperature – indicates if light is warm or cool.
Ambient Light getAmbientLight() Depends on gain and IT Lux (lx) Ambient light intensity in lux – computed from RGB channels.

 

Note: The range of the raw values (RGBW) can vary depending on the integration time (IT) and gain configured in the sensor. With an integration time of 320 ms, the sensor is more sensitive and can reach higher values.


ESP8266


12 May 2025 | Last Updated: 22 Nov. 2025 | jaimedcsilva

Related
  • AGS10 → Gas Sensor
  • VEML6040 → Light Sensor
  • INA226 → Voltage & Current Monitor

  • Buy Me a Coffee