Example Code for Raspberry Pi-UV Index Reading

Last revision 2025/12/30

Print UVA index, UVB index and UV index on the Raspberry Pi terminal. Users can learn how to interface the SEN0303 sensor with Raspberry Pi via I2C and read UV data using Python.

Hardware Preparation

  • Raspberry Pi 3B+ (Quantity: 1)
  • Gravity: VEML6075 UV Sensor (SKU: SEN0303, Quantity: 1)

Software Preparation

  • Development Tool: Python 3 (pre-installed on Raspberry Pi OS)
  • Library: DFRobot_VEML6075 Library (Download Link)

Wiring Diagram

Connect the sensor to Raspberry Pi 3B+ as shown below:

Connection Raspberry Pi

  • Connect the sensor VCC to Raspberry Pi 3.3V
  • Connect the sensor GND to Raspberry Pi GND
  • Connect the sensor SCL to Raspberry Pi SCL (BCM P3 / Physical Pin 5)
  • Connect the sensor SDA to Raspberry Pi SDA (BCM P2 / Physical Pin 3)

Other Preparation Work

  1. Enable I2C on Raspberry Pi: Follow the official guide.
  2. Download the DFRobot_VEML6075 Library to your Raspberry Pi.
  3. Enter the directory of Raspberry Pi example codes
    cd /DFRobot_VEML6075-master/python/raspberry/examples
    
  4. Run Raspberry Pi example codes
    python DFRobot_VEML6075_demo.py
    

DFRobot_VEML6075_demo.py

# -*- coding: utf-8 -*-
'''!
  @file DFRobot_VEML6075_demo.py
  @brief normal test for VEML6075
  @n     UVA index, UVB index and UV index will print on terminal 
  @copyright  Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
  @license     The MIT License (MIT)
  @maintainer [Fary]([email protected])
  @version  V1.0
  @date  2021-10-18
  @url https://github.com/DFRobot/DFRobot_VEML6075
'''

import time
import sys
sys.path.append("..")

from DFRobot_VEML6075 import DFRobot_VEML6075

if __name__ == '__main__':

  VEML6075 = DFRobot_VEML6075(1, 0x10)  # use i2c bus 1, module address is 0x10

  while VEML6075.begin() != True:
    print("VEML6075 begin faild")
    time.sleep(2)
  print("VEML6075 begin succeed")

  while True:
    Uva = VEML6075.get_uva()           # get UVA
    Uvb = VEML6075.get_uvb()           # get UVB
    Uvi = VEML6075.get_uvi(Uva, Uvb)   # get UVI
    print("")
    print("======== start print ========")
    print("UVA:     %.2f" %(Uva))
    print("UVB:     %.2f" %(Uvb))
    print("UVI:     %.2f" %(Uvi))
    print("mw/cm^2: %.2f" %(VEML6075.uvi2mwpcm2(Uvi)))
    print("======== end print ==========")
    time.sleep(1)

Result

The terminal will display UVA, UVB, UVI, and intensity values. A sample output is shown below:

Result on Raspberry Pi

Was this article helpful?

TOP