LM393 as Light Level Sensor
-
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
-
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; } }
-
@ferpando I haven't seen that level or rate of change myself, but a little hysteresis rarely hurts
-
I ordered one of the other light sensor type to test the differences.
-
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 levelFor 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
Suggested Topics
-
Over the air updates
General Discussion • 23 Mar 2014, 21:38 • ToSa 1 Mar 2015, 11:21 -
"Remote Irrigation with LoRaWAN: LM27313 Challenges and PCB Design"
Hardware • 24 Jan 2024, 23:06 • wrendral 3 Feb 2024, 07:13 -
Best time of year to buy higher quality small project solar panels?
Hardware • 10 Jun 2021, 19:19 • NeverDie 30 Aug 2024, 14:01 -
Sensors and more
Hardware • 19 Jun 2023, 00:41 • Robert Leverett 19 Jun 2023, 00:41 -
Sensor to detect marijuana vape/smoke
Hardware • 21 Jan 2025, 06:36 • Hellmark 25 Feb 2025, 20:56 -
Does MySensors require Arduino Timer 2?
Hardware • 6 Jan 2024, 19:39 • OldSurferDude 11 Jan 2024, 04:39