Making a Moon Light

A long time ago my son was given a light up moon. Similar to this one. It has not worked in a long time because we lost the remote. So I decided to fix it. I took it apart and found it had a very simple circuit driving it. It had 6 LEDs and some dividers to separate the LEDs from each other so it could show the different moon phases.

Modified Moon

I used a NodeMCU microcontroller and wired the LEDs up with a breadboard and some 100Ω resistors.

I wrote a simple NodeJS Express API that the NodeMCU can connect to look up how many LEDs to illuminate based on the actual current moon phase.

Moon Phase API

The API uses a library called Suncalc to calculate the current moon phase and to determine is the moon is "up" based on GPS coordinates. I included a docker configuration in the repo for running with docker as well as a Procfile for running on Heroku. The API is also available on this site:

https://d4v3y0rk.com/moon – returns a number representing how many LEDs to illuminate.
https://d4v3y0rk.com/moon/up – returns a boolean (true or false) representing with the moon is "up" or not (the location is preset to New York, NY) This endpoint is used by the moon to decide if it should illuminate the LEDs.

The code for the NodeMCU microcontroller is here:

Moon Light Arduino Code

If you choose to run your own server for the API,  in the microcontroller code you will need to change the values here to point to your own server. If you are running this behind HTTPS you will need to calculate the fingerprint for the SSL certificate using openssl.

openssl s_client -connect d4v3y0rk.com:443
// copy and paste the cert content into a file (I called mine cert.pem)
// everything between the 
// -----BEGIN CERTIFICATE-----
// -----END CERTIFICATE-----
// also include those two lines in the file contents as well
openssl x509 -noout -in cert.pem -fingerprint -sha1

After generating the fingerprint for the SSL certificate it will need to be put in the http.begin(serverName, "fingerprint"). I found that you need to remove the colons from the fingerprint that is generated. You can find an example of what that looks like here.

Below is a video of the Moon doing it's thing.