Datasheet

Here's a complete program that reads the photocell value and prints both the value and voltage every second. Save
this as main.py on your board and open the serial output to see the printed values. Try shining light on the sensor or
covering it up to see how the value and voltage change!
That's all there is to reading a photocell using an analog input with CircuitPython!
import time
import board
import analogio
# Initialize analog input connected to photocell.
photocell = analogio.AnalogIn(board.A1)
# Make a function to convert from analog value to voltage.
def analog_voltage(adc):
return adc.value / 65535 * adc.reference_voltage
# Main loop reads value and voltage every second and prints them out.
while True:
# Read the value, then the voltage.
val = photocell.value
volts = analog_voltage(photocell)
# Print the values:
print('Photocell value: {0} voltage: {1}V'.format(val, volts))
# Delay for a second and repeat!
time.sleep(1.0)
© Adafruit Industries https://learn.adafruit.com/photocells Page 23 of 25