File tree 1 file changed +33
-0
lines changed
1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments