-
Notifications
You must be signed in to change notification settings - Fork 71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bright status in motion.h #215
Comments
I'm not sure - sqrt() is a big function on a 8bit CPU. It will eat up a lot of flash space. May be we add this a alternative implementation which can be enabled by a define. |
sqrt() takes only 56 byte - but i will do some further checks. There is still a huge deviation if i compare the brightness values of an HM-Sen-MDIR and my solution with sqrt(). I will come back on this... |
The big question here is which range we really need to consider and report for the use case of a motion sensor. We get a lux value which can go up to at least 40k accoridng to the datasheet of the TSL2561. 40k is direct sunshine at a real bright summer day according to what I found. The values inside a living room are 50-200 lux or 200-300 lux with general illumination. For a working desk 500-1000 lux should be targeted. In my opinion the brightness of the motion sensor is used to define when a motion should turn on the light. So if it's brighter than my desk in the room I would consider that it's bright enough that no light needs to be turned on, so higher values than 1000 lux could be already reported as 255. Maybe setting this limit a bit higher makes more sense, but I hope you get my point here in general. This will leave more room for the more useful lower values. The current implementation takes the high possible range into account, but it doesn't make the sensors comparable. |
This is only a sample implementation. The important part is that is work with any light sensor out of the box. All absolute values depend from the use hardware. One open task is to store the maximal measured value into the flash. Then the battery change is no longer a problem. |
I was wondering about far to high brightness values after starting the motion sensor sketch/device.
The root cause for it sits in motion.h
The first bright measurement value sets the maxbright value, so that the return value will be 255 and it takes a whole day cycle to get the highest bright value for setting the maxvalue to a resonable size.
A better solution could be - assuming the followin:
BH1750 measures the brightness in lux _brightness is a uint16_t
TSL2561 measures the brightness in lux _brightness is a uint16_t
MAX44009 measures the brightness in lux _brightness is a uint16_t
So we get in any case a 16bit integer, reflecting a lux value.
Motion.h transmits an 8bit brightness value, so the challange is to scale down.
In the code above it is linear and if the sensor is in an bright environment the sensitivity is reduced.
If we would replace the code with:
sqrt will scale down the brightness with an exponent of 2, which looks like
What do you think?
The text was updated successfully, but these errors were encountered: