Intro to Hacking: The Glitter Box Example
A step by step guide to creating your own Arduino IDE code using research skills. This uses the example of a Glitter Box, a non-marine science-related project that uses Arduino IDE equipment to create a prank box that throws glitter when exposed to light to educate people about the process of coding when the specific code you need does not already exist and when resources like pre-written code and AI are allowed to be used.
Research
Arduino always turns into a research project. Figure out what you want to make and if people have created this type of thing before. Often times code and schematics already exist for what you are trying to make (e.g. many many different versions of a temperature sensor exist and are open for use), and in many non-school related scenarios, AI systems can eb used to troubleshoot and find errors. However, in this case, no code existed, but several Youtube videos about the topic were viewed and studied.
These links did not provide enough information AND used equipment that was easily accessible. So a new design had to be created. QUESTION: How can we use what we have in order to create what we need? We know that we want the glitter to be thrown via a motor, so what motor codes do we have access to?
​
SPARKFUN: Circuit 5A. Motor with switch.

Splice
Take code from the two different pieces: the motor with the switch, & the light sensor and splice them together so that things under "void setup" and "void loop" stay under those titles in the new code. Make several copies of the code while working to ensure you have a copy that works. This step takes a lot of trial and error.
Troubleshoot & Fix

After hand splicing the two codes together, the code was run through an AI program to smooth it out to fix errors. AI is a great aid for troubleshooting code, but needs to be paired with a working knowledge of code. In this case, it made the switch from the motor code totally overpower the light sensor in that when the switch is plugged in, then it is on regardless of what the light intensity is.
Start with changing things in the code that you know how to do. For example, the use of && was added manually to ensure that both the switch was low and the light had to be high at the same time in order for the motor to go off.
After moving things around by use of a combination of AI and writing code by hand, a new version of the code was created. Run the newest possible code through AI only. This one did not work as planned because, while it began spinning the motor when exposed to light, it never stopped. This was determined to be due to errors and lack of clarity in the for loop.


The limits of AI had been reached and it was not understanding what we wanted. The for loop was fixed using prior knowledge of how C++ works and logical thinking of what needed to be in each section of the loop. While knowledge of code is not necessarily required for Arduino projects, the more complicated and unique the project is, the less you will be able to rely on outside resources.
​
This is a good chance to manually add features to the code, such as the delay in the motor running after it senses light so that when someone opens the box and exposes the sensor to light, it won't throw glitter too soon.
IThis project is ongoing and will be updated regularly.