We use cookies to provide our customers with an optimal site experience. View our privacy statement to learn more about how we use cookies and how to manage your settings. By proceeding on our website you consent to the use of cookies.

Qwiic UV Sensor (VEML6075) Hookup Guide

The VEML6075 is SparkFun’s latest UV sensing solution. The VEML6075 implements a simple photodiode to measure the levels of UVA (320-400 nm) and UVB (280-320 nm) radiation. We can read the intensity of this light in irradiance, and from there, calculate the UV Index. The Qwiic UV Sensor has two spectrum ranges of measurement, UVA (365 ±10nm), and UVB. (330 ±10nm)

To get started, you’ll need a microcontroller to control everything. You may not need everything though depending on what you have. Add it to your cart, read through the guide, and adjust the cart as necessary.

First let’s check out some of the characteristics of the VEML6075 sensor we’re dealing with, so we know what to expect out of the board.

Pins

The following table lists all of the VEML6075’s pins and the direction of data flow.

Optional Features

The VEML6075 breakout has pull up resistors attached to the I2C bus; if multiple sensors are connected to the bus with the pull-up resistors enabled, the parallel equivalent resistance will create too strong of a pull-up for the bus to operate correctly. As a general rule of thumb, disable all but one pair of pull-up resistors if multiple devices are connected to the bus. If you need to disconnect the pull up resistors they can be removed by cutting the traces on the corresponding jumpers highlighted below.

Pull-Up Jumper

The onboard LED (highlighted below) will light up when the board is powered, and the sensor (also highlighted below) should be left uncovered in your application.

Sensor and Power LED

Hardware Assembly

If you haven’t yet assembled your Qwiic Shield, now would be the time to head on over to that tutorial. Depending on the microcontroller and shield you’ve chosen, your assembly may be different, but here’s a handy link to the Qwiic Shield for Arduino and Photon Hookup Guide to get you started!

With the shield assembled, SparkFun’s new Qwiic environment means that connecting the sensor could not be easier. Just plug one end of the Qwiic cable into the Qwiic UV Sensor, the other into the Qwiic Shield and you’ll be ready to upload a sketch and figure out how much sunscreen you need to put on to keep yourself from turning into a lobster. It seems like it’s too easy to use, but that’s why we made it that way!

SparkFun RedBoard and Qwiic Shield with the Qwiic UV Sensor Attached

Library Overview

Note: This example assumes you are using the latest version of the Arduino IDE on your desktop. If this is your first time using Arduino, please review our tutorial on installing the Arduino IDE. If you have not previously installed an Arduino library, please check out our installation guide.

First, you’ll need the SparkFun VEML6075 Arduino library. You can obtain these libraries through the Arduino Library Manager. Search for Sparkfun VEML6075 Arduino Library to install the latest version. If you prefer downloading the library from the GitHub repository and manually installing it, you can grab them here:

Before we get started developing a sketch, let’s look at a pertinent enum, VEML6075_error_t. Many of our functions will return this data type as a way of pointing out errors. The enum is shown below, notice how negative numbers are returned for errors, while a 1 is returned for a success.

VEML6075_error_t setHighDynamic(veml6075_hd_t hd) — Changes to high dynamic mode by passing in DYNAMIC_HIGH and normal dynamic mode by passing in DYNAMIC_NORMAL. High dynamic mode increases the resolution by a factor of 2.

veml6075_hd_t getHighDynamic(void) — Returns the current high dynamic setting.

Now that we have our library installed and we understand the basic functions, let’s run some examples for our UV sensor to see how it behaves.

Example 1 - Stream UV (i.e. Read Distance)

To get started with the first example, open up File > Examples > Examples from Custom Libraries > SparkFun VEML6075 UV Sensor > Example1_Stream_UV. In this example, we begin by creating a VEML6075 object called uv and then initializing our sensor object in the setup() loop. The code to do this is shown below.

Copy Code

VEML6075 uv; // Create a VEML6075 object

void setup() { Serial.begin(9600); // the VEML6075's begin function can take no parameters // It will return true on success or false on failure to communicate if (uv.begin() == false) { Serial.println("Unable to communicate with VEML6075."); while (1) ; } Serial.println("UVA, UVB, UV Index");}

Once we’ve initialized our sensor, we can start grabbing measurements from it. We pull the UVA and UVB values as well as the index using uv.uva, uv.uvb and uv.index The void loop() function that does this is shown below.

Opening your serial monitor to a baud rate of 9600 should show the calibrated UVA and UVB levels as well as the current UV index

Example 1 Output

Example 2 - Configure UV

To get started with the second example, open up File > Examples > Examples from Custom Libraries > SparkFun VEML6075 UV Sensor > Example2_Configure_UV. In this example, we begin by creating and initializing a VEML6075 object called uv. We then change the integration time (the amount of time over which a measurement is taken) and change to high dynamic mode (which increases the resolution) using the following lines of code (contained in the setup() loop).

Copy Code

void setup() { Serial.begin(9600); // The begin function can take a TwoWire port as a parameter -- in case your platform has more than // the one standard "Wire" port. // begin will return VEML6075_SUCCESS on success, otherwise it will return an error code. if (uv.begin(Wire) != VEML6075_SUCCESS) { Serial.println("Unable to communicate with VEML6075."); while (1) ; }

// High dynamnic: The VEML6075 can either be set to normal dynamic or high dynamic mode. // In high dynamic mode, the resolution is increased by about a factor of two. // Valid dynamic settings are: // VEML6075::DYNAMIC_NORMAL -- Normal dynamic mode // VEML6075::DYNAMIC_HIGH -- High dynamic mode // The library defaults the dynamic to normal uv.setHighDynamic(VEML6075::DYNAMIC_HIGH);}

Now that we’ve changed around a few of our UV sensors settings, we will read the raw UVA and UVB values along with their compensation values from visible and infrared noise, which are used to calculate the values we obtain from uv.uva and uv.uvb. The below code reads both raw values as well as calibrated values.

Opening your serial monitor to a baud rate of 9600 will show both raw values as well as calibrated values in the order of Time, raw UVA, raw UVB, visible compensation, IR compensation, calculated UVA, calculated UVB, calculated UV Index.

Example 2 Output

Example 3 - Shutdown

To get started with the third example, open up File > Examples > Examples from Custom Libraries > SparkFun VEML6075 UV Sensor > Example3_Shutdown. In this example, we’ll go over how to put the sensor into low power shutdown mode. We begin by creating and initializing a VEML6075 object called uv. We initialize the object in setup the exact same way as the first example. We then loop through, reading our calibrated UVA and UVB values. Every 50 reads, we switch the power state of the UV sensor. When we put the VEML6075 in shutdown mode, it only draws 800 nA of current while ignoring any reads we attempt to throw at it. The code that handles this is shown below.

The part in our serial output where we shut the VEML6075 down is shown below. Notice how after the sensor goes into shutdown mode, we always pull the exact same reading from it. This is because it is no longer updating those registers.

Example 3 Shutdown

After 50 more readings, the UV sensor powers back on and starts taking readings. This process looks like the image below in serial. Notice how the first reading after we turn the sensor back on is garbage.

Example 3 Power Up

Example 4 - Calculate UVI

In this example we will go through the steps of calculating the UV Index from our raw UVA and UVB values, which the library does for you. However, it’s always good to take a bit of a deeper dive into these things. To begin, go ahead and open up File > Examples > Examples from Custom Libraries > SparkFun VEML6075 UV Sensor > Example4_Calculate_UVI. The UV index can be calculated based on the average irradiance of our UVA and UVB light. This irradiance has a linear relation to our UV index, check out the chart below from the VEML6075 Application Guide to see the relationship between irradiance and UV index.

The VEML6075 is based around a silicon photodiode, which is susceptible to not only UV, but also visible light and wavelengths as low as infrared. This generates undesirable noise in our UV signal, so we factor in values from visible (uv.visibleCompensation()) and infrared (uv.irCompensation()) noise compensation registers. To get a little more accuracy out of this signal, you’ll have to calibrate it against the golden sample under a solar simulator like a Newport LCS-100, using a calibrated UVI meter such as a Davis 6490 UVI sensor changing the values of the below constants, located at lines 32-35.

The numerator in each of these constants will be the value from your VEML6075 UV sensor, while the denominator will be the value from the Davis UVI sensor. For example, if you were to change the value of ? you would divide the UVA measurement from the VEML6075 by the UVA measurement from the Davis 6490. Setting these constants to 1.0 essentially eliminates this calibration. In 90% of cases, this “golden sample” calibration won’t be used, but if you do use it, make sure you calibrate your values once the Qwiic UV Sensor has been placed into it’s final enclosure.

The main calibration occurs by adjusting the values of the visible and infrared noise compensation we obtain from the UV sensor. The application manual gives us values for the coefficients, shown in lines 47-50.

The responsivity converts the raw 16-bit data from the chip into something in units of W/m2. Changing the dynamic and integration time will change the responsivity of the sensor, so be careful changing these values, as you’ll have to change the responsivity on lines 41-42.

After we have all of these constants set up, we initialize our UV sensor like we normally do, then begin reading values from our sensor and doing the necessary math to convert our irradiance values into UV indices. The code in the void loop() that accomplishes this is shown below.