Monday, December 31, 2012

Loose arduino turret writeup

Because I didn't really document things as I went, and because my style of construction is absurdly haphazard, I wasn't able to write up a terribly good guide to making the turret.  However, here's what I was able to toss together.  Hopefully this should be enough to guide you in the right direction and help you learn stuff as you fill in the gaps, but unfortunately it won't be enough for you to sit down and build this from scratch if you don't have any previous fabrication or electronics experience.  If you have any specific questions about stuff (materials, wiring diagrams, detail pictures, anything like that) feel free to ask and I'll do my best to answer.

Turret writeup:

-Overall structure – the big picture
-Horizontal control – making it look left and right.
-Vertical control – making it look up and down
-Fire control – making it fire
-Electronics – the brain that ties it all together
-Specific links – links to components and code websites

Overall structure:

From a mechanical standpoint, the turret has three main pieces. There's the base, which remains completely stationary no matter how the turret moves. There's the body, which rotates on top of the base. There's the gun platform, which rotates up and down while rotating left and right with the body. The main structural material I used was lexan, although some other plastic, plywood, or (if you're careful about avoiding electrical shorts) metal would also work.
The base is simply a 12” by 12” square of 1/4”-thick lexan. It has a lazy susan bearing bolted to its top, and in the center of the square (centered with respect to the lazy susan) is a large sprocket gear that's used in the horizontal control.
The body is mounted atop the lazy susan, to allow it to rotate freely with respect to the base. It's bolted on top of approximately 1 1/2” spacers (in my case, I used extra nuts on the bolts) to leave room for the gears that allow horizontal movement. On top of the body's panel are two upright legs, atop which are situated bearings that hold the axle of the gun platform.
The gun platform is a 1/2” diameter lexan rod, to which two flat sheets of lexan have been glued (Weld-On 4 acrylic solvent makes connecting lexan to lexan ridiculously easy). I put pieces the same thickness as the axle between the sheets at each edge of the platform, to ensure that it was a consistent thickness. In order to connect the gun to the gun platform, I used electrical tape. Many more elegant solutions are possible, but this was basically the last thing I did when making the turret, so I was getting sloppy.

Horizontal control:

In order to power both the horizontal and vertical movement, I use motors taken from cordless drills. The one for horizontal control is affixed vertically, pointing down, to one of the legs. The chuck is still attached, and it holds a short length of 1/4” diameter steel axle. This goes through a hole in the body's bottom panel, and on the other side of the panel a small sprocket gear is attached to the axle. This sprocket gear is connected via chain with the large sprocket gear in the center of the base.
This motor on my turret is held in place by a strange series of wrapping done with spare 1/8” lexan rod. Gluing it in place, using hoseclamps to connect it to the leg, making some sort of bracket, duct tape, or almost anything else would be better, but it works.

Vertical control:

The motor to control vertical movement is mounted horizontally along the body's bottom panel, parallel with the axle of the gun turret. It's held in place by being tightly stuck in a large hole in one of the legs. The chuck of the motor holds another small piece of 1/4” diameter axle, that extends through a 1/4” hole in the other leg. On the far side of this leg, a small sprocket gear is attached to the axle.
The gun platform axle has a large sprocket gear attached to it, and it's connected to the motor's gear with a chain. To make the gun platform move more smoothly I've attached its axle to the legs with rotating bearings; for most purposes, 1/2” holes drilled in the lexan (or whatever material) will probably work almost as well, and be cheaper.

Fire control:

The gun I'm using is the cheapest electronically-triggered airsoft gun I could buy at the super-store down the street from my apartment. It's activated with just a small switch inside the body, connected via some levers and springs to the trigger. It's a pain to actually physically pull the trigger with a solenoid, so I just drilled into the gun body (it's transparent plastic, so it was pretty easy to figure out what to do) and unsoldered the wires from the switch. I connected these to two longer wires that lead back to the electronic control unit, where a relay closes the circuit to make it fire.
Because the batteries for the gun were stored in its handle, and I wanted to remove the handle to make it easier to mount on the gun platform, I had to replace them with an external battery pack. This is fairly simple – get an external battery pack of the same size (in this case, four AAs) and attach the leads to the two springs that connect the batteries to the internal gun circuitry.


To control the turret, I use an Arduino Duemilanove. It's an open-source microcontroller platform designed for hacky prototypes like this. I'm also using two Arduino “shields,” circuit boards with additional components that easily pop onto the Arduino. One of them is a Pololu motor controller to allow me to have precise control over the power and direction of each motor. The other is one that I made that has a Wii Nunchuck adapter and a pair of relays, chained together, to allow the Arduino to receive input (the Nunchuck adapter) and trigger the gun (the relays).
The motor shield just pops right on top of the Arduino, and the wires for the motors plug in easily. The relay/nunchuk shield takes a bit more work but is still relatively straightforward.

Specific links:

The motor controller: Pololu Dual MC33926 Motor Driver Shield for Arduino []
The wired nunchuk library: []
The wireless nunchuk library: []
The Arduino code: []