Tuesday, November 25, 2014

Arduino-Powered Going Away Gift

    Recently, one of my coworkers departed the office.  He's one of those folks who rails against the Arduino -- in his opinion, Arduinos are overkill for almost everything, people just need to get back to op amps and 555 timers, dag nabit!  So of course when we learned he was leaving, the entire office agreed -- his going away gift had to include an Arduino and it had to be used in a way that seemed like as much overkill as is humanly possible.  Given that the normal going away gift for our office is a challenge coin, here's what I came up with:

Challenge coin replaced with silver dollar in this photo.

Its a challenge coin with a blinking light.   Flip the coin over and...

Behold the power of the Arduino Micro!

…an Arduino Micro!  At first glance, it's all of the majesty of an Arduino used, essentially, to alternate the voltage value on a pin between high and low, switching an LED on and off.  Of course, I couldn't let all of that horsepower go to waste, so read on to find out what easter eggs I managed to cram under the hood.

Design Ideas

    Above and beyond the blinking light, here's were my ideas:
    • Challenge coin?  Let's turn that into a push button!
    • Regular LED?  No, no, no! RGB LED!
    • An Arduino Micro can represent itself as a Keyboard and Mouse?  No one could possibly do anything mischievous with that!

Final Design

    Based on my initial ideas and a little monkeying around, here's what I decided to do:
    • Mount the coin on a tactile push button switch, effectively turning it into a push button.
    • Use an RGB LED and implement the following effects:
      • Fade-in/fade-out blinking white light.
      • Fade-in/fade-out Red, White, and Blue blinking light
      • Fading color wheel going through the colors of the rainbow.
      • Morse code library allowing any arbitrary string to be communicated via blinking white light.
    • Using the Keyboard/Mouse subroutines, implement a subroutine that randomly causes one of the following effects (hereafter referred to as "random mischief"):
      • press ALT-TAB (Change window)
      • press CTRL-ALT-DEL (Bring up lock screen)
      • press ENTER
      • press CTRL-ALT-DEL, then ENTER (Lock a windows workstation)
      • press CTRL-ALT-F2 (change to the second virtual terminal in Linux)
      • send the cursor to the upper left corner of the screen
      • send the cursor to the upper right corner of the screen
      • send the cursor to the lower left corner of the screen
      • send the cursor to the lower right corner of the screen
      • draw a box with the mouse cursor
      • press the left-click mouse button
    • Implement another Keyboard subroutine that types out a user-specified message.

    The code ties all of this functionality together in the following fashion:
    • When first powered on, run the blinking white LED subroutine.  At the end of each cycle, run a subroutine that 10% of the time kicks off random mischief.
    • When button is pressed, switch to the Red-White-Blue fade subroutine.
    • During the Red-White-Blue subroutine, at the end of each cycle, run a subroutine that 10% of the time kicks off random mischief.  If the switch is pressed, the effect depends on what color is being displayed:
      • When fading between colors, the rainbow color wheel is run.
      • If pressed when Red, run random mischief.
      • If pressed when White, switch back to the blinking white LED subroutine.
      • If pressed when Blue, Morse code a going away message via the LED while typing it out character-by-character over USB.

Bill of Materials

    The following items were used in this build:

4" Black Canvas Frame
Small easel
Adafruit Protoboard
Arduino Micro
RGB LED (common anode)
USB Cable
USB Battery
100Ω Resistor
Tactile switch button
Miscellaneous Wires, Staples, etc
Challenge Coin

The Build - Prepping the Materials

    Remove the canvas from the frame.  Remove the excess material from the inside of the frame to make room for the circuit board.  Glue the protoboard to the frame (the protoboard will serve as both a circuit board and structure for the going away gift).

The Build - Wiring the Protoboard

    Here is the circuit diagram for the Protoboard:

[Not to scale]
    You'll note that there are three switches listed in the bill of materials, yet only one on the circuit diagram above.  In short, the remaining two switches are non-functional, only there to provide structural support (three points being the minimum number of contact points required for a stable plane).  When putting this all together, I recommend that you first solder the Arduino Micro in place.  Then place the active button (i.e., button connected to the circuit) above the Micro (where it will have its own dedicated circuit traces).  Using your challenge coin, determine where the other two buttons should go to provide a stable foundation, paying special attention to the traces you will be placing the inactive buttons on to ensure they don't interfere with the Arduino's operation (i.e., when the coin is pressed, all three buttons will be pressed, connecting the two traces those buttons are mounted to -- in my set up below, the placement of the buttons results in both traces being connected all of the time due to the button placement on the side rails).

All components positioned on the top of the board

   Once you know where the buttons are, figure out the placement of the remaining components based on the remaining space (other than the buttons and LED, all components should go on the bottom of the board).  Solder everything in place with the exception of the RGB LED (be especially careful that the three switches are soldered level at approximately the same height to provide a solid base for the coin).  Bend the RGB LED lines so they fit in the protoboard holes and take note of which holes you intend to use (simplifying placement of the RGB LED after the canvas is in place).  My finished protoboard can be found below (top of board is depicted above):

Protoboard back, post solder.

The Build - Putting it all together

  With the protoboard finished, wrap the canvas back over the frame and staple it in back in place.  From the back of the board, use a needle to punch through the protoboard and canvas in the spots previously identified for the RGB LED.  You may need to work a little to get the holes large enough to get the RGB leads through the canvas; work slowly to minimize any unnecessary canvas damage.  Once seated, solder the RGB LED in place.  Use a black marker to darken the RGB LED wires and/or touch up any canvas damage.  Trim and hot glue the flaps of the canvas.  Attach the USB cable to the Arduino Micro, and hot glue to the frame.  Hot glue the coin to the canvas over the three switches and allow it to cool.  Hot glue the frame and battery to the easel. Now we're ready for programming!

The Build - Programming the Arduino

  The code for the Arduino is located at https://github.com/ScratchesTheItch/Going_Away_Gift.  Clone it to your workstation using:

     git clone https://github.com/ScratchesTheItch/Going_Away_Gift.git

Once you have the code downloaded, just use Sketch to upload it to your Arduino and you should be good to go (Don't know how?  See http://arduino.cc/en/Guide/HomePage for details on how to get your Arduino up and working).  You'll know that everything is working correctly when you the LED starts blinking white.


    This is a relatively simple build, but makes for a fairly interesting going away present.  The  USB Rubber Ducky functionality is a good showcase of the mischief an Arduino Micro can wreak if programmed to do so.  I've also posted this as the Morse code routines are the most complete that I've seen on the web thus far and could be useful to others.  Any comments/suggestions?  Please leave those in the comments below.  Thanks for reading.

No comments:

Post a Comment