This is a simple algorithm to calculate Moon's Phase on a given date using the Arduino environment. Here, I used the Heltec esp32 v2 development board.
The algorithm is inspired by the magazine skyandtelescope.
You can find also a previous version using an Arduino nano and a Nokia LCD display in my old Github account.
The main function is moonPhases(int year, int month, int day) where 'year' is a four-digit number.
/* Calculate the moon number */
moonNum = moonPhases(year, month, day);
moonNum
corresponds to the "moon day/age", as well as the bitmap image number to be drawn on the OLED display.
A Time zone is also needed for the calculation of the Julian day :
int timeZone = 2;
Make sure to install the fellowing dependencies before you run the program:
Here is an output example of the following inputs :
int timeZone = 2;
int day = 17;
int month = 8;
int year = 2021;
- U8g2 Font List
- Sky & Telescope
- I used Open LCD Assisstant to generate the moon byte arrays
- Add an example using NTP server to get the current date