tf
Created November 5, 2023 © GPL3+

UV Risk Monitor ("XMC-for-Arduino" Demo)

A simple UV risk monitor demo featuring "XMC-for-Arduino" ...

BeginnerFull instructions provided3.14159265359 hours34
UV Risk Monitor ("XMC-for-Arduino" Demo)

Things used in this project

Hardware components

Infineon XMC1300 Boot Kit
Infineon XMC1300 Boot Kit
×1
Gravity Analog UV Sensor V2
DFRobot Gravity Analog UV Sensor V2
Or any other GUVA-S12SD based UV sensor board ...
×1
LED, RGB
LED, RGB
Any RGB LED will do. Common cathode is fine. A breakout solution with appropriate limiting resistors makes it easier to use.
×1
Illuminable plastic figure (e.g., an illuminable rabbit)
;)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Infineon XMC-For-Arduino
Integration of Infineon's XMC microcontrollers into the Arduino IDE.

Hand tools and fabrication machines

Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Custom parts and enclosures

Prototype / Demo

Schematics

Connection Schema / Diagram

The connection schema / diagram ...

Code

XMC_4_Arduino_UV_Risk_Monitor_Demo.ino

Arduino
XMC 4 Arduino - UV Risk Monitor
Demo sketch for a GUVA-S12SD UV sensor connected to an Infineon XMC1300 Boot Kit board.
The collected UV index is visualized by a RGB LED.
// XMC 4 Arduino - UV Risk Monitor
// Demo sketch for a GUVA-S12SD UV sensor
// connected to an Infineon XMC1300 Boot Kit board.
// The collected UV index is visualized by a RGB LED.
// Written by dxcfl, public domain

// REQUIRES the following Arduino libraries:
// - GUVA-S12SD UV Sensor Library: https://github.com/dxcfl/arduino-library-GUVA_S12SD
// - RGB LED Library: https://github.com/dxcfl/arduino-library-RGB_LED

// GUVA-S12SD UV Sensor - connected to pin A0 = P2.4 on the Infineon XMC1300 Boot Kit
#include "GUVA_S12SD.h"
#define GUVA_S12SD_PIN A0      // 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);

// "Standard" RGB LED (with common cathode) connected to pins P0.3, P0.4 and P0.5
#include "RGB_LED.h"
#define RGB_LED_RED_PIN 31
#define RGB_LED_GREEN_PIN 32
#define RGB_LED_BLUE_PIN 33
RGB_LED rgb_led(RGB_LED_RED_PIN, RGB_LED_GREEN_PIN, RGB_LED_BLUE_PIN);

// Misc.
#define UPDATE_CYCLE_MILLIS 10000

// 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};

  Serial.print(F("UV risk level: "));
  if (uv_index < 3)
  {
    Serial.println(F("low"));
    rgb_led->setColor(LOW_GREEN);
  }
  else if (uv_index < 6)
  {
    Serial.println(F("moderate"));
    rgb_led->setColor(MODERATE_YELLOW);
  }
  else if (uv_index < 8)
  {
    Serial.println(F("high"));
    rgb_led->setColor(HIGH_ORANGE);
  }
  else if (uv_index < 11)
  {
    Serial.println(F("very high"));
    rgb_led->setColor(VERY_HIGH_RED);
  }
  else
  {
    Serial.println(F("extreme"));
    rgb_led->setColor(EXTREME_PURPLE);
  }
}

void setup()
{
  Serial.begin(9600);
  Serial.println(F("XMC 4 Arduino - UV Risk Monitor"));
  // Initialize sensor pin ...
  guva_s12sd.begin();
  // Initialize LED pins ...
  rgb_led.begin();
  rgb_led.setOn();
}

void loop()
{
  float vout;
  float uv_index;

  // 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.println();
  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);

  // Show the UV risk level based on the UV index as color with the RGB LED ...
  show_risk_level(&rgb_led, uv_index);

  // Wait between measurements ...
  delay(UPDATE_CYCLE_MILLIS);
}

Arduino library for the GUVA-S12SD UV sensor

Arduino library for controlling a RGB LED

Credits

tf

tf

14 projects • 3 followers

Comments