Arduino B.Tech/Diploma Intermediate

Moon Phase Calculator With OLED Display Using Arduino

Moon Phase Calculator With OLED Display Using Arduino. 8 phases are shown with a description, the days remaining to the next full moon is also displayed.

  • Suitable forB.Tech/Diploma Arduino students
  • Build time1-2 weeks
  • LevelIntermediate
  • Available atAjvika Labs, Kakinada

About this project

Moon Phase Calculator With OLED Display Using Arduino:
In this post, we will discuss How to make Moon Phase Calculator With OLED Display Using Arduino. This small project displays the moon phase on an 0.96″ OLED display. Eight phases are shown with a short description, the days remaining to the next full moon is also displayed.
This project uses a real-time clock RTC Module DS3231 or DS1307 to provide the date. This data is converted into a Julian date. By choosing a date that had a known full moon, in this case, 1st January 1972, the number of days from this starting point until now is easily calculated.
Why does the Moon have phases?
The Moon has phases because it orbits Earth, which causes the portion we see illuminated to change. The Moon takes 27.3 days to orbit Earth, but the lunar phase cycle (from new Moon to new Moon) is 29.5 days. The Moon spends the extra 2.2 days “catching up” because Earth travels about 45 million miles around the Sun during the time the Moon completes one orbit around Earth.
At the new Moon phase, the Moon is so close to the Sun in the sky that none of the side facing Earth is illuminated (position 1 in the illustration). In other words, the Moon is between Earth and Sun. In the first quarter, the half-lit Moon is highest in the sky at sunset, then sets about six hours later (3). At full Moon, the Moon is behind Earth in space with respect to the Sun. As the Sunsets, the Moon rises with the side that faces Earth fully exposed to sunlight (5).
Components Required:
1. 0.96″ OLED Display
2. Arduino UNO Board
3. RTC Module DS3231 or DS1307
4. Breadboard
5. Jumper Wires
Circuit Diagram & Connections:
Both the OLED and RTC Module DS3231 is powered by 5V Power Supply. The SCL and SDA Pins of OLED & DS3231 is connected to SCL and SDA pins of Arduino, i.e A4 & A5.
Designing the Moon Phase Calculator:
The moon takes 29.53 days to complete the cycle from one full moon to the next, so if we divide the number of days since 1st January 1972 by 29.53 the remainder will be the number of days in this lunar month so far.
The sketch divides the lunar month into eight parts, starting with a full moon then waning gibbous, last quarter, crescent old, new moon, crescent new, first quarter, waxing gibbous and back to a full moon. The number of days to the next full month is also shown.
Results & Display:
Once the code is uploaded to Arduino UNO board for Moon Phase Calculator With OLED Display Using Arduino, the moon phase will be shown and also the day will be displayed as 1, 2, 3, 4 ……..28 as shown in the figure below.
Source Code/Program:
First, add the two libraries, i.e U8glib Library & RTC Library else the code won’t compile.
Download U8glib Library
Download RTClib Library

#include "U8glib.h"
#include <SPI.h>
#include <Wire.h>
#include "RTClib.h"
U8GLIB_SSD1306_128X64
u8g
(
U8G_I2C_OPT_NONE
)
;
// I2C setup u8g object
RTC_DS1307
RTC
;
static
unsigned
char
full_moon_bits
[
]
=
{
0x00
0x00
0x00
0x00
0x00
0xf8
0x07
0x00
0x00
0xff
0x3f
0x00
0x80
0xff
0x7f
0x00
0xe0
0xff
0xff
0x01
0xf0
0xff
0xff
0x03
0xf0
0xff
0xff
0x03
0xf8
0xff
0xff
0x07
0xfc
0xff
0xff
0x0f
0xfc
0xff
0xff
0x0f
0xfc
0xff
0xff
0x0f
0xfe
0xff
0xff
0x1f
0xfe
0xff
0xff
0x1f
0xfe
0xff
0xff
0x1f
0xfe
0xff
0xff
0x1f
0xfe
0xff
0xff
0x1f
0xfe
0xff
0xff
0x1f
0xfe
0xff
0xff
0x1f
0xfe
0xff
0xff
0x1f
0xfc
0xff
0xff
0x0f
0xfc
0xff
0xff
0x0f
0xfc
0xff
0xff
0x0f
0xf8
0xff
0xff
0x07
0xf0
0xff
0xff
0x03
0xf0
0xff
0xff
0x03
0xe0
0xff
0xff
0x01
0x80
0xff
0x7f
0x00
0x00
0xff
0x3f
0x00
0x00
0xf8
0x07
0x00
0x00
0x00
0x00
0x00
}
;
static
unsigned
char
waning_gibbous_bits
[
]
=
{
0x00
0xf8
0x0f
0x00
0x00
0xff
0x3f
0x00
0x80
0xff
0xff
0x00
0xe0
0xff
0xff
0x00
0xf0
0xff
0x7f
0x00
0xf8
0xff
0x7f
0x00
0xf8
0xff
0x3f
0x00
0xfc
0xff
0x1f
0x00
0xfe
0xff
0x1f
0x00
0xfe
0xff
0x0f
0x00
0xfe
0xff
0x0f
0x00
0xff
0xff
0x0f
0x00
0xff
0xff
0x0f
0x00
0xff
0xff
0x07
0x00
0xff
0xff
0x07
0x00
0xff
0xff
0x07
0x00
0xff
0xff
0x07
0x00
0xff
0xff
0x07
0x00
0xff
0xff
0x07
0x00
0xfe
0xff
0x0f
0x00
0xfe
0xff
0x0f
0x00
0xfe
0xff
0x0f
0x00
0xfc
0xff
0x1f
0x00
0xf8
0xff
0x1f
0x00
0xf8
0xff
0x3f
0x00
0xf0
0xff
0x3f
0x00
0xe0
0xff
0xff
0x00
0x80
0xff
0xff
0x00
0x00
0xff
0x3f
0x00
0x00
0xf8
0x1f
0x00
}
;
static
unsigned
char
last_quarter_bits
[
]
=
{
0x00
0xf8
0x0f
0x00
0x00
0xff
0x07
0x00
0x80
0xff
0x01
0x00
0xe0
0xff
0x01
0x00
0xf0
0xff
0x00
0x00
0xf8
0x7f
0x00
0x00
0xf8
0x3f
0x00
0x00
0xfc
0x3f
0x00
0x00
0xfe
0x1f
0x00
0x00
0xfe
0x1f
0x00
0x00
0xfe
0x0f
0x00
0x00
0xff
0x0f
0x00
0x00
0xff
0x0f
0x00
0x00
0xff
0x0f
0x00
0x00
0xff
0x0f
0x00
0x00
0xff
0x0f
0x00
0x00
0xff
0x0f
0x00
0x00
0xff
0x0f
0x00
0x00
0xff
0x1f
0x00
0x00
0xfe
0x1f
0x00
0x00
0xfe
0x1f
0x00
0x00
0xfe
0x1f
0x00
0x00
0xfc
0x3f
0x00
0x00
0xf8
0x3f
0x00
0x00
0xf8
0x7f
0x00
0x00
0xf0
0xff
0x00
0x00
0xe0
0xff
0x01
0x00
0x80
0xff
0x01
0x00
0x00
0xff
0x07
0x00
0x00
0xf8
0x0f
0x00
}
;
static
unsigned
char
crescent_old_bits
[
]
=
{
0x00
0xf8
0x07
0x00
0x00
0xff
0x00
0x00
0x80
0x1f
0x00
0x00
0xe0
0x0f
0x00
0x00
0xf0
0x03
0x00
0x00
0xf8
0x01
0x00
0x00
0xf8
0x01
0x00
0x00
0xfc
0x00
0x00
0x00
0x7e
0x00
0x00
0x00
0x7e
0x00
0x00
0x00
0x7e
0x00
0x00
0x00
0x3f
0x00
0x00
0x00
0x3f
0x00
0x00
0x00
0x3f
0x00
0x00
0x00
0x3f
0x00
0x00
0x00
0x3f
0x00
0x00
0x00
0x3f
0x00
0x00
0x00
0x3f
0x00
0x00
0x00
0x3f
0x00
0x00
0x00
0x7e
0x00
0x00
0x00
0x7e
0x00
0x00
0x00
0x7e
0x00
0x00
0x00
0xfc
0x00
0x00
0x00
0xf8
0x01
0x00
0x00
0xf8
0x01
0x00
0x00
0xf0
0x03
0x00
0x00
0xe0
0x0f
0x00
0x00
0x80
0x1f
0x00
0x00
0x00
0xff
0x00
0x00
0x00
0xf8
0x07
0x00
}
;
static
unsigned
char
new_moon_bits
[
]
=
{
0x00
0xf8
0x07
0x00
0x00
0x07
0x38
0x00
0x80
0x00
0x40
0x00
0x60
0x00
0x80
0x01
0x10
0x00
0x00
0x02
0x08
0x00
0x00
0x04
0x08
0x00
0x00
0x04
0x04
0x00
0x00
0x08
0x02
0x00
0x00
0x10
0x02
0x00
0x00
0x10
0x02
0x00
0x00
0x10
0x01
0x00
0x00
0x20
0x01
0x00
0x00
0x20
0x01
0x00
0x00
0x20
0x01
0x00
0x00
0x20
0x01
0x00
0x00
0x20
0x01
0x00
0x00
0x20
0x01
0x00
0x00
0x20
0x01
0x00
0x00
0x20
0x02
0x00
0x00
0x10
0x02
0x00
0x00
0x10
0x02
0x00
0x00
0x10
0x04
0x00
0x00
0x08
0x08
0x00
0x00
0x04

Technologies used

ArduinoSSD1306OLEDI2CSPIUART

Hardware components

  • Arduino
  • SSD1306
  • OLED

Software & tools

  • Arduino IDE

What you get

  • Working project / hardware kit, tested before delivery
  • Complete source code with explanation
  • Project demo and guidance for your viva
  • Project report, PPT and IEEE paper support (on request)
Delivery & Payment
Delivery takes a minimum of two weeks from the date your inquiry is confirmed. Payment is in two parts: • 50% advance to start the project • Remaining 50% before delivery Note: • Documentation and PPT are not included by default • If you need documentation/PPT, it can be arranged for extra time and cost We'll confirm the exact timeline and cost with you after reviewing your requirements.