Home » ESP32 and GA1A12S202 light sensor example

ESP32 and GA1A12S202 light sensor example

by shedboy71

In this example we will connect a GA1A12S202 Log-Scale Analog Light Sensor to an ESP32 LOLIN32 module from Wemos.

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

GA1A12S202

GA1A12S202

Parts Required

Here are the parts I used

 

Name Link
ESP32
GA1A12S202
Connecting cables

Connection

Vcc – 3v
Gnd – Gnd
Out – 36

LOLIN32 and GA1A12S202

LOLIN32 and GA1A12S202

Code

int sensorPin = 36; //
float rawRange = 4096;
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);
}

 

Results

Open the Serial monitor and you should something like this

Raw = 1235 – Lux = 32.18
Raw = 1227 – Lux = 31.46
Raw = 192 – Lux = 1.72
Raw = 26 – Lux = 1.08
Raw = 1216 – Lux = 30.51
Raw = 720 – Lux = 7.57
Raw = 2001 – Lux = 277.09
Raw = 1759 – Lux = 140.35
Raw = 1259 – Lux = 34.42

The sensor was covered and moved close to a desktop lamp – the higher values

You may also like

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.