by James Floyd Kelly
Cost
$50
Print Time
3 hours
Bed Size
4″x4″x4″
Assembly
2 hours
A few years back my wife gave me a nice pen that rested on a grip-shaped base as a fun little birthday gift for my home office.
Recently I began to wonder if it might be possible to add a special effect or two to the pen and base. After all, the pen looked just like a laser pistol right out of a science fiction movie! Pew Pew!
After examining the pen and base, I determined that the base wasn’t hollow and was too small to really allow me to add any electronics inside. So, I decided to start from scratch.
In this project I’ll show you how I used my 3D printer to create custom parts to retrofit an existing object and I’ll pass along a few prototyping tricks that you might find useful in your own projects.
By the end of the chapter, you’ll be able to duplicate the work I’ve done to create your own 1950s Style Raygun Pen—or have found a way to improve it!
Table 2-0.
Files to Download
To complete the 1950s Raygun Pen project, you’ll need to download the fabrication files and code from the Make: 3D Printing Projects site.
Every good retrofitting project begins with a brainstorming session.
I already knew that I wanted my Raygun Pen to “do something” other than just allow me to write or draw. Lots of ideas popped into my head.
The Raygun Pen could:
Make a “pew pew” sound when a button is pressed
Put some LEDs in the grip that light up when the pen is removed
Play a theremin-like space sound when the pen is placed on the base
Spin 360 degrees while the pen is resting in the base
After looking at various electronic components, I ultimately settled on using a tiny microcontroller board called a Trinket to control a NeoPixel Ring. The project is powered by a tiny battery box that holds three AAA batteries and provides the 5V needed by the electronics.
In the end, I settled on a simple short-term goal for the Raygun Pen. When the user places the pen on the base, which is shaped like the grip of a raygun, it closes a circuit. This causes the LEDs in the base to light up and cycle through a fun light pattern. When the pen is lifted from the base, the circuit is broken and the lights turn off.
Before you begin constructing your Raygun Pen, you’re going to need to purchase the actual pen that will sit on the base.
There are easily hundreds of suitable pens out there. When I began hunting for a pen to use, I wanted something that had a distinctive look to it—something reminiscent of early science fiction movies and those crazy-looking rayguns that the spacemen would fire. What I chose was the Cross Edge Nitro Blue (Figure 2-1)—normally I would never have selected a $40 pen but I got it on sale for $15 and it was perfect.
Figure 2-1. Cross Edge Nitro Blue pen
Ultimately, you’re going to want to pick one that suits your tastes and the type of device you wish to build. But before you make a purchase, find a pen that has an outer metal shell (not plastic) or at least a metal clip.
Why a metal body or metal clip? The metal will be used to help close the circuit that will be built inside the base and grip of the Raygun Pen.
You don’t have to have a metal pen or metal clip to close the circuit. You could easily incorporate a simple on/off switch on the base that turns the NeoPixel Ring animation on and off.
After selecting the pen, the next step is to create the shape of the grip that will hold the pen.
You could use a ruler or calipers to take measurements of your pen and then create a grip using a CAD application—at first that’s exactly what I intended to do. My original grip, however, was too angular—lots of sharp edges that made it look funny.
I decided to try and create some sketches of different grips. I found the easiest way to find something I liked was to make a few photocopies of my pen and then draw the grip on the photocopy, as seen in Figure 2-2.
Figure 2-2. Grip sketch on pen photocopy
After I dialed in the grip’s look, I designed it in Tinkercad. Tinkercad allows you to use primitive objects (such as cubes, spheres, and pyramids) to create more advanced shapes, but it can be a very time consuming to create something like the shape shown in Figure 2-2.
Luckily, there’s actually a much faster way to take a unique shape or sketch you’ve created and bring it into a CAD application.
Tinkercad can only import STL and SVG files, so for me to use my custom shape I’ll need to convert it to the SVG file format. Fortunately, there’s a free and easy online tool that can do this for you.
First, create a clean trace of the shape on a white piece of paper and then fill it in with a black marker. You’ll end up with something that looks like Figure 2-3.
Figure 2-3. Shaded grip sketch
Take a photo or scan the image and save the JPEG image to your computer and then point your web browser to online-convert.com. Click the “Go” button in the Image Converter box and select the “Convert to SVG” option as shown in Figure 2-4.
Figure 2-4. Online-Convert.com
A new screen will appear like the one in Figure 2-5. Click the “Choose Files” button and browse to the location of the JPEG image of your shaded shape. Also click the Monochrome option in the Color section. Click the “Convert file” button and your SVG file will be created.
Figure 2-5. Convert image to SVG
Next, this SVG file must be imported into Tinkercad. Log in to tinkercad.com and click the “Create new design” button shown in Figure 2-6.
Figure 2-6. Create new Tinkercad design
On the right side of the screen, open the Import section. Click the “Choose File” button, browse to your new SVG file, and then click the “Import” button.
As you can see in Figure 2-7 the grip has been imported, but it is a bit large compared to my sketch measurements.
I knew what the length and width of the grip should be because I had measured the paper sketch shown in Figure 2-2.
Figure 2-7. File imported too large
I resized the imported SVG in Tinkercad by holding down the Shift key and then dragging one of the corner controls to lock in the length and width ratio.
Then I needed to adjust the thickness. My intent was to split the grip into two pieces that will be hollowed out, so I could route the wires used in the circuit.
Since Tinkercad allows me to copy a 3D model and flip or mirror the model, I changed the grip’s thickness to half the final thickness.
Tinkercad has plenty of tutorials that can help you understand the controls and features better.
After resizing the grip to the proper measurements, I ended up with the solid object shown in Figure 2-8.
Figure 2-8. Solid half-thickness Raygun grip
Now it’s time for a test print to confirm that the size and shape matches my sketch. I didn’t print it out at full thickness—I only need a few layers to confirm that the shape is a match. Figure 2-9 shows my test grip printed out in white filament. I was quite happy with it.
Figure 2-9. Grip prototype test
Next, back in Tinkercad, I used a mix of rectangles and triangles converted into “hole objects” (with the Hole button) to make room for the necessary wiring, as shown in Figure 2-10.
Figure 2-10. Converted to a hole object
After merging the solid and hole objects, I ended up with a grip piece that was hollowed out. Figure 2-11 shows one-half of the grip.
Figure 2-11. Hollow grip
I could have easily printed the entire grip out, but to save time, I only printed the parts that I needed to test for accuracy. I needed to insert the pen into the grip to ensure that the pen sat properly and that the metal clip could contact with the circuit-closing wires.
With Tinkercad, I can make copies of existing models and then delete away sections I’m not interested in printing. To test the grip, I deleted some sections, leaving only the top third for printing.
Figure 2-12. A plethora of prototypes
Over a series of test prints, some of which are shown in Figure 2-12, I was able to add in a hollow space at the top of each grip half that both allowed the pen to rest properly and enabled the pen clip to go far enough down into the grip to touch two wires.
Once I was happy with the grip, I printed out the two halves, then put them together underneath the pen to see what it looked like. Figure 2-13 shows the two gray halves unassembled and Figure 2-14shows the assembled grip.
Figure 2-13. Unassembled grip halves
Figure 2-14. Assembled grip
The pen and grip will sit on top of a base that should be large enough to hold the battery box and the Trinket plus some wires. I went with one of the most popular and easily recognizable enclosures available to makers around the world—the mint tin. You can buy these from many sources or just find one in the grocery store.
Mint tins make great project enclosures; they’re cheap, strong, and open and close easily—and once closed the lid tends to stay closed. Plus, if you mess one up, it’s easily replaceable.
I wanted the NeoPixel Ring to sit inside a small partially curved surface. The best way to model this in Tinkercad is to create a sphere and cut off and keep the very top portion while discarding the bottom. The piece that remains behind will be flat on the bottom and curved on top.
Figure 2-15. Sphere fragment, hole object
Since I wanted to convert my cut sphere into a shell for the NeoPixel Ring, I took the measurments of the ring’s inner and outer diameters. Back in Tinkercad, I made a washer-like shape and converted it into a hole object that would be merged with the sphere. You can see the sphere fragment and the hole object in Figure 2-15.
Figure 2-16. Hole object and sphere overlay
Next, I merged the ring hole object (Figure 2-16) and the sphere fragment and ended up with the NeoPixel Shell shown in Figure 2-17.
Figure 2-17. Final merged NeoPixel Shell
Due to the too-tight fitting mishaps that I relate in “Prototyping Pitfalls”, I added a number of hole objects to the NeoPixel Shell so I could not only pop the ring out, but also so I would be able to route wires from the Trinket to the ring to make it function.
The final NeoPixel Shell model is shown in Figure 2-18 and Figure 2-19. I printed it in Rocket Red!
Figure 2-18. Final Tinkercad model
Prototyping Pitfalls
Funny story—it took three test prints to fine-tune the outer and inner dimensions of the hole ring before the NeoPixel Ring snapped down into the shell. And that’s when I figured out my mistake. The NeoPixel Ring was such a snug fit I couldn’t get the ring out! I couldn’t get a good grip on the ring with tweezers and I didn’t want to risk damaging the NeoPixel Ring, so after carefully drilling a few small holes on the back of the shell I was able to push it out.
Figure 2-19. Final Rocket Red printed base
That’s it for the 3D printer! But the Raygun Pen isn’t quite done yet…
Ask anyone who has done any type of electronics prototyping for any length of time, and they’ll tell you that it’s always a smart idea to test your circuits first before transferring them into an enclosure or soldering more permanent connections.
I absolutely love to use the female jumpers from Schmartboard (also available at select RadioShack stores)—these wires are very flexible and they make it super easy to plug and unplug connections quickly during prototyping.
The Trinket and NeoPixel Ring connections are at fixed locations on the printed circuit boards (PCBs), so I recommend that you solder headers to the Trinket and the NeoPixel ring (as shown in Figure 2-20) and use female jumpers to connect the components.
Figure 2-20. Trinket and NeoPixel with soldered headers
Trinket headers
The Trinket arrives from Adafruit with precut headers in the package; solder them to the PCB. Later, you’ll be attaching jumpers to the connections labeled #0, BAT, and GND.
NeoPixel Ring headers
Use the headers included with the jumper pack. Snap off three single headers with pliers and solder one to each of the Data Input, Power 5V, and Power Signal Ground holes.
Optionally, you could forgo the headers and solder wires directly to PCBs.
Trinket Setup Tricks
In order to use the Trinket, you’ll need a to install a modified version of the Arduino IDE. There are a few tricky bits, so read through the Adafruit Introducing Trinket Guide to set up and learn to use your Trinket.
After you’ve gone through the Trinket Guide, connect your Trinket to your computer via USB cable and run the Blink sketch. You can locate this example program from File menu→Examples→01.Basics→Blink. When the tiny LED on the board blinks, you’ll know that the hardware is functioning properly.
Once you’re sure you have a working Trinket, it’s time to test the NeoPixel ring and tweak the animation code.
Head to the Adafruit website to download the NeoPixel library and while you’re there, take a look at the original version of the NeoPixel Ring program I’ve modified for this project.
If you haven’t downloaded my code (raygun_blue_spin_final.ino) for this project yet, grab that as well.
Next, you’ll need to install the NeoPixel library in order to run the Arduino code. You can do this easily with the built-in library manager (Arduino Sketch menu→Include Library→Manage Libraries); the NeoPixel library is already present.
Unfamiliar with Arduino Libraries?
Installing Arduino libraries (like the Adafruit NeoPixel library you’ll need for this project) can be confusing for new users. Since several projects in this book use Arduino libraries, we’ve added step-by-step instructions in Appendix A.
The original NeoPixel Ring program does a number of things. It cycles through multiple animation pattern demos that consist of three colors—red, blue, and green.
I decided I liked the pattern where a single LED lights up at a time, racing around the perimeter. I slightly modified the original Arduino program by removing the bits I didn’t need and changing the LED color to blue in the raygun_blue_spin_final.ino file, also shown in the following code example.
Changing the LED Color
The following code example uses hexidecimal notation to set the colors: 0xff0000 for red, 0x0000ff for blue, and 0x00ff00 for green. To change colors, swap out the line uint32_t color = 0x0000FF; for another hex color.
// Raygun Pen program// Modified the original version from Adafruit Goggles project#include <Adafruit_NeoPixel.h>#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.#include <avr/power.h>#endif#define PIN 0Adafruit_NeoPixel pixels = Adafruit_NeoPixel(32, PIN);uint8_t mode = 0, // Current animation effect offset = 0; // Position of spinning LEDuint32_t color = 0x0000FF; // Start blueuint32_t prevTime;void setup() {#ifdef __AVR_ATtiny85__ // Trinket if (F_CPU == 16000000) clock_prescale_set(clock_div_1);#endif pixels.begin(); pixels.setBrightness(85); // 1/3 brightness prevTime = millis();}void loop() { uint8_t i; uint32_t t; { for (i = 0; i < 16; i++) { uint32_t c = 0; if (((offset + i) & 7) < 2) c = color; // 4 pixels on... pixels.setPixelColor( i, c); // NeoPixel in Shell } pixels.show(); offset++; delay(50); }}
Now that you’ve configured the animation code, you’ll need to test it out on the NeoPixel Ring.
Connect the Trinket to your computer with the USB cable. Then use jumpers to connect the NeoPixel Ring connections to the Trinket as shown in Table 2-1.
Load the code on the Trinket by clicking the upload button (right-pointing arrow) in the Arduino IDE.
Although the IDE shows the code has uploaded, it will appear that nothing has happened, but that’s not the case. You can’t power your NeoPixel Ring from your computer; it needs to be hooked up to a separate battery before it will illuminate.
Next you’ll breadboard the circuit, connect a battery pack, and set the NeoPixels aglow!
The battery box provides both V + and GND connections to the LED ring and the microcontroller board.
To make connecting and disconnecting the battery box much easier during testing, cut off one end of two female/female jumpers. Then clip the red and black wire exiting the battery box and solder on two jumper wires, as shown in Figure 2-21.
In this next step, you’ll connect the Trinket, NeoPixel Ring, and battery box using jumpers and a breadboard.
Figure 2-21. Breadboarded prototype
Because this project uses female/female jumpers, cut two rows of 3-pin headers and insert them into the breadboard, then connect the female jumpers to the headers.
The breadboard and PCB connections are described in detail in Table 2-2.
As the breadboard setup shows in Figure 2-21, now that it’s finally connected to the battery pack, the NeoPixel Ring is displaying the blue “racing” pattern.
Breadboard connections are numbered left to right for each header row, as shown in Figure 2-21.
Next, test out using the pen to close the circuit and activate the NeoPixel Ring. For the circuit to be closed by pen contact, it needs to be open by default.
First, insert a 2-pin header into the breadboard. Then disconnect the black/blue battery ground wire from the 3-pin header and attach it to the 2-pin header, as shown in Figure 2-22.
Figure 2-22. Pen contact wires
Cut and strip the ends of two “pen jumpers,” providing contacts for the pen’s metal clip to close the circuit. Attach one stripped jumper to the 2-pin header and the other to the former ground header row. Figure 2-22 shows the pen wires added to the existing circuit, sticking straight up, breaking the ground connection.
Now the moment of truth! Holding the nonmetalic parts of the pen, use the metal clip to bridge the two wires that are standing straight up.
If the NeoPixel Ring lights up, you’ve done it! If your prototype isn’t successful, check your connections until you find the problem. Jumpers are very handy for troubleshooting connection problems; the connections are easily rearranged—no desoldering required.
Now that you’ve got a working circuit, it’s time to transfer it from the breadboard to our final project enclosure.
On the breadboarded circuit, the headers shared a row and the breadboard’s internal connections created a common contact point. Now that you’ve removed the circuit from the breadboard, you’ll need to re-create these shared connections.
Since you’re replicating the final circuit shown in Figure 2-22, you’ll need two 3-pin headers and one 2-pin header (Figure 2-23).
Figure 2-23. Headers and stripped wire
The easiest way I’ve found to create a single connection between attached headers is to strip the end from a piece of wire, then lay it across the headers. Add a blob of solder to combine the two as shown in Figure 2-24. Then clip off the excess wire protruding from the side.
Figure 2-24. Solder a wire across all three headers
You can also use braided wire twisted around the headers as a base for the solder to adhere to.
Wrap the soldered ends of the headers with some electrical tape as shown in Figure 2-25 to prevent any shorts from occurring; remember, you’ll be stuffing these wired components into a small tin case, so use electrical tape to insulate any exposed leads whenever possible.
Figure 2-25. Taped, soldered headers
Painting the tin will be easier if you remove the lid. Use a pair of pliers to gently pull apart the metal tabs attaching the lid until you have enough space to separate the two pieces. Then it’s easy to paint the outer surface any color you like; I chose black as you can see in Figure 2-26.
Figure 2-26. Spray-painted tin
Next, on a blank piece of paper, trace the 3D-printed base. Be sure to include the holes for where the wires will connect to the NeoPixel Ring and a hole for inserting wire up into the hollow grip. Figure 2-27 shows my tracing.
Figure 2-27. Traced base
Tape or glue down the tracing to the underside of the tin lid. Orient the tracing so the Raygun Pen will point over the length of the base (otherwise it will tip over). The back of the base should be closest to the tin edge (see Figure 2-28 for general orientation), although that’s jumping ahead a step.
Next, using your pattern as a guide, cut holes in the tin lid with a drill press or rotary tool. The circuitry inside the tin needs to pass through the 3D-printed base to reach the NeoPixel Ring and pen connection points.
Before connecting any wires, test-fit the NeoPixel Ring into the red base, and the base into the tin, to ensure that they fit properly, as shown in Figure 2-28.
Figure 2-28. LED ring in 3D-printed shell on base
While test fitting, double-check that the Data Input, Power 5VDC, and Power Signal Groundheaders on the NeoPixel Ring are visible through the underside of the tin’s lid.
Once you’re satisfied with the holes, don’t reattach the tin lid. It’s easier to assemble the electronics with the two pieces still disconnected.
It’s time to start fitting things into the tin. Your battery box may be slightly larger or smaller than mine, but you want to make certain it’s placed where it won’t block the Trinket, or the NeoPixel Ring headers that protrude through the lid and down into the tin.
Figure 2-29 shows the initial test fit that will allow you to close everything up and tuck all the wires in. Use blue painter’s tape to hold things in place during test fitting. Once you’re confident in the component placement, use some double-sided tape to secure the battery box and a small dab of hot glue to hold the Trinket in place.
Figure 2-29. Initial test enclosure fit
Thread the Pen Connection 1 and Pen Connection 2 wires up through the largest hole in the tin lid and through the printed base as shown in Figure 2-30.
After the wires have been threaded through, reconnect the pieces of the painted mint tin and close the lid, securing the components inside.
Turn on the battery box before closing the tin or the pen won’t have a powered circuit to close.
Figure 2-30. Protruding pen connections
If you haven’t already, glue the two halves of the gray grip together with hot glue.
Trim and strip the ends of the protruding jumpers and solder a single pin header to both; this makes them a bit easier to grab and thread through the hollow grip as you fit the grip into the red base, securing it with hot glue.
Next, clip the headers off of the “grip wires” and apply a bit of solder to the wire, tinning them to make them stiff. I folded them over the top of one side of the grip as shown in Figure 2-31.
As you prototyped previously, these “grip wires” form the open circuit that’s closed when the pen clip touches both of the exposed ends.
Figure 2-31. Wires folded over grip
With the battery box turned on inside the enclosure, place the pen on the grip and hold your breath. A few seconds later, the LED ring should begin animating (see Figure 2-32).
Figure 2-32. Finished Raygun Pen
If removing the pen breaks the connection and the LEDs stop, it works!
Congratulations! You now have a working Raygun Pen, with the pen grip illuminated with blue LED animation.
Although my Raygun Pen build worked just as I expected, I immediately began thinking of ways it could be improved:
Augment the grip files
The exposed wires on the top of the grip work fine, but the design could be improved by creating two small holes in the grip’s 3D model that would be used to hold the exposed wires. A dot of solder could be applied to each wire, keeping them from falling down inside the grip and ensuring proper contact with the pen’s clip.
Skip the glue
Instead of gluing the grip to the top of the shell, it would be preferable to create a clip or pin locking system to keep the NeoPixel Ring shell and grip halves securely in place.
Improve the grip’s pen fit
The grip has a flat surface and ideally it would be more rounded to “hug” the contour of the pen.
Add sound
It would be super fun to have the LED ring light up and hear a PEW! PEW! sound go off when the pen is placed on the grip.
A custom case is probably in order, but check around to see what kinds of noisemaking options are available and whether they could be squeezed into the tin.
If you’re new to 3D printing (and maybe even electronics), I hope my project has inspired you to engage in the world of possibilities that exist for creating your own custom projects. For me, a project like this one is never finished, so it’s back to Tinkercad to begin as I develop additional improvements for Raygun 2.0!