Skip to main content

RAK12019 WisBlock UV Sensor Quick Start Guide

Prerequisite

What Do You Need?

Before going through each and every step on using the RAK12019 WisBlock UV Sensor Module, make sure to prepare the necessary items listed below:

Hardware

Software

Product Configuration

Hardware Setup

The RAK12019 is an Ambient Light Sensor (ALS) or Ultraviolet Light Sensor (UVS), which is part of the RAKwireless WisBlock sensor series. The measured ambient light intensity and ultraviolet index are interfaced via the I2C bus making it immune to electrical noises, unlike its analog output counterpart. This module utilizes the LTR-390UV-01 sensor from Lite-On. For more information about RAK12019, refer to the Datasheet.

RAK12019 module can be connected to the sensor's slot of WisBlock Base to communicate with the WisBlock Core, as shown in Figure 1. It will work on SLOT C to F. Also, always secure the connection of the WisBlock module by using compatible screws.

Figure 2560: RAK12019 Connection to WisBlock Base

Assembling and Disassembling of WisBlock Modules

Assembling

As shown in Figure 2, the location for Slot A, B, C, and D are properly marked by silkscreen. Follow carefully the procedure defined in WisBlock Base board assembly/disassembly instructions to attach a WisBlock module. Once attached, carefully fix the module with three pieces of M1.2 x 3 mm screws.

Figure 2561: RAK12019 assembly to WisBlock Base
Disassembling

The procedure in disassembling any type of WisBlock modules is the same.

  1. First, remove the screws.
Figure 2562: Remove screws from the WisBlock module
  1. Once the screws are removed, check the silkscreen of the module to find the correct location where force can be applied.
Figure 2563: Detach silkscreen on the WisBlock module
  1. Apply force to the module at the position of the connector, as shown in Figure 5, to detach the module from the baseboard.
Figure 2564: Apply even forces on the proper location of a WisBlock module
NOTE

If you will connect other modules to the remaining WisBlock Base slots, check on the WisBlock Pin Mapper tool for possible conflicts.

After all this setup, you can now connect the battery (optional) and USB cable to start programming your WisBlock Core.

warning
  • Batteries can cause harm if not handled properly.
  • Only 3.7-4.2 V Rechargeable LiPo batteries are supported. It is highly recommended not to use other types of batteries with the system unless you know what you are doing.
  • If a non-rechargeable battery is used, it has to be unplugged first before connecting the USB cable to the USB port of the board to configure the device. Not doing so might damage the battery or cause a fire.
  • Only 5 V solar panels are supported. Do not use 12 V solar panels. It will destroy the charging unit and eventually other electronic parts.
  • Make sure the battery wires match the polarity on the WisBlock Base board. Not all batteries have the same wiring.

Software Configuration and Example

In this example, you will be able to see the Lux and ALS or UVS and UVI data via Serial Monitor.

  1. Install the RAKwireless Arduino BSP for WisBlock by using the package_rakwireless_index.json board installation package. The WisBlock Core should now be available on the Arduino IDE.

  2. You need to select first the WisBlock Core you have, as shown in Figure 6 to Figure 8.

RAK4631 Board

Figure 2565: Select RAK4631 as WisBlock Core

RAK11200 Board

Figure 2566: Select RAK11200 as WisBlock Core

RAK11310 Board

Figure 2567: Select RAK11300 as WisBlock Core
  1. Copy the example code below:
Click to view the code
/**
@file RAK12019_UVlight_LTR390.ino
@author rakwireless.com
@brief Example of reading ambient light or ultraviolet light data
@version 0.1`
@date 2021-09-13
*/
#include <Wire.h>
#include "UVlight_LTR390.h" //Click here to get the library: http://librarymanager/All#RAK12019_LTR390

//if set LTR390_MODE_ALS,get ambient light data, if set LTR390_MODE_UVS,get ultraviolet light data.

UVlight_LTR390 ltr = UVlight_LTR390();
/*
For device under tinted window with coated-ink of flat transmission rate at 400-600nm wavelength,
window factor is to compensate light loss due to the lower transmission rate from the coated-ink.
a. WFAC = 1 for NO window / clear window glass.
b. WFAC >1 device under tinted window glass. Calibrate under white LED.
*/
void setup()
{
pinMode(LED_BLUE, OUTPUT);
digitalWrite(LED_BLUE, HIGH);
// Initialize Serial for debug output
time_t timeout = millis();
Serial.begin(115200);
while (!Serial)
{
if ((millis() - timeout) < 5000)
{
delay(100);
}
else
{
break;
}
}
//Sensor power switch
pinMode(WB_IO2, OUTPUT);
digitalWrite(WB_IO2, HIGH);
delay(300);

Serial.println("RAK12019 test");
Wire.begin();
if (!ltr.init())
{
Serial.println("Couldn't find LTR sensor!");
while (1)
delay(10);
}
Serial.println("Found LTR390 sensor!");

//if set LTR390_MODE_ALS,get ambient light data, if set LTR390_MODE_UVS,get ultraviolet light data.
ltr.setMode(LTR390_MODE_ALS); //LTR390_MODE_UVS
if (ltr.getMode() == LTR390_MODE_ALS)
{
Serial.println("In ALS mode");
}
else
{
Serial.println("In UVS mode");
}

ltr.setGain(LTR390_GAIN_3);
Serial.print("Gain : ");
switch (ltr.getGain())
{
case LTR390_GAIN_1:
Serial.println(1);
break;
case LTR390_GAIN_3:
Serial.println(3);
break;
case LTR390_GAIN_6:
Serial.println(6);
break;
case LTR390_GAIN_9:
Serial.println(9);
break;
case LTR390_GAIN_18:
Serial.println(18);
break;
default:
Serial.println("Failed to set gain");
break;
}
ltr.setResolution(LTR390_RESOLUTION_16BIT);
Serial.print("Integration Time (ms): ");
switch (ltr.getResolution())
{
case LTR390_RESOLUTION_13BIT:
Serial.println(13);
break;
case LTR390_RESOLUTION_16BIT:
Serial.println(16);
break;
case LTR390_RESOLUTION_17BIT:
Serial.println(17);
break;
case LTR390_RESOLUTION_18BIT:
Serial.println(18);
break;
case LTR390_RESOLUTION_19BIT:
Serial.println(19);
break;
case LTR390_RESOLUTION_20BIT:
Serial.println(20);
break;
default:
Serial.println("Failed to set Integration Time");
break;
}

ltr.setThresholds(100, 1000); //Set the interrupt output threshold range for lower and upper.
if (ltr.getMode() == LTR390_MODE_ALS)
{
ltr.configInterrupt(true, LTR390_MODE_ALS); //Configure the interrupt based on the thresholds in setThresholds()
}
else
{
ltr.configInterrupt(true, LTR390_MODE_UVS);
}
}

void loop()
{
if (ltr.newDataAvailable())
{
if (ltr.getMode() == LTR390_MODE_ALS)
{
Serial.printf("Lux Data:%0.2f-----Als Data:%d\r\n", ltr.getLUX(), ltr.readALS()); //calculate the lux
}
else
{
Serial.printf("Uvi Data:%0.2f-----Uvs Data:%d\r\n", ltr.getUVI(), ltr.readUVS());
}
}
delay(500);
}
NOTE

If you experience any error in compiling the example sketch, check the updated code for the RAK12019 WisBlock UV Sensor Module that can be found on the RAK12019 WisBlock Example Code Repository.

  1. Install the required library, as shown in Figure 9 and Figure 10.
Figure 2568: Get the Library link
Figure 2569: Install the Library
  1. Select the right Serial Port and upload the code, as shown in Figure 11 and Figure 12.
NOTE

If you are using the RAK11200 as your WisBlock Core, the RAK11200 requires the Boot0 pin to be configured properly first before uploading. If not done properly, uploading the source code to RAK11200 will fail. Check the full details on the RAK11200 Quick Start Guide.

Figure 2570: Select the correct Serial Port
Figure 2571: Upload the sample code
  1. When you have successfully uploaded the sample code, you may open up your serial monitor as shown in Figure 13. You can try to experiment with the data by manipulating the light source.
Figure 2572: Serial Monitor reading in ALS mode
Figure 2573: light_source
  1. You can also try to switch to UV mode by changing this line of code as shown in Figure 15. And see the sensor reading in Serial Monitor as shown in Figure 16
Figure 2574: Switch the LTR390 to UV mode
Figure 2575: Serial Monitor reading in UV mode