3D Printed LED Bracelet Changing Color Based on Motion

Hello! My name is Gladys and I’m going to be a senior at Lowell High School. I was lucky enough to enter the program with some Java and physics background, but I had never worked on an electrical project in my life, let alone for six weeks. I didn’t even know how to pronounce “solder” properly, so creating something from scratch that worked seemed beyond me, but I decided to try anyway. I had chosen a light organ for my starter project because I wanted to work with LEDs and I wanted to learn how sound could translate into lights, but I switched to a voice changer because of shipping difficulties. Regardless, the voice changer gave me a good introduction to components and I learned about analog to digital conversions, so I fulfilled my goal. As for my main project, I chose an LED bracelet that uses an accelerometer to change color which was created by Marcus Olsson. After successfully powering the LED strip, I wrote code with the accelerometer on Arduino UNO and transferred both the accelerometer and my code to my Trinket microcontroller when it was finished. My prior knowledge definitely helped me with the coding process, but I was able to experience 3D modeling, circuitry, and hardware tools for the first time. I also learned how to narrow down the problem in steps, a lesson that I can apply to more than just electronics. Building the bracelet was an incredible experience and I just wish I had realized just how fulfilling it was to build something earlier! I now aim to attach a potentiometer to vary the strip’s brightness, but the code I wrote (which works on UNO) is too big for Trinket, so if I can’t reduce the size of the code, I’ll rely on the fact that a potentiometer varies resistance instead.

Final pic

Link to code and libraries used: https://github.com/GladysNLEDBracelet/LEDBracelet.git

Link to BOM (including resistor, capacitor, and USB cable for Trinket, but they were provided by Bluestamp): Bill of Materials
content/uploads/2014/06/LEDbraceletCircuit1.png” alt=”Circuit” width=”1293″ height=”569″ class=”aligncenter size-full wp-image-7207″ />

As for the 3D model, I used two of Marcus’ files “ledBracelet_body_hollow.v6.1.stl” and “ledBracelet_body_protection.v6.1.stl” from http://www.thingiverse.com/thing:248567/#files and a file that I edited, which you can find at http://www.thingiverse.com/thing:405172.

Final Video
The project has a Trinket microcontroller, a NeoPixel RGB LED strip, and a Flora accelerometer. There is a 470 microFarad capacitor between the positive and negative terminals on Trinket and a 470 Ohm resistor between the data input line to the NeoPixels and Trinket. Both were suggestions by Adafruit (the company that manufactures NeoPixels) to avoid voltage spikes from damaging the pixels when the battery is plugged in. The code that I’ve uploaded to Trinket uses the data from the accelerometer to determine whether there has been a shake, or a significant difference in acceleration. It also determines whether shakes are in the same sequence; shakes in a sequence can’t be more than 300 milliseconds within each other. If there are around 3 shakes in a sequence, the NeoPixels will turn a random color. If there are around 5 shakes, they will display an on-off sequence that alternates to give a sparkling effect. The model is designed by Marcus Olsson; I only edited the removable piece to have more space. There are neodymium magnets fastening the removable piece to the body of the model. There are two colors because the first model I printed was blue (a misunderstanding) and not translucent; the second model is white and translucent. I combined the blue protection, the blue removable piece, and the white body for this project. Trinket and the accelerometer are sealed with blue insulating tape. You can disconnect the battery from Trinket to charge it. I also added a connector between the pixels and Trinket but the wires aren’t flexible, so you have to be careful when disconnecting it; this makes the removable piece fully removable. As for modifications, I’m working on attaching a potentiometer to vary the brightness of the LEDs.

Third Milestone
I finished the code for the project and successfully uploaded it to Trinket. I had added the sparkling effect, which only ends 2.5 seconds after the last shake, so I could keep making it sparkle if I wanted to. Then I addressed the shake detection of the program. My code used delays in detecting shakes and in displaying the sparkling effect. I did not change the sparkling effect’s delays because I don’t need the program to count shakes while the bracelet sparkles. For the shakes, I omitted the delays and instead used a while loop that runs for around 150 milliseconds and counts shakes within that time frame. If a shake is counted, the loop completely stops. Since this does not require a difference in coordinates (or a shake) with an exact time gap between them, using the while loop improves the program. My program also uses a timer to count shakes within a time period of around 1.2 seconds. I edited it such that achieving a color change and starting a new shake sequence would reset the timer. Now people don’t have to wait for 1.2 seconds to pass before shaking again to avoid contributing shakes to a timer from the last shake sequence. While uploading the code to Trinket, I noticed that the accelerometer was more sensitive than it had been on Arduino. To compensate for that, I increased the required difference in coordinates for a shake. Since Trinket had no serial port, debugging was harder. At one point, my code uploaded, but shaking would not light up the strip. I noticed that an earlier version of my code allowed shakes to light it up, so I copied line for line code from my newest version into my earlier version and tested the bracelet each time until it stopped working. I was able to pinpoint the problem (my timing to allow shakes was too strict), but if I had a serial port, I would have printed the number of shakes the program registered, and when “0” printed out despite my shakes, I would’ve known what was wrong. But in any case, the code now works with Trinket. My next step is to edit Marcus’ model because I want more space for my Trinket in the bracelet, resolder my components into a more compact orientation, add connectors between the strip and Trinket, and assemble the bracelet.

Second Milestone
I wrote the basic code combining the accelerometer and the LED strip and managed to make the lights respond to the accelerometer’s movement. I attached a test LED strip and the accelerometer to Arduino UNO because Trinket has no serial port and I wanted to use the serial monitor to debug my code, which was a great decision. The basic idea of the code is as follows: define a shake as a significant difference in two axis, start a timer when one shake begins, count the number of shakes within a time frame (I chose ~1 second), and if the number of shakes go past a certain amount, change the color on the LED strip. One problem I had was that the wires that I had soldered to the LED strip kept falling off, so I soldered the wires to the pads on both sides. I also had to be careful not to break the LED strip by accidentally shorting or unplugging wires incorrectly (unplug data, then power, then ground; data seems to be the most sensitive). The code gave me a lot of practice in debugging code and taking steps to narrow down the problem. I also got to experience things like splitting tasks into functions, avoiding global variables, returning values, and passing values into parameters. I still want to refine the code to add a “sparkling” effect as well as to solve two problems: bypassing delays, which prevent the program from reading shakes consistently, and restarting the timer when a number of shakes have been reached so a new shake sequence won’t start during the previous sequence’s timer.

First Milestone
I managed to power the LED strip and upload code that I wrote. I thought it would be simple, but just installing Arduino IDE such that it is compatible with my Trinket microcontroller resulted in about four different errors. I spent a lot of time reading up on each error and following suggestions to fix it, which usually did not work. Even the bootloader had problems: it becomes inactive after ten seconds and a button must be pressed to reactivate it. But I found that on my laptop (as opposed to my PC, as later tests revealed), pressing the button did not always activate it, and even then, I had to time it with the upload of the Arduino sketch. After a lot of downloads and tries, I finally installed the drivers, solved all errors but one (which supposedly can be ignored), and secured at least a one-in-three-tries success in uploading code…but nothing on the strip lit up. At one point I thought Trinket was faulty after I successfully lit up the LED strip on a separate Arduino DUE, but when I tried different pins on Trinket, the LED strip lit up. When I soldered the LED strip to Trinket, the LEDs failed. I had to disconnect the LEDs and test them on Arduino DUE again, which failed; I suspect I accidentally shorted the circuit while soldering, which would ruin the LEDs. I replaced the strip and connected it to Trinket, resulting in a successful light show. Despite the pain over something that should be simple, I still feel that I learned a lot. I had learned the values of device manager and command prompt, tools that will definitely help in the future. I learned about drivers, bootloading, how to search online for my problems, and most importantly, I learned that testing must come in stages to avoid complications. I can finally start the heart of this project: attaching the accelerometer and coding it such that it will change the color on the LED strip.

By the way, while I was filming the milestone video below, the connector between the battery and Trinket broke. Since the camera was already set up, I did not solder the connector back until after the video was filmed. The video features me holding the connector in place to power Trinket.

Starter Project: Voice Changer
My first project was a voice changer. It consists of resistors, capacitors (both electrolytic and ceramic, ceramic having a lower capacitance), IC chips, LEDs, buttons, and a zener diode. Resistors dissipate energy by resisting the current, capacitors store voltage, IC chips are small circuits, LEDs are light-emitting diodes, and a diode allows current in only one direction while a zener diode acts like a diode but allows the current to run in the reverse direction if the voltage is high enough. Resistance is measured in ohms and capacitance is measured in Farads. When someone speaks into the microphone, the analog waves are processed into digital waves. An IC chip switches the frequency to change the pitch of the voice that comes out and another IC chip amplifies the power for the speakers. The buttons allow a variety of pitches and even have a “Vibrato” and a “Robot” mode. After I finished the project, I attached it to a small box to allow appropriate distance between the speaker and the microphone to avoid feedback.

Leave a Comment

Start typing and press Enter to search