Home Code Raspberry Pi and VEML6070 sensor example

Raspberry Pi and VEML6070 sensor example

by shedboy71

In this article we will take a look at the VEML6070 sensor and connect it to our Raspberry PI. Lets take a look at the VEML6070 first

Sensor Information

The VEML6070 is an advanced ultraviolet (UV) light sensor with I2C protocol interface and designed by the CMOS process. It is easily operated via a simple I2C command. The active acknowledge (ACK) feature with threshold windows setting allows the UV sensor to send out a UVI alert message.

Under a strong solar UVI condition, the smart ACK signal can be easily implemented by the software programming.

VEML6070 incorporates a photodiode, amplifiers, and analog / digital circuits into a single chip. VEML6070’s adoption of FiltronTM UV technology provides the best spectral sensitivity to cover UV spectrum sensing. It has an
excellent temperature compensation and a robust refresh rate setting that does not use an external RC low pass filter.

The VEML6070 has linear sensitivity to solar UV light and is easily adjusted by an external resistor. Software shutdown mode is provided, which reduces power consumption to be less than 1 μA. VEML6070’s operating voltage ranges from 2.7 V to 5.5 V.



Lets look at how you connect the sensor to your Raspberry Pi

An I2C device that just needs 3.3v and GND as well, so its pretty simple to connect to your Raspberry PI, the layout below shows a Raspberry PI 3 but you can use others as well

pi and veml6070 layout

pi and veml6070 layout

Parts List

Here is a parts list generated from the fritzing layout above. The sensor costs about $3 depending on where you buy it from, we have given options for all of the parts below

Name Links
Raspberry Pi 4 Model B Development Board Aliexpress link

Amazon. com link

Ebay search

VEML6070 sensor AliExpress Product

Amazon Link

Ebay link

Connecting wire Aliexpress link

Amazon.com link

Ebay link

Code Example

This is a python example, the code comes from CodeEverything as you can see in the comments

[codesyntax lang=”python”]

# Distributed with a free-will license.
# Use it any way you want, profit or free, provided it fits in the licenses of its associated works.
# VEML6070
# This code is designed to work with the VEML6070_I2CS I2C Mini Module available from ControlEverything.com.
# https://www.controleverything.com/products

import smbus
import time

# Get I2C bus
bus = smbus.SMBus(1)

# I2C address of the device

# VEML6070 Command Set
VEML6070_CMD_ACK_DISABLE				= 0x00 # Acknowledge Disable
VEML6070_CMD_ACK_ENABLE					= 0x20 # Acknowledge Enable
VEML6070_CMD_ACK_THD_102				= 0x00 # Acknowledge threshold 102 Steps
VEML6070_CMD_ACK_THD_145				= 0x10 # Acknowledge threshold 145 Steps
VEML6070_CMD_IT_1_2T					= 0x00 # Integration time = 1/2T
VEML6070_CMD_IT_1T						= 0x04 # Integration time = 1T
VEML6070_CMD_IT_2T						= 0x08 # Integration time = 2T
VEML6070_CMD_IT_4T						= 0x0C # Integration time = 4T
VEML6070_CMD_RESERVED					= 0x02 # Reserved, Set to 1
VEML6070_CMD_SD_DISABLE					= 0x00 # Shut-down Disable
VEML6070_CMD_SD_ENABLE					= 0x01 # Shut-down Enable
VEML6070_CMD_READ_LSB					= 0x38 # Read LSB of the data
VEML6070_CMD_READ_MSB					= 0x39 # Read MSB of the data

class VEML6070():
	def __init__(self):
	def write_command(self):
		"""Select the UV light command from the given provided values"""
	def read_uvlight(self):
		"""Read data back VEML6070_CMD_READ_MSB(0x73) and VEML6070_CMD_READ_LSB(0x71), uvlight MSB, uvlight LSB"""
		data0 = bus.read_byte(VEML6070_CMD_READ_MSB)
		data1 = bus.read_byte(VEML6070_CMD_READ_LSB)
		# Convert the data
		uvlight = data0 * 256 + data1
		return {'u' : uvlight}

from VEML6070 import VEML6070
veml6070 = VEML6070()

while True:
	light = veml6070.read_uvlight()
	print "UV Light Level : %d" %(light['u'])
	print " *********************************** "


copy the code above to your Raspberry PI, open a terminal and run

sudo python VEML6070.py


You should see something like this, I tested this indoors hence the output was 0

veml6070 output

veml6070 output

You may also like

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish. Accept Read More