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.
Parts List
Connection
Arduino Due | VEML6040 module |
3v3 | Vin |
Gnd | Gnd |
SCA – 20 | SCA |
SCL – 21 | SCL |
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
Vishay VEML6040 RGBW color sensor auto mode example
CCT: Correlated color temperature in ⸮K
AL: Ambient light in lux
RED: 947 GREEN: 947 BLUE: 947 WHITE: 947 CCT: 10144 AL: 29.79
RED: 949 GREEN: 949 BLUE: 949 WHITE: 949 CCT: 10144 AL: 29.86
RED: 947 GREEN: 947 BLUE: 947 WHITE: 947 CCT: 10144 AL: 29.79
RED: 949 GREEN: 949 BLUE: 949 WHITE: 949 CCT: 10144 AL: 29.86
RED: 949 GREEN: 949 BLUE: 949 WHITE: 949 CCT: 10144 AL: 29.86
RED: 948 GREEN: 948 BLUE: 948 WHITE: 948 CCT: 10144 AL: 29.82