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:


Sample Code
#!/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
light = Turta_UV_Light.UVAmbientLightSensor()
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))
#Exit on CTRL+C
except KeyboardInterrupt:


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.