Light sensor calculation



  • Hi,

    I am looking at light sensor LM393 and wonder about the logic.

    int lightLevel = (1023-analogRead(LIGHT_SENSOR_ANALOG_PIN))/10.23;
    

    First part ((1023-analogRead(LIGHT_SENSOR_ANALOG_PIN)) I understand the thinking to.... little light = low value and it's logical but for the division by 10.23 I cannot understand the reason.
    Can anyone enlighten me? 😉


  • Admin

    The division is there to get a percentage value between 0-100.



  • Ha 🙂 stupid me ...of course....thanks
    I however feel it get "0" (no light at all) with still some light and will remove that division to have a bit more "sensitivity".

    Would also be nice to have some comments in the source about these calculations to make it easier to understand the thought behind 😉


  • Hero Member

    @jocke4u The biggest number that can fit in the register that holds the light sensor value is integer 1023 (based on the register size). Given the range of 0-1023, the formula will return a value of 1 to 100. For my light sensor I changed it to a direct read with no modification, because I like you was more interested in accuracy for lower light level values. Maybe in direct sunlight you would get 1023, but indoors my max is about 500.


  • Hero Member

    Have you guys had luck with the sensitivity on these? I also removed the division but I'm still not satisfied with the sensitivity.
    Would it make a difference if I connect the "light sensor" to 3.3V insted of 5v? I'm using it with a Pro Mini 3.3 that I also feed with 5v on the raw pin.


  • Hero Member

    @korttoma I think I am using a different light sensor then you (AmbiLight Sensor). For my sensor it was recommended to hook a 100k resistor in series with the output to improve low end sensitivity. You may want to try that on your light sensor. Seemed to work for me. They also said if you want to improve the top end (readings max out) use a resistor in parallel with the output.



  • I'm just curious. What is the benefits and difference between a Lux and Photosensitive sensor?


Log in to reply
 

Suggested Topics

44
Online

11.4k
Users

11.1k
Topics

112.6k
Posts