Arduino Calculate Sunrise Sunset
1 sunrise project. The software library to calculate moon age, sunrise and sunset time. Sun and Moon Times. By Alexander. Login with Arduino. Zenith: Sun's zenith for sunrise/sunset offical = 90 degrees 50' civil = 96 degrees nautical = 102 degrees astronomical = 108 degrees NOTE: longitude is positive for East and negative for West NOTE: the algorithm assumes the use of a calculator with the.
I like to keep track of sunrise and sunset times. For the past couple of years I've been doing this with a small program written with a popular library for my favorite programming language. The last two months I've been keeping track of these times more regularly than usual, and I happened to notice that on the day of the equinox the sunrise time jumped eight minutes as compared to the day before! I knew this was impossible and compared with NOAA, finding out that my rise and set times had been off for several days and in fact seemed to be off by about a minute for most of the year.
At this point, I'd like to just implement the calculations myself. What algorithms or formulas are available to do this computation?
How To Calculate Sunrise
Azaclosed as off topic by Martijn Pieters♦, Smi, Emil, sgarizvi, GravitonFeb 25 '13 at 3:09
Questions on Stack Overflow are expected to relate to programming within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here. If this question can be reworded to fit the rules in the help center, please edit the question.
8 Answers
You may consider reading Wikipedia's article on sunrise equations. The lead paragraph gives the equation:
where:
- ωo is the hour angle in degrees at either sunrise (when negative value is taken) or sunset (when positive value is taken) in degree (°)
- φ is the latitude of the observer on the Earth in degrees
- δ is the sun declination in degrees
If you want to match NOAA, you'll have to consult Jean Meeus' Astronomical Algorithms (mostly Chapter 15). And it's complicated! Martin Beckett is correct, you have to define the sunset. Typically this is the apparent rise or set of upper limb of the sun, which makes your 'standard' altitide -5/6 degrees (not zero). And you can't calculate the sunrise or sunset directly with NOAA's accuracy. You'll have to create a governing set of equations for apparent right ascension and declination for the day in question and then interpolate the apparent right ascension and declination over time to find the exact rising and setting times at the standard altitude.
Hope this helps. I spent about a month digesting AA and re-writing all our solar code when I came across the same thing, and it still took over a year to sort out some of the corner cases where my code broke. So it will take some time to figure out. I'm not aware of any public code examples of this algorithm and don't have any to share at this moment, but I'm happy to help you through some headaches if I can.
mattexxmattexxFor accuracy in the 5min range you have to consider 'which' sunset.
Do you want the time the bottom of the sun touches the horizon or the time the top of the sun passes below the horizon?
It takes 2mins for the sun to cross the horizon.
Below the 1min level you also need to take into account atmospheric refraction.
Definitions of what constitutes sunrise/sunset can vary. For example, in ephem
'rising and setting are defined as the moments when the upper limb of the body touches the horizon (that is, when the body’s alt plus radius equals zero)' [PyEphem Quick Reference].
Output
If it is open-source library then you could fix it instead of creating a new one with new bugs.
jfsjfsHave a look at this book:
'Practical Astronomy with your Calculator (Paperback)' by Peter Duffett-Smith.
It is quite old but still in print...link
In Ruby I wrote this for equation of time.
Then for the above equation:
There is a whole website devoted to this at http://www.analemma.com/
- The key to these calculations are good libraries like the one for python above.
- Also usage of Date and Time classes. I would look on rubyforge for something like ephem.
You might want to look at an earlier entry on calculating the position of the sun. Specifically, the Solpos program that I pointed to has support for sunrise/sunset.
I did see some interesting things on this NOAA page under the Technical Definitions and Computational Details heading, but I'm sure you've read that already.
The answer to the SO question 'Position of the sun given time of day, and lat/long' and the above may actually be all you need.
As a side note (it doesn't answer your question directly), is there a reason you can't pull the NOAA data and use it as a lookup table instead of calculating it? Storage tends to be relatively cheap these days.