Full Circle
Its a bit like booze, you know its not good for you but you keep coming back for more!
Anyway I am back looking at the sunrise/sunset transition. I was looking at the Lux curve and noting that the curve has a strong inflection (red circles) between twilight (i.e. dawn/dusk) and sunrise/sunset:

Anyway, here is the first and second derivative:

Now note the curve above is a "standard" curve not a measured curve. So the funny "hook" for Lux' is an artifact of the construction of the "standard" curve. What is interesting is Lux'' as it has a peak around sunrise and sunset. Now this is not surprising, the question is it practical to use this information?
Okay here is some (old) measured data:

And yes it does look promising. Note, the green line is the first derivative of the LDR voltage (the magic on non-linear maths!). The noise on the right hand side can be filtered:

Well that looks very nice! The LDR peaks are very consistent. Some thought needs to be made to avoid false trips but it looks very promising.
Well it ran last night, if I cheat and adjust the assumed altitude for the best result (I can't calculate it at the moment as I do not have a calibrated the LDR sensor), I get:
- Year: 2018
- Month: 2
- Day: 28
- LTC: 8 hours
- Sampling frequency: 1 per minute
- Sunset: 19.0833
- Sunrise: 5.9000 (next day)
- Calibrated Altitude: -3.3 degrees
- Latitude: -32.027 (versus -32.090)
- Longitude: 115.747 (versus 115.844)
This is within 11 km of my true location and within accuracy of the sampling frequency.
So it the results are consistent, especally with cloudy conditions I have a great solution.
Another reading for today;
- 1/3/2018
- LTC: 8 hours
- Sunset: 19.0500
- Lat: -31.479
- Lon: 115.973
- 68.85 km away.
The box site was not the roof this time but in the middle of my back yard. A more typical/practical location.
I reworked the filter (green) but more work is required:

I am currently using a threshold and a simple adjacent value test to determine a peak. I still need a threshold but better to use a sliding window to find the loacl maxima.
It seems as if the sunrise transition this morning was missed. The box site is shaded by a tree from the morning sunlight (unlike the roof position). With the new filter I can lower the threshold significantly. Currently the threshold is about 50% of the full sunlight range. With the new filter this can be reduced to 10% (or less).
New Code
Here is a sunset with the box placed in a window putting up with some ambient room light:

- Cyan curve is the calculated sunlight (Lux) level.
- The green markers are sunset and dusk.
- The blue curve is the ADC reading of the LDR.
- The red curve is the derivative of the ADC-LDR curve.
- The yellow curve is the window maximum calculations. It has a 31 minute window and is delayed 15 minutes.
- Back calculating the altitude of the derivative peak I get -2.5 degrees.
This looks quite promising. It will be interesting to see how much the peak altitude moves in full sunlight. Hopefully not much. I am expecting -3.3 degrees. I will probably have to look at a calibration factor based on the peak derivative value (a higher value should indicate a brighter sunset).
Some results (assuming -3.0 altitude):
- 18.9333, 0.0000, 120.0000
- 5.9000, -31.9239, 116.7482
Well it off 80 km, it means I am not going to escape a poorly selected site, assuming no coding errors. It is a poorly selected sight because the longitude is off which means the sunrise and sunset are not equal intensity (which I know for this site).
Magic
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.