VEML6040 color sensor and ESP32

VEML6040 color sensor senses red, green, blue, and white light and incorporates photodiodes, amplifiers, and analog / digital circuits into a single chip using CMOS process.

With the color sensor applied, the brightness, and color temperature of backlight can be adjusted base on ambient light source that makes panel looks more comfortable for end user’s eyes. VEML6040’s adoption of FiltronTM technology achieves the closest ambient light spectral sensitivity to real human eye responses.

VEML6040 provides excellent temperature compensation capability for keeping the output stable under changing temperature. VEML6040’s function are easily operated via the simple command format of I2C (SMBus compatible) interface protocol. VEML6040’s operating voltage ranges from 2.5 V to 3.6 V.

 

Schematics/Layout

 

esp32 and VEML6040
esp32 and VEML6040

Code

Again we use a library – https://github.com/thewknd/VEML6040

This example worked just fine

[codesyntax lang=”cpp”]

#include “Wire.h”
#include “veml6040.h”

VEML6040 RGBWSensor;

void setup() {
Serial.begin(9600);
Wire.begin();
if(!RGBWSensor.begin()) {
Serial.println(“ERROR: couldn’t detect the sensor”);
while(1){}
}

/*
* init RGBW sensor with:
* – 320ms integration time
* – auto mode
* – color sensor enable
*/

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);
}

[/cpp]

Output

Open the serial monitor – this is what I saw

RED: 2681 GREEN: 1532 BLUE: 657 WHITE: 4341 CCT: 2027 AL: 48.20
RED: 2696 GREEN: 1543 BLUE: 661 WHITE: 4362 CCT: 2031 AL: 48.54
RED: 2617 GREEN: 1493 BLUE: 641 WHITE: 4257 CCT: 2024 AL: 46.97
RED: 3547 GREEN: 2504 BLUE: 974 WHITE: 5499 CCT: 2524 AL: 78.78
RED: 6319 GREEN: 7683 BLUE: 2525 WHITE: 10616 CCT: 4311 AL: 241.71
RED: 7193 GREEN: 9257 BLUE: 2923 WHITE: 12246 CCT: 4494 AL: 291.23
RED: 3830 GREEN: 3999 BLUE: 1319 WHITE: 6284 CCT: 3682 AL: 125.81
RED: 65535 GREEN: 64482 BLUE: 21495 WHITE: 65535 CCT: 3470 AL: 2028.60
RED: 65535 GREEN: 65535 BLUE: 25409 WHITE: 65535 CCT: 3747 AL: 2061.73
RED: 65535 GREEN: 65535 BLUE: 22060 WHITE: 65535 CCT: 3543 AL: 2061.73
RED: 6104 GREEN: 5541 BLUE: 1739 WHITE: 9182 CCT: 3122 AL: 174.32

Links

https://www.vishay.com/docs/84276/veml6040.pdf

VEML6040 Breakout Vishay RGBW Sensor Module