Ultraviolet (UV) radiation is a type of electromagnetic radiation that mainly comes from the sun and can have both positive and negative effects on human health. On the one hand, it stimulates the production of vitamin D in the skin - on the other hand, overexposure to UV radiation can cause skin cancer, premature aging of the skin, cataracts, immune suppression, and other skin disorders. The effects of overexposure to UV radiation accumulate over a lifetime. Therefore, it is important to protect yourself from overexposure to UV radiation by wearing protective clothing, hats, and sunglasses; seeking shade during midday hours; and using sunscreen with an SPF of 30 or higher.
The UV index is a measure of the strength of UV radiation from the sun at a particular place on Earth at a particular time. The UV index is measured on a - color-coded - scale of 0 to 11+, with higher values indicating stronger UV radiation, greater potential for damage to the skin and eye, and less time of exposure necessary before harm occurs. It is used to help the public plan sun-safe outdoor activities.
Safe exposure to UV radiation based on the UV index depends on the individual’s skin type and the duration of exposure. However, as a general rule,
- a UV index of 2 or lower is considered safe for all skin types
- A UV index of 3 to 5 is considered moderate and requires some protection.
- A UV index of 6 to 7 is considered high and requires protection such as a hat, sunglasses, and sunscreen.
- A UV index of 8 to 10 is considered very high and requires extra protection such as seeking shade during midday hours and wearing protective clothing.
- A UV index of 11 or higher is considered extreme and requires all possible precautions to be taken.
For more information see e.g.,
- WHO - Newsroom - Q&A - Radiation: The ultraviolet (UV) index
- US EPA - Health Effects of UV Radiation
- US EPA - UV Index Scale
This project demonstrate how to build a very simple monitoring device, which measures the actual UV radiation exposure and shows the derived risk level as colored light in an illuminated object.
Hardware SetupInfineon XMC1300 Boot Kit: The XMC1300 Boot Kit is a XMC1302 Microcontroller in TSSOP-38 with 200KB Flash and full peripheral set of XMC1300 series programmable via the Arduino IDE. This kit utilizes Infineon’s industry leading ARM® Cortex®-M0 microcontroller. Focused on evaluate the capabilities of the XMC1300 Microcontroller multiple applications solutions, it can be used with a wide range of development tools including Infineon’s Modus Toolbox as well as the Arduino IDE. See the product page for more details.
Gravity: GUVA-S12SD Analog UV Sensor: The Gravity: GUVA-S12SD Analog UV Sensor is a UV sensor that uses a UV photodiode to detect the 240-370nm range of light (which covers UVB and most of UVA spectrum). It can detect the UV wavelength of 200-370nm and has a fast response time with linear analog voltage signal output that changes with the intensity of UV light. The output voltage of the module is proportional to the intensity of the UV light detected by the sensor. The sensor is suitable for detecting the UV radiation in sunlight and can be used in UV Index Monitoring, DIY projects, UV-A Lamp Monitoring, Plants growing Environmental monitoring, etc. See the product page and the documentation for more details.
Connection: The Gravity: GUVA-S12SD Analog UV Sensor comes with one Gravity: Analog Sensor Cable for Arduino with a 3 pin JST connector to connect to the sensor and a servo type connector with pins for signal (blue), GND (black) and PWR (red). The sensor is connected to the XMC1300 Boot Kit board as follows:
- Signal - blue wire - to pin P2.4 (corresponds to Arduino pin 0)
- PWR - red wire to any pin labeled VDD
- GND - black wire to any pin labeled VSS
RGB LED: To display the risk level color associated to the measured UV index a RGB LED (common cathode) is connected to the XMC1300 Boot Kit board as follows:
- Red LED anode (with the appropriate limiting resistor) to pin P0.4 (PWM0, corresponds to Arduino pin 31)
- Green LED anode (with the appropriate limiting resistor) to pin P0.5 (PWM2, corresponds to Arduino pin 32)
- Blue LED anode (with the appropriate limiting resistor) to pin P0.3 (PWM3, corresponds to Arduino pin 33)
- Common cathode to any pin labeled VSS
The complete setup:
XMC For Arduino
For instructions how to integrate and program Infineon's XMC Microcontroller using the Arduino IDE follow the excellent guide XMC For Arduino. After completing the steps documented in this guide and importing the two libraries described below you should be able to compile and run the main sketch for this project.
For an easy-to-use interface for the GUVA-S12SD UV sensor a simple Arduino library is provided.
To use the sensor an object of type/class GUVA_S12SD
needs to be declared providing the number of the board pin connected to the signal pin of the sensor and the supply voltage used for the sensor (e.g., 3.3 or 5 Volts):
// Example testing sketch for the GUVA-S12SD UV sensor
// Written by dxcfl, public domain
// REQUIRES the following Arduino library:
// - GUVA-S12SD UV Sensor Library: https://github.com/dxcfl/arduino-library-GUVA_S12SD
#include "GUVA_S12SD.h"
#define GUVA_S12SD_PIN 0 // Analog pin connected to the UV sensor
#define GUVA_S12SD_VOLTAGE 5.0 // Supply voltage for the UV sensor (usually same as board supply voltage)
// Initialize UV sensor.
GUVA_S12SD guva_s12sd(GUVA_S12SD_PIN, GUVA_S12SD_VOLTAGE);
void setup() {
Serial.begin(9600);
Serial.println(F("GUVA-S12SD test!"));
guva_s12sd.begin();
}
void loop() {
float uv_index;
float vout;
// Read the output voltage (mV) from the sensor
vout = guva_s12sd.readOutputVoltage();
// Calculate the UV index based on the sensor's output voltage
uv_index = guva_s12sd.getUvIndex(vout);
Serial.print(F("Sensor GUVA-S12D - Voltage: "));
Serial.print(vout);
Serial.println(F(" mV"));
Serial.print(F("Sensor GUVA-S12D - UV index: "));
Serial.println(uv_index);
Serial.println(F("- - - - - - - - - - - - - - - - - - - - - - - - "));
// Wait a few seconds between measurements.
delay(2000);
}
The library implements two functions to get the output voltage from the sensor and to calculate the resulting UV index based on a specific conversion table for the GUVA_S12SD.
The function GUVA_S12SD::readOutputVoltage
obtains multiple readings from the analog sensor pin, calculates the average and the resulting voltage in millivolt:
/* GUVA_S12SD_READ_OUTPUT_VOLTAGE
Returns the voltage (mV) measured by the sensor.
*/
float GUVA_S12SD::readOutputVoltage()
{
int sensor_value = 0;
int sensor_value_sum = 0;
float vout = 0;
for (int i = 0; i < 1024; i++)
{
sensor_value = analogRead(channel);
sensor_value_sum = sensor_value + sensor_value_sum;
delay(1);
}
sensor_value = sensor_value_sum >> 10;
vout = sensor_value * supplyVoltage * 1000 / getAnalogReadMaximum();
return vout;
}
The other function GUVA_S12SD::getUvIndex
converts the output from the sensor to the corresponding UV index as shown in this table:
/* GUVA_S12SD_UV_INDEX
Function to convert sensor output voltage (mV) to UV index
for a GUVA-S12D based analog UV sensor based on a conversion table.
See http://www.esp32learning.com/code/esp32-and-guva-s12sd-uv-sensor-example.php
for conversion table ...
*/
float GUVA_S12SD::getUvIndex(float vout)
{
const float mv_uvi[12] = {50, 227, 318, 408, 503, 606, 696, 795, 881, 976, 1079, 1170};
int i = 0;
float uvi = 0;
for (i = 0; i < 12; i++)
{
if (vout < mv_uvi[i])
break;
}
if (i < 11)
{
uvi = vout / mv_uvi[i] * (i + 1);
}
else
{
uvi = 11;
}
return uvi;
}
To use this library in this project or other projects
- download the library as ZIP archive from the GitHub repository here
- and follow the instructions to import a .zip library.
This simple Arduino library just encapsulates basic handling of a RGB LED. To use this library in this project or other projects
- download the library as ZIP archive from the GitHub repository here
- and follow the instructions to import a .zip library.
Main Sketch
The main sketch XMC_4_Arduino_UV_Risk_Monitor_Demo.ino
just declares and initialize the handling objects for the GUVA-S12SD sensor and the RGB LED in the setup()
function. In the loop()
function the UV exposure measurements are read and converted into the corresponding UV index. The derived UV index is then converted into RGB colors for the associated risk levels and displayed by the RGB LED.
// Show the risk-level color
// according to https://www.who.int/news-room/questions-and-answers/item/radiation-the-ultraviolet-(uv)-index ,
// Table 4 (Presenting the UVI: International colour codes)
// and https://www.sciencedirect.com/science/article/pii/S2666469023000210 , Table 1
// for the given UV index on a RGB LED
void show_risk_level(RGB_LED *rgb_led, float uv_index)
{
static const int LOW_GREEN[3] = {151, 215, 0};
static const int MODERATE_YELLOW[3] = {252, 227, 0};
static const int HIGH_ORANGE[3] = {255, 130, 0};
static const int VERY_HIGH_RED[3] = {239, 51, 64};
static const int EXTREME_PURPLE[3] = {144, 99, 205};
if (uv_index < 3)
{
rgb_led->setColor(LOW_GREEN);
}
else if (uv_index < 6)
{
rgb_led->setColor(MODERATE_YELLOW);
}
else if (uv_index < 8)
{
rgb_led->setColor(HIGH_ORANGE);
}
else if (uv_index < 11)
{
rgb_led->setColor(VERY_HIGH_RED);
}
else
{
rgb_led->setColor(EXTREME_PURPLE);
}
}
TestSince the weather (clouded sky, rain, storm etc.) during the time implementing this project did not allow outdoor tests the setup was tested using a UV lamp and the results have been verified and compared to measurements made with another setup (see project "Smart UV Meter (Ultraviolet radiation exposure monitoring)") which proved to be accurate.
Demo
For demonstration purposes (and just for fun) the RGB LED has been installed into a illuminable plastic figure (a "Flying Tiger Copenhagen Rabbit" night light) ...
A green rabbit can enjoy its sun bath, a yellow one should not stay for to long in the sunshine. Glowing orange the rabbit should consider applying sunscreen and on red it should stay in the shadow. As a plastic rabbit it can not suffer from skin cancer when staying purple but it might risk to melt down. ;)
Comments