Lilypad - The Light Sensor


lightsensor2.jpg
Lilypad Light Sensor
Description:

Senses the amount of light hitting its surface. Returns a value of between 0 and 1023 where 0 equals maximum darkness and 1023 equals maximum brightness.

Connecting:

1. Connect the positive petal on the Light Sensor to the positive petal on the Lilypad Main Board.
2. Connect the negative petal on the Light Sensor to the negative petal on the Lilypad Main Board.
3. Connect the "S" petal on the Light Sensor to one of the analog input petals on the Lilypad Main Board e.g. "a0".

NB: If you are using alligator leads to prototype then make sure that the teeth of your clips make good contact with the metal parts of the sensor petals. If not, you will get inconsistent results.


Getting Data From:


circuitlight1.jpg
Light Sensor and LED connected to Lilypad

Getting data from any analog input involves writing a sketch to read that input using the anlogRead() function. A good basic example of this is the Arduino example AnalogInSerial sketch (File > Examples > Analog > AnalogInSerial). This sketch will read any analog input and then output the result to the serial monitor. This is a good way to check the range of values that your sensor is giving.

The circuit in the picture above uses the light sensor to control the brightness of an LED via this sketch below (lightSensorFadeLED.pde).


sensorled.png
Sketch to Fade LED based on Light Sensor Readings


Links: