UV Exposure Indicator

by esarder in Circuits > Microcontrollers

325 Views, 1 Favorites, 0 Comments

UV Exposure Indicator

PXL_20220429_230431585.jpg

Colorado's weather changes quickly, and people often find themselves unprepared for the weather. I personally have a hard time remembering to put on sunscreen when it's cloudy out, which often leads to me getting sunburned as I walk outside during the day. I coded a Circuit Playground Express to read the light conditions outside and reflect a range of values using the onboard LEDs to give me a better estimate of the light conditions.

I had originally planned to attach a true UV sensor to sense UVB (280-314 nm) and UVA 315-400nm), which is the range measurements like the UV Index are calculated across. However, the UV sensor I was able to procure seemed to have no support for the Circuit Playground. As a result, I used the onboard light detector, which is an ALS-PT19, which was designed to have close responsiveness to the human eye spectrum of light. Its sensitivity range is 390 nm to 700nm, so it does not cover and of the UVB range and only covers a little of the UVA range. However, if you're able to find a compatible UV sensor, this code should still work well!

Supplies

Code

For this project, I used the Mu editor, a Python editor option for coding with the Circuit Playground.

Here's the code:

import time
import random

from adafruit_circuitplayground import cp

#Setting up initial pixel values
cp.pixels.auto_write = False
cp.pixels.brightness = 0.3

# function to scale the "fake" UV measurements from the onboard light sensor to appear on the 10 LEDs
def uv_scale(I_light):
    fake_UVI = round(I_light/25)
    return round(fake_UVI/12.8 *9)


# code responsively reads in the light sensor value from cp.light, scales it, and turns on the respective LEDs
while True:
    print("Base value:", cp.light)
    pix_val = uv_scale(cp.light)

    # range of color values from bright green (indicating safe UV exposure) to bright red (indicating dangerous
    # UV exposure)
    pixel_colors = [(81, 255, 0), (196, 255, 0), (234, 254, 0), \
        (255, 200, 0), (250, 130, 0), (255, 80, 0), (255, 60, 0), \
        (255, 30, 0), (255, 15, 0), (255, 0, 0)]

    # turns on the pixel values corresponding to how high the UV exposure is
    for i in range(10):
        if i <= pix_val:
            cp.pixels[i] = pixel_colors[i]
        else:
            cp.pixels[i] = (0,0,0)


    cp.pixels.show()
    # code responds to new light conditions every 1/20th of a second
    time.sleep(0.05)


Run It!

UV-indicator

Upload this code to the Circuit Express and watch it go!


In the video, you can see that as I expose the microcontroller to more or less light from my lamp, the LEDs respond.


If you're interested in building a more robust sensor, this article had some great first steps!