Android Question How do I detect the ambient light sensor?

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
Hi Erel
thanks for this forum
How do I detect the ambient light sensor?
i want create book project that change bright screen in night and day
is light sensor in SensorEvent(phone library)?
 

Baltazar

Member
Licensed User
Longtime User
Did you try using the camera? Set a reference frame for both day and night then on a periodic basis, say every minute, grab a frame and compare.
Many years back, I did a motion sensing program in Delphi using webcam with this approach. I think it would work also. But take note of the time involved in monitoring :) . The reference frames can also be omitted if you have already established the levels of RGB in both night and day frames.
 
Upvote 0

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
Did you try using the camera? Set a reference frame for both day and night then on a periodic basis, say every minute, grab a frame and compare.
Many years back, I did a motion sensing program in Delphi using webcam with this approach. I think it would work also. But take note of the time involved in monitoring :) . The reference frames can also be omitted if you have already established the levels of RGB in both night and day frames.
no but camera cannot detect light,isn't?
 
Upvote 0

Baltazar

Member
Licensed User
Longtime User
no but camera cannot detect light,isn't?
It is not really intended for that purpose. But if you are thinking of coming up with a light detector when there is no dedicated light detector in your mobile device, it can be used with some programming. The RGB values of the picture taken by your cam is higher at daytime (light) than at nighttime (darkness). We are of course assuming a normal ambient. If you are thinking of a well lit stadium , for instance, then even a dedicated light detector will not detect day and night. It will take me a little while to write a sample detector using cam because I'm busy now but I can make it work because I have practically done it in a PC.
 
Upvote 0

derez

Expert
Licensed User
Longtime User
B4X:
Dim phs As PhoneSensors
...
phs.Initialize(phs.TYPE_LIGHT)
phs.StartListening("phs")
...

Sub phs_SensorChanged (Values() As Float)
Log(Values(0))
End Sub
 
Upvote 0
Top