Categories

Follow Us

Arduino and VEML6040 color sensor example

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

An I2C device

 

Code

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

This example worked just fine

WP-SYNHIGHLIGHT PLUGIN: NOTHING TO HIGHLIGHT! PLEASE READ README.TXT IN PLUGIN FOLDER!

#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

 

Links

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

VEML6040 Breakout Vishay RGBW Sensor Module

Share

VEML6075 ultraviolet light sensor and Arduino example

The VEML6075 senses UVA and UVB light and incorporates photodiode, amplifiers, and analog / digital circuits into a single chip using a CMOS process. When the UV sensor is applied, it is able to detect UVA and UVB intensity to provide a measure of the signal strength as well as allowing for UVI measurement.

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

 

Shopping List

 

Amount Part Type
1 VEML6075
1 UNO R3 CH340G/ATmega328P, compatible for Arduino UNO

 

Schematics/Layout

Arduino VEML6075
5v Vcc
Gnd Gnd
SCL SCL
SDA SDA

 

Code

 

Again we use a library  – https://github.com/NorthernWidget/VEML6075

 

#include <VEML6075.h>
 
VEML6075 UV;
 
void setup()
{
Serial.begin(38400); //Begin Serial
UV.begin(); //Begin the UV module
 
}
 
void loop()
{
Serial.print("UVA = ");
Serial.print(UV.GetUVA()); //Get compensated UVA value
Serial.print(" UVB = ");
Serial.println(UV.GetUVB()); //Get compensated UVB value
delay(1000);
}

 

 

 

Output

Open the serial monitor – this is what I saw

UVA = 0.00 UVB = 3.00
UVA = 0.00 UVB = 0.00
UVA = 0.00 UVB = 1.00
UVA = 0.00 UVB = 2.00
UVA = 0.00 UVB = 1.00
UVA = 0.00 UVB = 3.00
UVA = 0.00 UVB = 1.00
UVA = 0.00 UVB = 1.00

Links

https://www.vishay.com/docs/84304/veml6075.pdf

 

Share

Reading temperature using the DS3231 RTC

Did you know that you can read the temperature from a DS3231 RTC – the DS3231 uses temperature compensation to calibrate the adjustable capacitors of its resonance circuit, in order to maintain time and date with accuracy

The DS3231 is a low-cost, extremely accurate I2C real-time clock (RTC) with an integrated temperaturecompensated crystal oscillator (TCXO) and crystal.
The device incorporates a battery input, and maintains accurate timekeeping when main power to the device is interrupted. The integration of the crystal resonator enhances the long-term accuracy of the device as well as reduces the piece-part count in a manufacturing line.

The RTC maintains seconds, minutes, hours, day, date, month, and year information. The date at the end of the month is automatically adjusted for months with fewer than 31 days, including corrections for leap year. The clock operates in either the 24-hour or 12-hour format with an AM/PM indicator. Two programmable time-of-day alarms and a programmable square-wave output are provided. Address and data are transferred serially through an I2C bidirectional bus.

A precision temperature-compensated voltage reference and comparator circuit monitors the status of VCC to detect power failures, to provide a reset output, and to automatically switch to the backup supply when necessary. Additionally, the RST pin is monitored as a pushbutton input for generating a μP reset.

Some specific info from the datasheet

Temperature Registers (11h–12h)

Temperature is represented as a 10-bit code with a resolution of 0.25°C and is accessible at location 11h and 12h. The temperature is encoded in two’s complement format. The upper 8 bits, the integer portion, are at location 11h and the lower 2 bits, the fractional portion, are in the upper nibble at location 12h. For example, 0001100101b = +25.25°C. Upon power reset, the registers are set to a default temperature of 0°C and the controller starts a temperature conversion.

The temperature is read on initial application of VCC or I2C access on VBAT and once every 64 seconds afterwards. The temperature registers are updated after each user-initiated conversion and on every 64-second conversion. The temperature registers are read-only.

Parts List

name Link
Arduino Uno UNO R3 CH340G/ATmega328P, compatible for Arduino UNO
DS3231 RTC
connecting wire Free shipping Dupont line 120pcs 20cm male to male + male to female and female to female jumper wire

 

Connection

 Arduino Pins Module Pins 
 GND  GND
5v  VCC
A4  SDA
A5  SCL

 

Code

This example requires the https://github.com/Makuna/Rtc

// These tests do not rely on RTC hardware at all
 
//#include <Wire.h> // must be included here so that Arduino library object file references work
#include <RtcDS3231.h>
 
void PrintPassFail(bool passed)
{
    if (passed)
    {
      Serial.print("passed");
    }
    else
    {
      Serial.print("failed");
    }
}
 
void ComparePrintlnPassFail(RtcTemperature& rtcTemp, float compare)
{
    Serial.print(rtcTemp.AsFloatDegC());
    Serial.print("C ");
    PrintPassFail(rtcTemp.AsFloatDegC() == compare);
    Serial.println();
}
 
void ConstructorTests()
{
    // RTC constructors
    Serial.println("Constructors:");
    {
      RtcTemperature temp075Below(0b11111111, 0b01000000); // -0.75 
      ComparePrintlnPassFail(temp075Below, -0.75f);
 
      RtcTemperature temp050Below(0b11111111, 0b10000000); // -0.5 
      ComparePrintlnPassFail(temp050Below, -0.50f);
 
      RtcTemperature temp025Below(0b11111111, 0b11000000); // -0.25 
      ComparePrintlnPassFail(temp025Below, -0.25f);
 
      RtcTemperature tempZero(0b00000000, 0b00000000); // 0.0 
      ComparePrintlnPassFail(tempZero, -0.0f);
 
      RtcTemperature temp025Above(0b00000000, 0b01000000); // 0.25 
      ComparePrintlnPassFail(temp025Above, 0.25f);
 
      RtcTemperature temp050Above(0b00000000, 0b10000000); // 0.5 
      ComparePrintlnPassFail(temp050Above, 0.5f);
 
      RtcTemperature temp075Above(0b00000000, 0b11000000); // 0.75 
      ComparePrintlnPassFail(temp075Above, 0.75f);
 
      RtcTemperature temp25Above(0b00011001, 0b00000000); // 25.0
      ComparePrintlnPassFail(temp25Above, 25.0f);
 
      RtcTemperature temp25Below(0b11100111, 0b00000000); // -25.0
      ComparePrintlnPassFail(temp25Below, -25.0f);
    }
    Serial.println();
 
    // SameType
    {
      Serial.print("same type ");
      RtcTemperature temp25Below(0b11100111, 0b00000000); // -25.0
      RtcTemperature test = temp25Below;
      ComparePrintlnPassFail(test, -25.0f);
    }
 
    // CentiDegrees
    {
      Serial.print("centi degrees ");
      RtcTemperature temp025Below(-25); // -0.25
      ComparePrintlnPassFail(temp025Below, -0.25f);
 
      Serial.print("centi degrees ");
      RtcTemperature temp025Above(25); // 0.25
      ComparePrintlnPassFail(temp025Above, 0.25f);
 
      Serial.print("centi degrees ");
      RtcTemperature temp25Below(-2500); // -25.0
      ComparePrintlnPassFail(temp25Below, -25.0f);
 
      Serial.print("centi degrees ");
      RtcTemperature temp25Above(2500); // 25.0
      ComparePrintlnPassFail(temp25Above, 25.0f);
    }
 
    Serial.println();
}
 
void PrintlnExpected(RtcTemperature& temp, uint16_t digits)
{
  Serial.print(" = ");
  Serial.print(temp.AsFloatDegC(), digits);
  Serial.println();
}
 
void PrintTests()
{
  Serial.println("Prints:");
 
  RtcTemperature temp25Above(2500);
  temp25Above.Print(Serial);
  PrintlnExpected(temp25Above, 2);
 
  RtcTemperature temp25Below(-2500);
  temp25Below.Print(Serial);
  PrintlnExpected(temp25Below, 2);
 
  RtcTemperature temp025Above(25);
  temp025Above.Print(Serial);
  PrintlnExpected(temp025Above, 2);
  temp025Above.Print(Serial, 1);
  PrintlnExpected(temp025Above, 1);
 
  RtcTemperature temp025Below(-25);
  temp025Below.Print(Serial);
  PrintlnExpected(temp025Below, 2);
  temp025Below.Print(Serial, 1);
  PrintlnExpected(temp025Below, 1);
 
  RtcTemperature temp050Above(50);
  temp050Above.Print(Serial);
  PrintlnExpected(temp050Above, 2);
  temp050Above.Print(Serial, 0);
  PrintlnExpected(temp050Above, 0);
 
  RtcTemperature temp050Below(-50);
  temp050Below.Print(Serial);
  PrintlnExpected(temp050Below, 2);
  temp050Below.Print(Serial, 0);
  PrintlnExpected(temp050Below, 0);
  temp050Below.Print(Serial, 2, ',');
  Serial.println(" == -0,50");
 
  Serial.println();
}
 
void MathmaticalOperatorTests()
{
  Serial.println("Mathmaticals:");
 
  RtcTemperature temp050Below(-50);
  RtcTemperature temp050Above(50);
  RtcTemperature temp050Diff(100);
  RtcTemperature temp050Same(-50);
  RtcTemperature tempResult;
 
  Serial.print("equality ");
  PrintPassFail(temp050Below == temp050Same);
  Serial.println();
 
  Serial.print("inequality ");
  PrintPassFail(temp050Below != temp050Above);
  Serial.println();
 
  Serial.print("less than ");
  PrintPassFail(temp050Below < temp050Above);
  Serial.println();
 
  Serial.print("greater than ");
  PrintPassFail(temp050Above > temp050Below);
  Serial.println();
 
  Serial.print("less than ");
  PrintPassFail(temp050Below <= temp050Above);
  Serial.print(" or equal ");
  PrintPassFail(temp050Below <= temp050Same);
  Serial.println();
 
  Serial.print("greater than ");
  PrintPassFail(temp050Above >= temp050Below);
  Serial.print(" or equal ");
  PrintPassFail(temp050Below >= temp050Same);
  Serial.println();
 
  tempResult = temp050Above - temp050Below;
  Serial.print("subtraction ");
  PrintPassFail(tempResult == temp050Diff);
  Serial.println();
 
  tempResult = temp050Above + temp050Above;
  Serial.print("addition ");
  PrintPassFail(tempResult == temp050Diff);
  Serial.println();
 
  Serial.println();
}
 
void setup () 
{
    Serial.begin(115200);
    while (!Serial);
    Serial.println();
 
    ConstructorTests();
    PrintTests();
    MathmaticalOperatorTests();
}
 
void loop () 
{
    delay(500);
}

 

Output

Open the serial monitor window and you will see something like this

Constructors:
-0.75C passed
-0.50C passed
-0.25C passed
0.00C passed
0.25C passed
0.50C passed
0.75C passed
25.00C passed
-25.00C passed

same type -25.00C passed
centi degrees -0.25C passed
centi degrees 0.25C passed
centi degrees -25.00C passed
centi degrees 25.00C passed

Prints:
25.00 = 25.00
-25.00 = -25.00
0.25 = 0.25
0.3 = 0.3
-0.25 = -0.25
-0.3 = -0.3
0.50 = 0.50
1 = 1
-0.50 = -0.50
-1 = -1
-0,50 == -0,50

Mathmaticals:
equality passed
inequality passed
less than passed
greater than passed
less than passed or equal passed
greater than passed or equal passed
subtraction passed
addition passed

Link

https://www.silabs.com/documents/public/data-sheets/Si1145-46-47.pdf

Share

34 Arduino Sensor Projects ebook

We have just written an ebook and published it on the Amazon Kindle store, the topic of this ebook was looking at a variety of sensors with the Arduino IDE

We have written this on the basis that you have some basic knowledge of installing and using the Arduino IDE and know a little about the hardware but want to look at various sensors, each sensor or chapter has a description of the sensor, schematics or connection, source code and where applicable the output. the code examples are also on github, the link is available in the ebook.

Overview 4
Arduino Basics 5
Sensor 1 – BMP180 7
Sensor 2 – DS18B20 11
Sensor 3 – DHT11 14
Sensor 4 – PIR Detector 18
Sensor 5 – HC-SR04 Ultrasonic Sensor 21
Sensor 6 – HDC1008 24
Sensor 7 – mcp9808 26
Sensor 8 – mlx90614 30
Sensor 9 – BME280 32
Sensor 10 – TSL2561 35
Sensor 11 –SHT21 38
Sensor 12 – ML8511 41
Sensor 13 – SHT31 43
Sensor 14 – MAG3110 46
Sensor 15 – TCS34725 50
Sensor 16 – MLX90393 54
Sensor 17 – DS1624 58
Sensor 18 – SI7021 61
Sensor 19 – HDC1080 65
Sensor 20 – BMP280 68
Sensor 21 – DHT12 72
Sensor 22 – AM2320 76
Sensor 23 – LM75 79
Sensor 24 – OPT3001 82
Sensor 25 – TMP175 87
Sensor 26 – MPL3115A2 91
Sensor 27 – CCS811 95
Sensor 28 – MAX30100 99
Sensor 29 – MLX90615 102
Sensor 30 – Si1145 105
Sensor 31 – TMP102 109
Sensor 32 – HMC5983 113
Sensor 33 – MAX44009 116
Sensor 34 – MMA8451 119

We recieve a percentage of the profits from Amazon which we reinvest into this site with regards domain name renewal, web site hosting and purchasing any parts we use – we don’t get any samples or freebies from any companies.

So please support the site by purchasing the ebook from the following links

Site Link
Amazon US Buy here
Amazon UK Buy here
Amazon DE Buy here
Amazon FR Buy here
Amazon ES Buy here
Amazon IT Buy here
Amazon NL Buy here
Amazon JP Buy here
Amazon BR Buy here
Amazon CA Buy here
Amazon MX Buy here
Amazon AU Buy here
Amazon IN Buy here
Share