Datasheet
At this point you can read the value property to get a reading of the light seen by the photocell. Try it:
Try covering the photocell with your hand to block the light it can see and read the value again:
Notice the value changed! When the sensor sees less light the value is reduced. The more light the sensor sees, the
higher the value.
You might wonder, what's the range of possible values? It turns out for an analog input in CircuitPython the maximum
values range from 0 to 65535 (or the maximum 16-bit unsigned integer value). If you shine an extremely bright light on
the photocell you might see a value near 65k, and if you completely block the sensor you might see a value down
near 0.
If you're curious you can also convert this value into a voltage that's higher or lower depending on how much light is
hitting the sensor. Let's make a function to do this:
Cool! Notice the voltage increases up to near 3.3 volts as the light hitting the photocell increases. If you cover the
photocell up and read the voltage you'll see it falls down near 0 volts.
You can use either the raw value or voltage to check how much light is hitting the photocell. Both will change
proportionally to the amount of light hitting the sensor.
photocell = analogio.AnalogIn(board.A1)
photocell.value
photocell.value
def analog_voltage(adc):
return adc.value / 65535 * adc.reference_voltage
volts = analog_voltage(photocell)
print('Photocell voltage: {0}V'.format(volts))
© Adafruit Industries https://learn.adafruit.com/photocells Page 22 of 25










