Software apps and online services
Hand tools and fabrication machines
The moon like many other things exists in a cycle. The moon takes 29.5 days to go through the entire lunar cycle and during this cycle, 8 unique phases can be seen on the moon. These phases are due to the moon being turned away from the sun. This causes shadows to be projected onto the moon's surface which then changes the moon's appearance and creates beautiful images overtop the night sky. With this project, I wanted to capture the moon's beauty and create a representation of the moon cycle that can be displayed in one's home so that the beauty of the moon isn't only limited to the night sky.
The concept for this project is to create a device that contains a light that projects a circle onto any surface. This circle represents the illumination of the moon. A stepper motor with a circular disk will then be connected to this device to block sections of the light to project the shadow of the current moon phase.
The circuitry for the device is pretty straight forward. The required electrical components for this project are:
- 5V DC Stepper Motor
- ULN2003 Stepper Motor Driver Board
- Particle Argon with Wifi
This microcontroller is important because it allows us to connect to the internet which will allow us to pull information that we need for this project to work. Particle is also a very nice choice for what we are doing since their online IDE contains a very convenient way to implement a webhook which makes the process very easy.
The 5V DC stepper motor with pre-routed wires is slotted into the ULN2003 stepper motor driver board. Pins 1-4 of the driver board are then connected to digital pins 5-8 of the Particle Argon. The 5V(+) power pin is connected to the VUSB pin of the argon and the Ground(-) pin is connected to the GND of the Argon.
As for the hardware side of this project, you are free to get creative as you want when designing the physical encasing of the device. The key fundamental components of this project are a funnel that can focus light into a circle that can then be projected on any surface and a rod with a disk that matches the circumference of the funnel's opening. This project essentially is the use of shadows to create specific images that represent a specific piece of information.
For this project, the funnel I used a PVC Area Floor Drain that when flipped can act as a funnel that will allow us to focus light in a specific direction. For the rod, I specifically used a 6-inch wood ruler that has a hole drilled with the specifications of the stepper motor's notch that has a mason jar lid taped to it.
This project can be chosen to be projected on the wall or ground but for convivence, it is easier to just project our images onto the ceiling so that no mounting is required.Data Visualization
Using an API, or Application Programming Interface can allow us to pull data from a database that updates regularly to pull real-time information that we can use to update our project regularly. Databases can be found for almost anything that can give data. For this project, we are going to use the Visual Crossing Weather API. This API is primarily used for pulling information on the climate however there is a small portion of this API dedicated to updating the current fractional portion of moon illumination through the current moon lunation cycle. This fraction is basically how far into the lunar cycle the moon is. This fraction can be used to update our stepper motor's position to represent the current illumination of the moon. To access this information though, we need to create a webhook that when a specific event is published on our IDE will pull the correct information we need from the database.Creating a Webhook
Creating a webhook as previously mentioned is super easy and convenient when using the Particle IDE.
- To create our webhook we first need to navigate to the Particle Console Integrations where we can create a new integration.
- Make sure that webhook is selected when making a new integration
- The information needed for the webhook builder is: the name of the webhook event that will be needed for when we want to call the actual pulling of information from our database, the URL which can be found after creating an account on Visual Crossing Weather API and requesting 1 day of weather information, and the request type needs to be GET.
- The link I use is for the webhook is https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/weatherdata/forecast?aggregateHours=12&forecastDays=1&combinationMethod=aggregate&includeAstronomy=true&shortColumnNames=true&outputDateTimeFormat=dd/M/yyyy%20h:m:ssa&contentType=json&unitGroup=us&locationMode=single&key=APIKEY&dataElements=legacy&locations=LOCATION
- This link can be used in your webhook but APIKEY and LOCATION need to be replaced with your respective information
- When we publish our event and make the request for the information from the database the the data we get back is more than we actually need
- In order to only get the specific number we need which is "moonphase" we need to enter a line of code in the custom template of the webhook builder. This line of code is:
Once we finish our webhook we can publish our moonPhase event which will give us the specific information we need to make our device run the way we want it to.Code
The setup of our code initializes the pins of the motor along with variables we will need such as timer and the old moon phase. Old moon phase initializes as 0.00 because this is the neutral state of the moon or New Moon and is how our device should be calibrated before running.
After setting up our pins and initial variables we need to actually subscribe to the webhook event we just created. The line :
Particle.subscribe("hook-response/moonPhase", myHandler, MY_DEVICES);
Will allow us to subscribe to our webhook and will call a function that we are going to make called "myHandler" every time our webhook event is published.
We publish our first event in the setup as well in order to get our device in the spot that the moon is in at the current time.
After our setup, we create our active loop that will count every second since the device has been powered on and will keep a count of the seconds until 3600 second or 1 hour where our loop well then publish our webhook which will call our "myHandler" function and update our device and then reset the timer.
When the webhook response is published, data is pulled Visual Crossing API that contains a float value from 0.00 - 1.00 that represents the fractional portion through the current moon lunation cycle. Every time the webhook is called, the data is stored in a variable called moon phase which is then translated to the number of steps needed to get to that current moon phase. The calculation takes the old moon phase, the phase the moon was last hour (which will always be 0.00 or a New Moon on first startup), and subtract it from the current moon phase. This subtraction will give you a number between 0.00 - 1.00 due to the moon phase always incrementing positively before resetting back to 0.00 in which case the old phase is incremented back to 0.00 as well. This number can then be multiplied by 1000 where it will represent the number of steps needed to create the current moon phase. These steps are used to move the motor X number of steps counterclockwise of neutral position which will always be 0.00 or a New Moon. If X number of steps is greater than 500 the motor will start from the left side to represent the full moon cycle. After all, calculations are done, the old moon phase is then set to the current moon phase to be ready to be used for the next calculation that will be down the following hour.
The oneStep function takes a boolean to determine whether the motor should move a step clockwise (true) or counterclockwise (false). This function is the sequence of one step and can be used in a loop to move X amount of steps in either direction.
After everything is constructed and coded the final result will give a projection of the moon that is fairly accurate to the percentage of illumination of the current moon phase. The limitation of this project is the use of a disk to represent the shadow of the moon. This disk doesn't allow each phase to be perfectly comparable to that of the moon. The illumination will be correct but the Gibbous and Quarter phases of the moon can't be properly portrayed. This device will however create an impressive projection that represents moon illumination and will allow you to keep a little beauty of the moon in your home.