Light Sample

This sample demonstrates reading the IR and UV Index.

To run the sample:

  1. Copy the sample code to a folder on the Raspberry Pi.

  2. Open terminal, and then go to the folder you copied the sample.

  3. Run the sample with the following command:

python3 light.py

Sample Code

light.py
#!/usr/bin/env python3
#This sample demonstrates reading the IR and UV Index.
#Install Sensor uHAT library with "pip3 install turta-sensoruhat"
from time import sleep
from turta_sensoruhat import Turta_UV_Light
#Initialize
light = Turta_UV_Light.UVAmbientLightSensor()
try:
while True:
#Read UV Index
uv = light.read_uv()
#Read Raw IR
ir = light.read_ir()
#Print the readings
print("UV Index........: " + str(round(uv, 1)))
print("IR Raw Value....: " + str(ir))
#Wait
sleep(2.0)
#Exit on CTRL+C
except KeyboardInterrupt:
print('Bye.')

Result

When you run the sample, it prints the light data. The example output should be like this:

UV Index........: 3.4
IR Raw Value....: 0
-----

To stop the Python script, just press CTRL + C.