Skip to content

Commit 30bec08

Browse files
committed
Added light sensor example
1 parent 73b4a88 commit 30bec08

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
GA1AS202 Light sensor
3+
4+
reads sensor on analog inout, outputs light value in lux
5+
6+
Slight rearrangement of Bill Earl's example for Adafruit,
7+
with more notes.
8+
9+
This version assumes a 3.3V supply for the board, not 5V.
10+
If you're using a 5V board, attach AREF to 3.3V and add this to setup:
11+
analogReference(EXTERNAL);
12+
13+
modified 22 Jan 2016
14+
by Tom Igoe
15+
*/
16+
17+
void setup() {
18+
Serial.begin(9600); // initialize serial communication
19+
}
20+
21+
void loop() {
22+
// read the sensor:
23+
int lightSensor = analogRead(A0);
24+
/*
25+
Top of sensor range is 100000 (10^5) lux.
26+
(the 5.0 below is the exponent, NOT 5V)
27+
Lux changes on a log10 scale, so you need to
28+
use the power (pow()) function to do the conversion:
29+
*/
30+
float lux = lightSensor * 5.0 / 1024;
31+
lux = pow(10, lux);
32+
Serial.println(lux);
33+
}

0 commit comments

Comments
 (0)