Light Sample
This sample demonstrates reading the IR and UV Index.
- 1.Download the sample code from https://github.com/Turta-io/Sensor-uHAT/blob/master/Samples/Python/light.py
- 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:
python3 light.py
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.')
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.
Last modified 3yr ago