Lemontree

[Cause of death unknown] VEML6040 color sensor module - with tutorial

 
Overview

[Unknown cause of death] It is suspected that the temperature of my welding was too high (I had to re-solder it several times after it became crooked)

This module uses VEML6040A3OG

Why?

Because it is cheap, compared to other color sensors, such as ** TCS3200, **VEML6040A3OG is only half the price! If you buy parts from Lichuang Mall, you can build a VEML6040A3OG color sensor module for about 12-13 yuan, which is not enough to buy a TCS3200 chip. Moreover, the chip is small in size and the overall size of the module is also smaller than the TCS3200 module, making it easier to stuff small things into it. It also supports I2C communication, so much data can be read with just 4 pins, which is convenient! Although this chip is small, the resolution can reach 16b, which is enough to meet simple needs, and the power supply current only requires 200ua to work! ! !

In addition, I added an LED control pin to this module to save power and not blind the eyes when not in use.

The following is a sample program based on Arduino, the library can be downloaded in the attachment

#include       //载入总线库
#include     //载入vml6040库

int x = 0;

void setup() {
    Serial.begin(115200);
    Wire.begin();
    VEML6040.init();
    Serial.println("14CORE | VEML6040 TEST CODE");
    VEML6040.VEML6040_forceMode();
    VEML6040.VEML6040_trigger();
    delay(1000);
}

void loop() {
    measureLight();              //探测颜色函数
    Serial.println();
    delay(500);
    VEML6040.VEML6040_trigger();
}

void measureLight() {       //探测颜色函数
    uns16 red, blue, green, white;      //定义红蓝绿白 如果是veml6070的话好像有紫外线检测
    red = VEML6040.getRed();                //获取红色数值
    green = VEML6040.getGreen();            //获取绿色数值
    blue = VEML6040.getBlue();              //获取蓝色数值
    white = VEML6040.getWhite();            //获取白色数值
    Serial.println("VEML6040 DATA");         //打印文本'veml6040数据'
    Serial.println();
    Serial.print("Red:	");
    Serial.print(red);                       //打印红色数值
    Serial.println();
    Serial.print("	Green:	");              //打印绿色数值
    Serial.print(green);
    Serial.println();
    Serial.print("	Blue:	");                //打印蓝色数值
    Serial.print(blue);
    Serial.println();
    Serial.print("	White:	");               //打印白色数值
    Serial.println(white);
    Serial.print("RGBW Value");
    Serial.println(red,green,blue,white);       //打印RGBW数值
    uns16 K= min(1-red,1-green,1-blue); //将RGB数值转换成CMYK色碼
    uns 16 C = (1-red-K)/(1-K);
    uns 16 M = (1-green-K)/(1-K);
    uns 16 Y = (1-blue-K)/(1-K);
    println(K,M,C,Y);           //打印CMYK色碼
}
参考设计图片
×
 
 
Search Datasheet?

Supported by EEWorld Datasheet

Forum More
Update:2025-08-08 16:38:31

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
community

Robot
development
community

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号