Light sensor on the CPX
The Circuit Playground (Classic, Express and Bluefruit) has an on-board ambient light sensor. The Circuit Playground software library handles the low-level details and the CircuitPlayground.lightSensor()
function returns an 10-bit integer (\(0\le v \le 1023\)), where a value of \(v\sim300\) corresponds to a well lit office environment
Table of contents
Light Sensor
The Circuit Playground Express has an ambient light sensor mounted permanently to the circuit board as shown in the following image.
Reading the Light Sensor with Hello_LightSensor
The Hello_LightSensor
sketch is part of the Adafruit Circuit Playground library. You can open the sketch by selecting File –> Examples –> Adafruit Circuit Playground –> Hello_CircuitPlayground –>Hello_LightSensor. Running the sketch produces light sensor readings in the Serial Monitor.
Light sensor reading scale
Consult the source code in Hello_LightSensor
to see how ambient light readings are made.
The reading of the light sensor is obtained with the statement
value = CircuitPlayground.lightSensor();
where value
is an int
. The reading is an 8-bit value, i.e. an integer in the range between 0 and 1023, where 0 is completely dark and 1023 is the maximum brightness the sensor can record. Typical ambient light levels are about 300 on this scale.