Light Sample
This sample demonstrates reading the IR and UV Index.

To run the sample:

    2.
    Copy the sample code to a folder on the Raspberry Pi.
    3.
    Open terminal, and then go to the folder you copied the sample.
    4.
    Run the sample with the following command:
1
python3 light.py
Copied!

Sample Code

light.py
1
#!/usr/bin/env python3
2
3
#This sample demonstrates reading the IR and UV Index.
4
#Install Sensor uHAT library with "pip3 install turta-sensoruhat"
5
6
from time import sleep
7
from turta_sensoruhat import Turta_UV_Light
8
9
#Initialize
10
light = Turta_UV_Light.UVAmbientLightSensor()
11
12
try:
13
while True:
14
#Read UV Index
15
uv = light.read_uv()
16
17
#Read Raw IR
18
ir = light.read_ir()
19
20
#Print the readings
21
print("UV Index........: " + str(round(uv, 1)))
22
print("IR Raw Value....: " + str(ir))
23
24
#Wait
25
sleep(2.0)
26
27
#Exit on CTRL+C
28
except KeyboardInterrupt:
29
print('Bye.')
Copied!

Result

When you run the sample, it prints the light data. The example output should be like this:
1
UV Index........: 3.4
2
IR Raw Value....: 0
3
-----
Copied!
To stop the Python script, just press CTRL + C.
Last modified 1yr ago
Copy link