In this example we will connect a GA1A12S202 Log-Scale Analog Light Sensor to an Arduino Due
The features of this sensor are as follows
Output voltage increases with light on the sensor
Logarithmic response not only gives more sensitivity in low light, its also almost impossible to “max-out” the sensor
Dynamic range of 3 to 55,000 Lux
Use indoors and outdoors without needing to recalibrate
Illuminance | Example |
---|---|
0.002 lux | Moonless clear night sky |
0.2 lux | Design minimum for emergency lighting |
0.27 – 1 lux | Full moon on a clear night |
3.4 lux | twilight under a clear sky |
50 lux | Family living room |
80 lux | Hallway/toilet |
100 lux | Very dark overcast day |
300 – 500 lux | Sunrise or sunset on a clear day. |
1,000 lux | Overcast day |
10,000 – 25,000 lux | Full daylight |
32,000 – 130,000 lux | Direct sunlight |
Again these are typically best used in breakout/module form. Here is a picture of the module
Connection
Vcc – 3.3v
Gnd – Gnd
Out – A0
Code
[codesyntax lang=”cpp”]
int sensorPin = A0; // float rawRange = 1024; float logRange = 5.0; void setup() { Serial.begin(9600); } void loop() { // read the raw value from the sensor: int rawValue = analogRead(sensorPin); Serial.print("Raw = "); Serial.print(rawValue); Serial.print(" - Lux = "); Serial.println(RawToLux(rawValue)); delay(1000); } float RawToLux(int raw) { float logLux = raw * logRange / rawRange; return pow(10, logLux); }
[/codesyntax]
Results
Open the Serial monitor and you should something like this
Raw = 442 – Lux = 143.95
Raw = 443 – Lux = 145.57
Raw = 443 – Lux = 145.57
Raw = 443 – Lux = 145.57
Raw = 442 – Lux = 143.95
Raw = 444 – Lux = 147.22
Raw = 659 – Lux = 1651.10
Raw = 703 – Lux = 2707.80
Raw = 695 – Lux = 2474.88
Raw = 689 – Lux = 2313.44
Raw = 754 – Lux = 4804.42
Raw = 788 – Lux = 7041.35
Raw = 458 – Lux = 172.32
Raw = 455 – Lux = 166.60
The sensor was covered and moved close to a desktop lamp – the higher values