Party rockers in the house tonight! Everybody just have a good time!
March 10, 2021
For my final project, I created a product called Party Mode. With party mode, users can create customized color patterns that will cycle on an RGB LED strip. The product allows users to adjust the cycling rate of the RGB LED strip as well as reset color patterns on the fly.
As a culmination of the work I had done with circuits, it was a fun and exciting way to end my quarter with a bang! There's not some higher purpose or deeper meaning behind this project; I had the RGB LED strip and wanted to recreate the infmaous TikTok lights trend.
Demo First! Then Details After
I believe that this project is best explained with a demo to help visualize the entire product in action. Below is my demo video, which can also be viewed on YouTube:
The Circuit
Next, let's dive into the circuitry. Below I have a diagram explaining each of the major components on the breadb—sorry, I mean "prototype."
Note: if any of the diagrams are too small to read and don't like zooming in right click and open the image the in new tab!
I also have provided a schematic for a more abstract and clearer view of the circuit.The biggest thing to note here is that MOSFET transistors are used to control the RGB LED strip, as we cannot directly manipulate the +12V drain. The Arduino pins then control the transistors' gate, controlling flow similar to a singular RGB LED.
Voltages and Resistances
Before we get to any more of the fun, I have to address the boring aspect of resistances and expected voltages. Here we go!
For resistances:
The reset pushbutton (#1 on Figure 1) has a an arbitrary 10KΩ resistor to set a low current that wouldn't fry the Arduino.
The reset LED indicator has a 220Ω resistor becuase it is closest to its ideal resistance of 160Ω after the voltage drop.
The potentiometer setup has a 1KΩ resistor; this means that the range of resistance for the circuit is 1K–11K.
The transistors already limit the current flowing through them to a stable range, so no need for resistors here.
For voltages:
Given the resistance range of 1K–11K for the voltage divider at #3, this gives a more sensitive voltage range of 0.45V–5V.
The MOSFET transistors are fed a drain of 12V, meaning the range the indivial RGB lines on the strip will see 0-12V.
A Pixel's Journey
Before heading into the code, I think that it's easier to first visualize how the program takes information from the web page and puts it out in the real world.
To put it into words, here is what happens. If the mouse is clicked, the program
extacts RGB values from the pixel using the cursor's position on the page. The program then sends the RGB values back to Arduino via serial in a comma-separated string. The Arduino reads the integers from the serial and stores them into an array of RGB value arrays. When the color needs to be transmitted, the program writes to the analog pins the RGB values from the array, which manipulate the voltage to produce the color on the RGB LED strip. *Takes a deep breath in* And that is the life of a pixel in Party Mode!
The Javascript Code
There is actually less Javascript code for the final project than the previous prepatory assignment. This is because I removed the joystick feature and solely focused on using the mouse, which cut back much of the code. The main feature here is to grab the pixel's RGBA value from the cursor's position, then send it over the serial.
The Arduino Code
The Arduino code is a bit beefy. To help chunk out what's going on, on top of the raw code I have also provided a couple of annotated diagrams that help explain the two essential functions of the Arduino code: the main loop and the reset loop.
Problems with the Arduino Code
I think that one of the biggest issues I had with the Arduino code concerned the main loop and how to run code asynchronously from that very limiting span.
The reset process I had in mind required me to break the main loop, so my solution was to create a separate function and code in a while loop that would run indefinitely until either the user ends the reset process or the max array limit is reached. I don't know if this is quality coding, but it got the results I wanted.
My second qualm with the main loop was that I could only go into reset mode or apply a different cycling rate one every couple of seconds, and not instantaneously. This is becuase my delays set by the potentiometer-controlled rate would not allow for any input to interrupt the code. To solve this, I used some fancy code using millis() to keep track of time. For every pass through the function, it checks if a certain amount of time has passed before executing. This allowed me to interrupt the loop as any given moment as well as have the cycling rate run asynchronous to the loop clock.
When The Party's Over
Overall, this project has been such a blast for me. It was really cool to take something accidentally given to me (the RGB LED strip was a packaging mistake) and give it meaning and charm through hard work and lots of code. I know I've said this a lot now, but I am genuinely so proud of the work I have accomplished here in this class. It's refreshing to be tinkering with my hands, and it brings back joys of playing with LEGOs as a kid.
Anyways, enough sentimental talk. I hope that you enjoyed reading my project! If you have been sticking around, I am glad (and surprised) that you've seen me grow as a circuiter (probably not a word) and engineer over these past 10 weeks. Now, it's time to retire the breadboard and microcontroller for now. Until next time, party on!