

The SparkFun Mini Spectral UV Sensor - AS7331 (Qwiic) is a compact and highly versatile sensor designed to measure light intensity across multiple UV wavelengths. It is ideal for applications requiring precise UV detection and analysis, such as environmental monitoring, UV sterilization systems, and scientific research. The sensor leverages the AS7331 spectral sensor, which provides high-resolution measurements of UV light, and integrates seamlessly with the Qwiic connect system for easy and solder-free connections to microcontrollers.








The SparkFun Mini Spectral UV Sensor - AS7331 (Qwiic) is built for precision and ease of use. Below are its key technical details:
The sensor features a Qwiic connector for I²C communication and optional breakout pins for additional flexibility. Below is the pin configuration:
| Pin Name | Description |
|---|---|
| GND | Ground (0V reference) |
| 3.3V | Power supply input (3.3V) |
| SDA | I²C data line |
| SCL | I²C clock line |
| INT | Interrupt pin (optional, not required) |
| ADDR | I²C address selection (optional) |
The SparkFun Mini Spectral UV Sensor - AS7331 (Qwiic) is designed for straightforward integration into your projects. Follow the steps below to use the sensor effectively:
To use the sensor with an Arduino UNO, you will need a logic level shifter since the Arduino operates at 5V logic, while the sensor requires 3.3V. Below is an example code snippet to read data from the sensor:
#include <Wire.h>
// I²C address of the AS7331 sensor
#define AS7331_ADDRESS 0x39
void setup() {
Wire.begin(); // Initialize I²C communication
Serial.begin(9600); // Start serial communication for debugging
// Check if the sensor is connected
Wire.beginTransmission(AS7331_ADDRESS);
if (Wire.endTransmission() == 0) {
Serial.println("AS7331 sensor detected!");
} else {
Serial.println("AS7331 sensor not detected. Check connections.");
while (1); // Halt execution if sensor is not found
}
}
void loop() {
// Request 2 bytes of data from the sensor
Wire.beginTransmission(AS7331_ADDRESS);
Wire.write(0x00); // Replace with the appropriate register address
Wire.endTransmission();
Wire.requestFrom(AS7331_ADDRESS, 2);
if (Wire.available() == 2) {
uint16_t uvData = Wire.read() << 8 | Wire.read(); // Combine MSB and LSB
Serial.print("UV Intensity: ");
Serial.println(uvData);
} else {
Serial.println("Failed to read data from AS7331.");
}
delay(1000); // Wait 1 second before the next reading
}
0x39. If you have multiple devices on the same I²C bus, use the ADDR pin to change the address.INT pin is optional and can be used for event-driven applications, such as triggering an action when UV intensity exceeds a threshold.Sensor Not Detected
No Data or Incorrect Readings
Arduino UNO Compatibility Issues
Q: Can I use this sensor with a Raspberry Pi?
A: Yes, the sensor is compatible with Raspberry Pi via the I²C interface. Use the Qwiic connector or GPIO pins for communication.
Q: What is the maximum I²C bus speed supported?
A: The AS7331 supports I²C speeds up to 400 kHz (Fast Mode).
Q: How do I calibrate the sensor?
A: Calibration is typically not required for most applications. However, for precise measurements, you can use a known UV light source to verify and adjust the readings in your software.
Q: Can this sensor measure visible or infrared light?
A: No, the AS7331 is specifically designed for UV light detection in the 240 nm to 370 nm range.
By following this documentation, you can effectively integrate the SparkFun Mini Spectral UV Sensor - AS7331 (Qwiic) into your projects and achieve accurate UV light measurements.