Arduino Uno

Header

Corner
-->

Light sensor

Schematics

light sensor schematics

Photo

light sensor

Sample code

01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
// the pin where the temperature is to be mesured
int lightPin = 5;

void setup()
{
// open te serial output with 115200 baud
Serial.begin(115200);
}

void loop()
{
// read the light
int lightReading = analogRead(lightPin);
// calculate the percentage
float percent = lightReading / 1024.0 * 100;
// round to two decimals
percent = floor(percent*100) / 100;
// print it on the serial output
Serial.println(percent);
// wait a second
delay(1000);
}