Max and Sam's Useful Box
- 1 Overview
- 2 Design
- 3 Programming
- 4 Wiring
- 4.1 Subsystems
- 4.2 Cool Conveniences
- 4.3 Problems
- 4.4 Photos and Diagrams
Concepts and Planning
At first, we wanted to make our box a perfect cube, because that tends to look the cleanest and means we will have a nice finished product. However, we also hate assembling the box design involving screwing nuts and bolts on every edge, so Instead we are making our box in the shape of a cylinder using 6in diameter PVC pipe as the shell.
We decided on the cylindrical shape because it had never been done before and allows for a really cool effect when taking the box apart. When making this shape, we decided to make a "core" and a "shell" that would fit together in order to make a complete box. The shell was made of 6 inch PVC pipe, painted black with a few added screws on the sides and a black acrylic bottom. The shell was made up of 3 layers of acrylic, the top layer, the middle layer, and the bottom-most layer.
The top layer (diameter 160mm) holds a LCD screen, a potentiometer, a blue LED, two switches (one for PID control and one for power) and mounting holes for a motor mount. The motor mount is mounted on the bottom of the black, acrylic sheet, and is a 3D modeled and printed part that holds a motor and has mounting holes for the photogate. The top panel also contains four mounting holes for the locking mechanism. See the section "locking mechanism" for more details.
This layer is a 140mm circle cut out of light blue, transparent acrylic. This layer has mounting holes for a breadboard using the breadboard mount designed and 3D printed for this project. This layer also hold 7 blue LEDs (Wired in parallel, receiving 6V, controlled via transitor) and has two large holes on either side of the breadboard for the wires. This layer is separated from the top layer with 3 2" standoffs.
Like the middle layer, this layer is a 140mm hole cut from light blue, transparent plastic. This layer has mounting holes for an arduino (when 1/2" standoffs are used) and mounting holes for a slightly modified 9V battery holder. The battery holder was modified to fit 2 9V batteries wired in parallel, stacked on top of each other. This positioning provides a more current (still just at 9V) to run all of the LEDs and the motor. The bottom layer, like the middle layer, has 7 blue LEDs wired in parallel that receive 6V.
The locking mechanism is a 150mm ring that is 5mm thick. The circle has four holes equally spaced along the ring. The bottom of the ring has cutouts that are T-shaped that allow the "lockers" some room to move. There are also locking bumps that restrict the movement of the mechanism, but at this point they are too large and not necessary so they are not used. The locking mechanism works using a friction fit. The shell has four equally spaced holes that have #4-40 screws inside. The nuts on the inside are exactly the right size to slide into the T-shaped cutout of the ring, and allow the ring (and the connected top) to spin around, sliding along with the nuts inside the ring. Pulling the shell out involves turning the ring to a point where it can escape the nut, and then removing the ring from the shell. because the ring is connected to the top layer, and the rest of the core is connected to the top layer, removing the ring mechanism can remove the entire core, allowing for easy wiring or code access. As always, a picture is worth a thousand words. See the pictures for more details (and watch our super cool promo to see the locking mechanism in action).
Assembly of the box is relatively easy. First, the arduino, the LEDs and the battery pack are mounted to the bottom layer and the standoffs are screwed into the holes provided on that layer. The second layer can be placed and secured onto those standoffs. On this layer, the breadboard can then be mounted to the middle layer ajnd the LEDs mounted around it. The three standoffs for this layer have holes so that they can meet perfectly with the top layer. The top layer must be assembled off of the standoffs and then screwed on. First, the LCD is put into the top, then the LED, potentiometer and the two switches are mounted in their respective holes. From the bottom of the top layer, the motor mount is attached. From the bottom, the locking ring can be screwed on and then tested. The entire top then can be mounted on the standoffs and the core is complete. The shell has four holes drilled into the sides. Screws are mounted in those holes and then nuts are placed on those screws. An acrylic bottom is then glued onto the pipe and the shell is completed. Relatively speaking, the shell requires little assembly. See pictures of the final box for clues on how it was assembled.
Core Too Tall with LEDs
Once the LEDs were added, the core was a few millimeters too tall to fit in the already made shell because of the added space for the LED casing. First we considered replacing the bottom of the shell with a few layers of "spacer" acrylic, but then realized that it was a waste of material. Instead, we reprinted three of the standoffs in order to make them a bit shorter. This solution, shortening the bottom standoffs by half an inch (1.5 inch instead of 2 inch), made it so that when the LEDs were mounted, the entire core fit perfectly in the shell.
Originally, the design included the LCD screen upside down. There was no easy way to fix this in code because in the LCD library, a user can only create up to 8 of their own characters. Instead, we removed the LCD (an arduous process), and flipped it around 180 degrees in order to make the LCD right. This was a pain but it was worth it to avoid some gross code stuffs.
The way the locking mechanism was designed means that over time the lock will wear out. With excessive rubbing of the nut and the slight bending that the box goes through every time the core is taken out, the locking mechanism will eventually break down. The expected life for the locking mechanism is around 1000 unlocks, so assuming the box is not stretched beyond that, the current locking mechanism works perfectly. In future models, the locking mechanism would be strengthened or perhaps made out of a higher strength material such as specially cast acrylic. For the scope of this project however, using the 3D printed model is sufficient.
Photos and Renders
Green is input speed. Red is actual speed. Blue is adjusted power.
The Arduino code consists of two distinct modes, PID closed-loop and non-PID open-loop. Every 1/2 second, the the code detaches the interrupter so that it can do calculations. First it check to see what mode it's in by doing an digital read on PIDpin. If PID mode is off, the arduino doesn't bother calculating errors or adjusted and it only maps, writes and prints. Otherwise, the Arduino is in PID mode and it calculates error. Error and derivative of error don't need global variables because each calculation is unique to that half-second; however, the integral of error requires a pre-declared global variable because each new calculation of integral relies on the previous value. After error calculations, the Arduino sums all the errors by "adjustedSpeed = inputSpeed - 0.00*error - 0.1*dError - 0.45*errorSum;" The coefficients of the weighted sum were simply found by trial and error. The adjusted speed is also constrained to 0 to 255 so that the automatic modular nature of analogWrite doesn't write unexpected speeds (writing 256 is the same as writing 0). Finally the Arduino combines error and input speed to calculate an nice speed for the aesthetic lighting pulse.
Abrupt Lighting Pulse Rate Changes
Originally, because the Arduino only updates actual speed and adjusted speed every half-second, the pulse rate of the aesthetic lighting also only updated every half-second. This meant that whenever the user drastically changed the input speed and the error skyrocketed, the lighting would abruptly start pulsing very quickly and abruptly slow down as the motor approached it's target speed. This was not very smooth or natural, so an extra layer was added between error and pulse rate. There is a instead of pulse rate being determined by error, a new variable, rateTarget, is determined by error. The Arduino uses the number of 50 milliseconds between now and the next total update to calculate a dRate, which is the amount the rate will have to change every 50 milliseconds in order to reach the target rate in exactly 500 milliseconds. This was, the pulse rate of the aesthetic lighting changes linearly over time rather than jumping sporadically.
The graphical processing involved in the graphs is handled by an object detailed here.
Motor Feedback System
This subsystem consists of the motor, it's transistor, and the photo-interrupter. The 6V motor is fed off the 6V voltage regulator side of the breadboard, while the photo interrupter is on the opposite side for easy access to 5V straight from the Arduino, as the photo-interrupter does not require much current. This system was tested before assembly of the box; click here to see a gallery of that test.
The Interface consists of the LCD, it's backpack, a potentiometer, the on/off switch, the PID switch, and an LED to indicate that the photo-interrupter is working. The entire IO system works on the 5V side of the breadboard because it does not draw much current. The global power switch is directly connected to the 9V battery in the middle, and the side is split between the Arduino 9V input and the breadboard, where 9V goes into the voltage regulator to provide 6V.
The internal lighting wiring system was suprising tricky. To provide enough voltage for the 14 interior LEDs, they had to be wired in parallel, meaning that they draw more current. Because of this current requirement, we decided to run the interior LEDs off the 6V from the voltage regulator and the battery instead of thorugh the Arduino like the IO LED. This means that each loop of interior LEDs needed its own transistor to convert arduinio 5V PWM to 6V for the LED's. Using Ohms law and resistance in parallel circuits equations, we calculated that given 6V, each row of 7 LEDs in parallel would need only a single 220ohm resistor to keep the LED from frying. Note that blue LEDs have a diferent resistance and voltage requirement than green and red LEDs, so different calculations should be made for similar LED setups in different color.
Using Only 9V Batteries
Rather than using a bulky and awkward split 6xAA better pack (or worse, both a 6xAA pack and a 9V battery... this), we decided to only use 9V batteries and to use a 6V voltage regulator to get the proper voltage for the motor. Originally, we planned and modeled for only one 9V battery, but this ended up not supplying enough voltage. However, it was very simple to just "piggyback" another 9V battery on top of the first. Wiring the two batteries in parallel boosts the available current. We think that using only 9V batteries saved us from a lot of complicated modelling, mounting, and wiring, and we recommend this solution to anyone using a 6V motor.
LCD Backpack Header
Another great idea which saved us a lot of trouble was using a modified female-female header to connect the LCD to its backpack. We neither wanted to take up space with a long ribbon-cable nor solder the backpack directly to the LCD, so our solution was to solder the male ends of two male-female headers together, essentially creating a female-female header. We wrapped the exposed male headers in electrical tape to prevent short circuits, and we bent the female-female header in the middle to create a 90 degree angle for easy mounting.
15 Blue LEDs
Firstly, the sigma lab didn't even have 15 blue LEDs. We had to order some just for this project. Also, when originally wired in series, they required such an incredible amount of voltage to light up, that we switched our original plans to wire the LEDs in parallel. After a few tries, we connected all of the bottom 7 LEDs in parallel and then connected the middle 7 in parallel. This configuration draws more current but requires less voltage and is within the current range of two 9V batteries in parallel.
Sam fried the potentiometer. Like 4 or 5 times. Turns out those guys are really sensitive. When soldering to the potentiometer, the soldering iron was too hot and touched the delicate components inside. This fried the resistor every time. Heat shrinking the wires didn't help with this problem either. When the potentiometer was fried it would read seemingly random values that fluctuated more based on the acceleration of the potentiometer than on the position of the dial. Key point here: when soldering sensitive electronic components, move fast. And when that doesn't work, move faster. And if that still doesn't work, let Max solder it.
Photos and Diagrams
Motor & Phototransistor Wiring Gallery
Click here to see a gallery of how our motor and photo-interrupter were wired.