After I built this, I discovered that Milwaukee already makes something that does just that, called a Power Port for their 12v lineup of power tools. Why not save $20 and build it into a tool you've already got? The 12v -> 5v USB adapter I used can handle up to 24v of input, so you could do this with your 18v tools as well. It also has a handy status LED, so you know when the power is switched to it.
- 12-24v battery operated power tool
- Car cigarette USB adapter
- Solodering iron
- Glue gun
Step 1: Disassembly
Also take apart the car charger, mine had a sneaky screw under the label.
Step 2: Soldering and Testing.
These wires will need to be attached to the battery contacts, but first put your switch if you're using one, on the positive wire.
As you can see, the wires will have to be pretty short to fit in the confined space, use heat shrink and hot glue where necessary.
Also, if your design requires your USB port or your switch to be installed from the outside of the tool casing, make sure to cut the hole and install it before finishing the soldering. My hole lined up with the seam line of the two case halves.
Once everything is together, plug in a battery and switch it on, you should see your LED status light come on. Test the output with a multimeter, you should be getting 5v across the outside two pins of the USB port.
Step 3: Finishing
Once everything fits the way you like it, hot glue the parts in place. I also covered the exposed PCB contacts to keep the 2 boards from shorting against each other. Screw the case back together and you're done!
I use this a lot for geocaching, because my GPS has a terrible battery life, and quite often a flashlight can come in handy for finding well hidden caches, even during the daytime.