B4R

B4R Arduino GA1A12S202 light sensor example

In this example we will connect a GA1A12S202 Log-Scale Analog Light Sensor to an Arduino.

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!

Again these are typically best used in breakout/module form. Here is a picture of the module

You connect the sensor as follows

Vcc – 5v
Gnd – Gnd
Out – A1 (or you can use another analog in pin but you would need to change the code example)

Layout

 

arduino and GA1A12S202

 

Code

 

[codesyntax lang=”cpp”]

Sub Process_Globals
Public Serial1 As Serial
Private SensorPin As Pin ‘Output pin connected
Private SensorPinNumber As Byte = 0x01 ‘Pin number used is A1 (Analog)
Private MeasureTimer As Timer ‘Timer for the sensor measurement
Private MeasureTimerInterval As ULong = 2 ‘Timerinterval in seconds
End Sub

Private Sub AppStart
Serial1.Initialize(115200)
Log(“AppStart – Pin “, SensorPinNumber, ” read every “, MeasureTimerInterval, ” seconds”)
‘Init the pin with GA1a12s02 connected
SensorPin.Initialize(SensorPinNumber, SensorPin.MODE_OUTPUT)
‘Init the timer
MeasureTimer.Initialize(“MeasureTimer_Tick”, MeasureTimerInterval * 1000)
‘Start the timer
MeasureTimer.Enabled = True
End Sub

‘Handle the timer ticks
Private Sub MeasureTimer_Tick
‘Read the current state of the pin
Dim rawvoltage As UInt = SensorPin.AnalogRead
Log(“Raw voltage: “, rawvoltage)
‘Convert rawvoltage
Dim loglux As Double = (rawvoltage*5.0)/1024.0
Dim luxvalue As Double = Power(10,loglux)
Log(“Lux: “, luxvalue)
End Sub

[/codesyntax]

 

Results

You should see something like the following

AppStart – Pin 1 read every 2 seconds
Raw voltage: 382
Lux: 73.3220
Raw voltage: 382
Lux: 73.3220
Raw voltage: 383
Lux: 74.1510
Raw voltage: 108
Lux: 3.3678
Raw voltage: 274
Lux: 21.7716
Raw voltage: 346
Lux: 48.9162
Raw voltage: 360
Lux: 57.2549
Raw voltage: 366
Lux: 61.2505
Raw voltage: 367
Lux: 61.9430

 

Links

Adafruit GA1A12S202 Log-scale Analog Light Sensor [ADA1384]

Related posts

B4R Arduino TM1637 7 segment display example

B4R Arduino and BH1750 Ambient Light Sensor example

B4R Arduino and ADXL335 accelerometer example