Sample sketch for the AS7331 UV A/B/C light sensor by AMS
Easy to use UV A/B/C light sensor from AMS. The well-commented sketch shows how to configure the sensor, make use of the power saving features, data ready interrupt and properly scale the light and chip temperature data while varying the gain and integration time. Basic error handling is included. Should be a good place to start for any custom applications.
Both CMD (one shot) and CONT (continuous) modes work with the latter sample rate defined by the time variable. gain and (integration) time determine the sensitivity of the sensor to light. For example, use low gain and short integration time for direct sunlight. I used a gain of 1024 and integration time of 512 s to collect the below data from indoors through a window on a cloudy, drizzly day. The sensor is quite sensitive!
I haven't made SYNS or SYND modes work yet.
Sketch makes use of the STM32L432 (Ladybug) development board but should work with just about any Arduino compatible dev board with minor modifications.
Breakout board (pcb-only) design can be found in the OSH Park shared space.
Fully-assembled breakout board available on Tindie and at Elecrow.
2023 Copyright Tlera Corporation