LM393 as Light Level Sensor


  • Hero Member

    I've been playing with the LM393 analog output as a light level sensor using the sensor code from the MySensor site. Usin ghe divisor values in the sketch

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

    it appears to have a very very narrow range from full dark to full brightness. Using it indoors in a dark room i've seen a reading of about 35+/- and in a fully lit room a reading of 60+/-. Is this normal for this sensor or is mine just not up to par?

    I've ordered some of the BH1750 sensors for "production" use so i'm hoping they will be better.

    Thanks
    John


  • Hero Member

    I have the same problem.
    Too narrow range.
    Another problem I have is the readings spike all over the place.
    With the same light, it fluctuates a few decimals up and down.
    I ended up adding some code to reduce the spikes and have a more linear curve.

    Here's what I did with the condition in the loop function:

     if (lightLevel != lastLightLevel) {
         if(lightLevel > lastLightLevel + 0.3 || lightLevel < lastLightLevel - 0.3){
              gw.sendVariable(CHILD_ID_LIGHT, V_LIGHT_LEVEL, lightLevel);
              lastLightLevel = lightLevel;
         }
     }

  • Hero Member

    @ferpando I haven't seen that level or rate of change myself, but a little hysteresis rarely hurts 🙂


  • Hero Member

    I ordered one of the other light sensor type to test the differences.


  • Mod

    Do not mix digital and analogue outputs of the light sensor
    Lm393 is used to switch from low to high above the light threshold. Etc. it provides digital (binary) output. If you connect it to arduino analogue ping you mostly will read binary data with some noise.
    Analogue output of this sensor is bypassing lm393 and provides you a range of analogue levels depending on the light level

    For me a cheap 5mm round photoresistor is very sufficient as a light sensor. Just create a divider with photoresistor on bottom and fixed resistor on top. Fixed resistor should be with resistance much lower than dark resistance of the photoresistor, so you will read 1023 in a dark room


Log in to reply
 

Suggested Topics

  • 87
  • 9
  • 2
  • 1
  • 7
  • 8

19
Online

11.2k
Users

11.1k
Topics

112.5k
Posts