Step 12: War Machine cannon

Example 8- War Machine cannon

You want to be the War Machine? This example is based on the Predator cannon but uses a motor connected to a transistor to spin the cannon barrels. When you push the fire button the motor turns on. There is a 1N4004 diode to prevent back voltage from the motor damaging the controller output pin.

A War Machine cannon is substantially larger than a Predator cannon and would require larger, more powerful servos so I have individual TIP 120 transistors shown on the wiring diagram.

For mounting the cannon Servocity sells pan/tilt mechanisms that would be perfect for this application-

 * Example 8
 * Iron Man War Machine Cannon
 * This uses a modified Wii nunchuck as a head tracking input device to control an animatronic Iron Man War Machine cannon
 * Adafruit Wave shield is used for sound effects
 * Honus 2010
 * Wii nunchuck reading code modified/extended from nunchuck code by Tod E. Kurt and Windmeadow Labs
 * 2007 Tod E. Kurt, http://todbot.com/blog/
 * The Wii Nunchuck reading code is taken from Windmeadow Labs, http://www.windmeadow.com/node/42

 #include "Wire.h"  // include the Wire library

int controlPin1 = 7; // Control pin for sound effects board using z button 
int transistorPin1 = 13; // Control pin for cannon LED using z button 
int transistorPin2 = 12; // Control pin for servo 1 using c button
int transistorPin3 = 11; // Control pin for servo 2 using c button
int transistorPin4 = 10; // Control pin for cannon motor using z button
int servoPin1 = 9; // Control pin for servo 1 using accelerometer x axis
int servoPin2 = 8; // Control pin for servo 2 using accelerometer y axis

int pulseWidth1 = 0; // Amount to pulse the servo 1
int pulseWidth2 = 0; // Amount to pulse the servo 2

int refreshTime = 20; // the time in millisecs needed in between servo pulses
long lastPulse1;
long lastPulse2;

int minPulse = 700; // minimum servo pulse width
int loop_cnt=0;

boolean button_down = false;
unsigned long start;

void setup()
pinMode(controlPin1, OUTPUT); // Set control pin 1 as output
pinMode(transistorPin1, OUTPUT); // Set transistor pin 1 as output
pinMode(transistorPin2, OUTPUT); // Set transistor pin 2 as output
pinMode(transistorPin3, OUTPUT); // Set transistor pin 3 as output
pinMode(transistorPin4, OUTPUT); // Set transistor pin 4 as output
pinMode(servoPin1, OUTPUT); // Set servo pin 1 as output
pinMode(servoPin2, OUTPUT); // Set servo pin 2 as output

pulseWidth1 = minPulse; // Set the servo position to the minimum
pulseWidth2 = minPulse; // Set the servo position to the minimum

nunchuck_init(); // send the initilization handshake
Serial.print("NunchuckServo ready\n");

void loop()
updateServo1(); // update servo 1 position
updateServo2(); // update servo 2 position

if( nunchuck_cbutton() ) {
digitalWrite(transistorPin2, HIGH); // turn on transistor pin 2 if c button is pressed
digitalWrite(transistorPin3, HIGH); // turn on transistor pin 3 if c button is pressed
else {
digitalWrite(transistorPin2, LOW); // turn off transistor pin 2
digitalWrite(transistorPin3, LOW);

if ( nunchuck_zbutton() )
if (!button_down) // if button was just pressed do this
digitalWrite(controlPin1, HIGH); // turn on sound effect
button_down = true;
start = millis();
else if (millis() - start > 1200)  // if timer has elapsed do this
digitalWrite(transistorPin1, HIGH); // turn on cannon LED
digitalWrite(transistorPin4, HIGH); // turn on cannon motor
else // if button is up do this
button_down = false;
digitalWrite(controlPin1, LOW); // turn off sound effect
digitalWrite(transistorPin1, LOW); // turn off cannon LED
digitalWrite(transistorPin4, LOW); // turn off cannon motor

delay(1); // this is here to give a known time per loop

void checkNunchuck1()
if( loop_cnt > 100 ) { // loop()s is every 1msec, this is every 100msec


float tilt = nunchuck_accelx(); // x-axis, in this case ranges from ~70 - ~185
tilt = (tilt - 70) * 1.5; // convert to angle in degrees, roughly
pulseWidth1 = (tilt * 9) + minPulse; // convert angle to microseconds

loop_cnt = 0; // reset for


// called every loop().
// uses global variables servoPin, pulsewidth, lastPulse, & refreshTime
void updateServo1()
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() - lastPulse1 >= refreshTime) {
digitalWrite(servoPin1, HIGH); // Turn the servo on
delayMicroseconds(pulseWidth1); // Length of the pulse sets the servo position
digitalWrite(servoPin1, LOW); // Turn the servo off
lastPulse1 = millis(); // save the time of the last pulse

void checkNunchuck2()
if( loop_cnt > 100 ) { // loop()s is every 1msec, this is every 100msec


float tilt = nunchuck_accely(); // y-axis, in this case ranges from ~70 - ~185
tilt = (tilt - 70) * 1.5; // convert to angle in degrees, roughly
pulseWidth2 = (tilt * 9) + minPulse; // convert angle to microseconds

loop_cnt = 0; // reset for


// called every loop().
// uses global variables servoPin, pulsewidth, lastPulse, & refreshTime
void updateServo2()
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() - lastPulse2 >= refreshTime) {
digitalWrite(servoPin2, HIGH);  // Turn the servo on
delayMicroseconds(pulseWidth2); // Length of the pulse sets the servo position
digitalWrite(servoPin2, LOW); // Turn the servo off
lastPulse2 = millis(); // save the time of the last pulse

// Nunchuck functions

static uint8_t nunchuck_buf[6]; // array to store nunchuck data,

// initialize the I2C system, join the I2C bus,
// and tell the nunchuck we're talking to it
void nunchuck_init()
Wire.begin(); // join i2c bus as master
Wire.beginTransmission(0x52); // transmit to device 0x52
Wire.send(0x40); // sends memory address
Wire.send(0x00); // sends sent a zero.
Wire.endTransmission(); // stop transmitting

// Send a request for data to the nunchuck
// was "send_zero()"
void nunchuck_send_request()
Wire.beginTransmission(0x52); // transmit to device 0x52
Wire.send(0x00); // sends one byte
Wire.endTransmission(); // stop transmitting

// Receive data back from the nunchuck,
// returns 1 on successful read. returns 0 on failure
int nunchuck_get_data()
int cnt=0;
Wire.requestFrom (0x52, 6); // request data from nunchuck
while (Wire.available ()) {
// receive byte as an integer
nunchuck_buf[cnt] = nunchuk_decode_byte(Wire.receive());
nunchuck_send_request(); // send request for next data payload
// If we recieved the 6 bytes, then go print them
if (cnt >= 5) {
return 1; // success
return 0; //failure

// Print the input data we have recieved
// accel data is 10 bits long
// so we read 8 bits, then we have to add
// on the last 2 bits. That is why I
// multiply them by 2 * 2
void nunchuck_print_data()
static int i=0;
int joy_x_axis = nunchuck_buf[0];
int joy_y_axis = nunchuck_buf[1];
int accel_x_axis = nunchuck_buf[2]; // * 2 * 2;
int accel_y_axis = nunchuck_buf[3]; // * 2 * 2;
int accel_z_axis = nunchuck_buf[4]; // * 2 * 2;

int z_button = 0;
int c_button = 0;

// byte nunchuck_buf[5] contains bits for z and c buttons
// it also contains the least significant bits for the accelerometer data
// so we have to check each bit of byte outbuf[5]
if ((nunchuck_buf[5] >> 0) & 1)
z_button = 1;
if ((nunchuck_buf[5] >> 1) & 1)
c_button = 1;

if ((nunchuck_buf[5] >> 2) & 1)
accel_x_axis += 2;
if ((nunchuck_buf[5] >> 3) & 1)
accel_x_axis += 1;

if ((nunchuck_buf[5] >> 4) & 1)
accel_y_axis += 2;
if ((nunchuck_buf[5] >> 5) & 1)
accel_y_axis += 1;

if ((nunchuck_buf[5] >> 6) & 1)
accel_z_axis += 2;
if ((nunchuck_buf[5] >> 7) & 1)
accel_z_axis += 1;


Serial.print(joy_y_axis, DEC);
Serial.print(" \t");

Serial.print(accel_x_axis, DEC);
Serial.print(accel_y_axis, DEC);
Serial.print(accel_z_axis, DEC);

Serial.print(z_button, DEC);
Serial.print(c_button, DEC);

Serial.print("\r\n"); // newline

// Encode data to format that most wiimote drivers except
// only needed if you use one of the regular wiimote drivers
char nunchuk_decode_byte (char x)
x = (x ^ 0x17) + 0x17;
return x;

// returns zbutton state: 1=pressed, 0=notpressed
int nunchuck_zbutton()
return ((nunchuck_buf[5] >> 0) & 1) ? 0 : 1; // voodoo

// returns zbutton state: 1=pressed, 0=notpressed
int nunchuck_cbutton()
return ((nunchuck_buf[5] >> 1) & 1) ? 0 : 1; // voodoo

// returns value of x-axis joystick
int nunchuck_joyx()
return nunchuck_buf[0];

// returns value of y-axis joystick
int nunchuck_joyy()
return nunchuck_buf[1];

// returns value of x-axis accelerometer
int nunchuck_accelx()
return nunchuck_buf[2]; // FIXME: this leaves out 2-bits of the data

// returns value of y-axis accelerometer
int nunchuck_accely()
return nunchuck_buf[3]; // FIXME: this leaves out 2-bits of the data

// returns value of z-axis accelerometer
int nunchuck_accelz()
return nunchuck_buf[4]; // FIXME: this leaves out 2-bits of the data
<p>hello honus , is it possible to have the plan and component name for the hand repulsor , please , thanks my mail , leeloan@hotmail.com</p>
I'm not sure I understand. Everything you need is shown in the instructable.
<p>hello honus , is it possible to have full plan and component for build the hand repulsor ? as i'm not expert electronic but will try to buy and build it myself , my mail leeloan@hotmail.com</p>
Hi man. That canon is awesome. Would you be able to make the basic assembly as shown in the 15 steps. I will build into medi pack and add the canon onto the white bracketing<br>I have a suit and would love this accessory
Thanks- glad you like it! I'm sorry but I can't take on any more work right now.
My suit
My suit
And we'll paid for your time. No rush at all for finished article
Awesome stuff. Can't believe I haven't discovered your stuff sooner. Do you have a email contact?<br>What is the best way to get your some of your pcb boards made? servo, transistor, led boards.
Oh and just with the servo and the blinking LEDs, nothing else
You mean like in Step 7? You can add another servo to any digital output pin and then just copy the code for the existing servo and change the output pin number.
Ah ok cheers
I like this a lot thanks for posting! Can someone tell me how I could add another servo to it, on the same breadboard?
<p>HI, you mentioned possibly building and assembling an Arduino animatronics board at a price. I'm not sure if this is something i could successfully build on my own, but I would be interested in building an adruino board with an Xbee chip that would power my repulsors and Unibeam with sound, helmet opening/closing with eyes lit up flickering when closed, and mini gun movement (spinning and movement tracking for my War Machine costume, I would be really interested in getting some pricing on what it would cost to build. If that is something you may have time or be interested in building, please let me know. Sincerely, ~greg my email is thegovernor08@yahoo.com</p><p>And thanks again for all of the helpful information.</p>
Honus, <br><br> Absolutely amazing work and I want to thank you very much for all the effort that has gone into this as well as taking and answering questions and comments! <br> I am just getting started with arduino and hope you can help me if at all possible. I'm planning a project for Halloween that includes a &quot;Nullifier Ray&quot; attached to the ceiling. I would like to have the body of the ray drop (tilt) down from level with the ceiling, and swing (pan) to the right to point at an object on a table. Then, I'd like the barrel to begin to spin and ultimately activate several super bright LEDs to simulate a &quot;blast&quot; from the ray. Sound would be great but isn't necessary. <br> Does this sound possible for a beginner such as myself and if so, would it be possible for you to help me work parts of your code to make it happen? <br> Thank you for any advice or help you can provide. I'm overwhelmed by all the information in this instructable!
Thanks! Of course your project is possible to do and I'm happy to help. Just work up a drawing or schematic with the specifics of what you want it to do and message me. The important things you need to figure out is the range of movement you need, how heavy it will be and how you want to power and activate it.
<p>Thank you for all the time you out into this, especially the purchase links. I'll be sure to share projects that result from the info.</p>
<p>Honus,</p><p>I'm wondering if I need a voltage regulator with the Pro Mini. Reading on the Arduino website, it says:</p><p>&quot;The Arduino Pro Mini can be powered with an FTDI cable or breakout board <br> connected to its six pin header, or with a regulated 3.3V or 5V supply <br>(depending on the model) on the Vcc pin. There is a voltage regulator on <br> board so it can accept voltage up to 12VDC. If you're supplying <br>unregulated power to the board, be sure to connect to the &quot;RAW&quot; pin on <br>not VCC.&quot;</p><p>I'm trying to figure out how to connect a G4 LED light which is rated to 9-15V DC to the Pro Mini to use in my IM gloves with a flex sensor to turn them on and off. I'm testing with my mega 2560 and have the flex sensor figured out but am trying to figure out how I am supposed to connect the light and the flex sensor and the battery to the pro mini. It sounds like I should be able to use an E23A battery which is 12 volts, but I don't want to fry the board, and have no idea how to wire all of these together as I'm just getting started with the electronics stuff. Any hints?</p>
There's a few different ways you can do this. You could use a 7805 voltage regulator to drop the voltage from your battery to 5V to power the ProMini and connect it to the VCC pin ( assuming you have the 5V version ProMini ) if you're worried about frying it. Some batteries are rated at maybe 12V but at full charge they can overshoot this by a fair amount. <br><br>Then you can also connect your 12V battery to your LED light using a transistor to turn it on and off- the ProMini will not be able to provide enough current to drive it so it cannot be directly connected to an output pin. You can use something like a TIP120 transistor to turn the LED on and off. <br><br>Just let me know if you need a wiring diagram! It's pretty simple to do. :)
<p>Hmm. Well, I bought 4 of the 3.3 volt Pro Minis to use in various parts of the suit, but may be able to return them to SparkFun as they haven't been opened. I got them because I figured fewer batteries to power the boards would save space. Would you recommend doing that or is there a workaround? And a diagram would be awesome! Can't tell you how many times I've poured over your tutorial and am just amazed at what you've done. </p>
<p>You can still use the 3.3V ProMinis- just connect the power out from the regulator to the RAW input. I do this all the time since I run servos with a ProMini from single power source. I'll get you a wiring diagram asap.</p>
<p>Cool. Thanks Honus.</p>
<p>Here you go. Just let me know if this doesn't make sense!</p>
<p> Thanks Honus. You are awesome! It totally makes sense.</p>
<p>Thanks to you I got the sensor, G4 light, and pro mini all working off that little 12V A23 battery. Thank you! Thank you! I had issues with the board not wanting to talk to my laptop to upload my sketch, and realized it was the cable of all things. The first 2 I tried wouldn't allow an upload, the third and 4th ones did. Did my first through-hole soldering to get wires hooked up.</p>
<p>Awesome! So happy you got it to work! :)</p>
<p>Wow awesome Instructable! very nice Project! </p><p>Do you have a Video of it working in final state? :-)</p><p>vlg Stefan</p>
<p>Thanks- glad you like it! </p><p>Video of what in it's final state?</p>
<p>I meant the Predator Gun and Helmet with painting and Costume ;)</p>
Have a look here-<br> <a href="http://www.instructables.com/id/Building-a-killer-Predator-costume/" rel="nofollow">http://www.instructables.com/id/Building-a-killer-Predator-costume/</a>
<p>Cool! Thank you!</p>
Wondering if there is another place to buy your PCB? <br>
You can upload the board files to several different PCB manufacturers and have them made. I haven't made any more of them as I'm going to make a simpler version of the board- I've found I rarely use the rechargeable LiPo and I'd like it to be a bit smaller to make it easier to fit in my projects.
Honus, <br>If you aren't using the LiPos any more, what are you using?
I've been using NiMh cells to power everything. Much more durable inside costumes. The biggest problem with using LiPo cells (especially when using multiple cells, like 2s packs) is regulating them in regards to low voltage cutoff since RC packs don't usually have any type of protection circuitry. There are also severe shipping restrictions on LiPo packs so if you have to ship a costume somewhere it's a real pain.<br><br>Unless you have a specific application where you need the energy density of LiPo cells due to weight and/or space restrictions they're just not worth the hassle in my opinion.
Great! <br>Favorited!
Thanks for this great instructable! <br> <br>I'm planning a very similar thing as the Predator shoulder cannon and have one question: <br> <br>I'm not much of a Wii gamer so I don't know exactly how a nunchuck behaves. But wouldn't the motion sensor still also be triggered when you move and walk around and not only when you turn your head? How did you make the cannon only follow your heads movement no matter where your whole body moves and turns to?
Thanks- glad you like it!<br><br>The sensor from the nunchuck is an accelerometer and it's mounted in the helmet so it only senses when the helmet moves (with respect to gravity.) It only senses when the helmet tilts ( X and Y axis ) so you can walk around all you want without it being affecting. Also have a look at the FAQ section- I explain a bit more there.
I looked at the FAQ first, but didn't understand it all. My first idea before reading your instructable was actually using two gyros (one on the head and one in the cannons base) like you described but that seemed very complicated to me. I think I'll try it with your method and experiment a bit :). <br> <br>I don't want to use a Nunchuk since there are some affordable accelerometer modules out there like this one: <br>http://www.ebay.de/itm/ADXL345-3-axis-Digital-Tilt-Sensors-Acceleration-Module-For-Arduino-/181185887400?pt=Bauteile&amp;hash=item2a2f853ca8 <br> <br>Or would it be advisable to get one with a gyro like this? <br>http://www.ebay.de/itm/MPU-6050-3-Axis-Gyro-Gyroscope-Accelerometer-Sensor-Module-for-Arduino-/181018466904?pt=Bauteile&amp;hash=item2a258a9a58
Pretty much any of the Analog Devices ADXL accelerometers would work. I really don't see the need for a gyro in this application but if you want to incorporate one to try and improve the rotation performance then I say go for it! :)
finally. a tutorial on how to use arduino for people like me that know jack shit about programming and hardware. i really want to get invested in animatronics and i am going to be having hand surgery later this year and want to build a portable hand for use while my hand is in a cast
What would it take to adapt this setup to be used in your Horus helmet rig? I just ordered an arduino board to get started and would love to be able to track my own head movements to the bird's head.
I've had a few people ask about this. The problem is that you can't really move your head that much while wearing the Horus helmet. The great bit with the Horus helmet is that your head stays still and ONLY the bird head moves. The lower part of the Horus helmet really does not move- the movie helmets only had a few degrees of rotation between the lower part of the helmet and the neck collar.
hi um i was wondering about animatronics and what i would need to go to college for in order to buld,design,and program animatronics and i noticed what you made was cool. so do you have any tips on what schools to go to or what programs to take?
I would look at mechanical engineering, robotics, 3D design/CAD, electronics and classes that involve physical computing. Animatronics covers a wide variety of disciplines- molding, casting, fabrication, mechanics, hydraulics, pneumatics, electronics, programming, etc. There's a lot of problem solving that involves thinking about how you want things to move and then making mechanisms that fit within a limited volume.<br> <br> There are classes and workshops for Arduino to get your feet wet in the electronics area and Stan Winston School has videos you can watch that cover all aspects of creature fabrication. They specifically have a couple of videos by Rick Lazzarini of The Character Shop that covers radio control animatronics. Check it out here-&nbsp;<a href="http://www.stanwinstonschool.com" rel="nofollow">http://www.stanwinstonschool.com</a><br> <br> Rick Lazzarini also teaches people here- <a href="http://www.animatronicsinstitute.com/" rel="nofollow">http://www.animatronicsinstitute.com/</a><br> <br> If you have any other questions just let me know!
Thanks so much...all of this makes alot of sense...I know what I want but no idea how to get there and have never done anything like this before. Sadly I have not even found anything prebuilt out there that does what I want either (my 2nd resort is always to cannablize anything premade). <br>I think it would be amazing if the eyes lit up when the sound effect when off...you are going to have to email me or else this post will get very long, but a list of parts would be a fantastic start. As far as sounds I would love a Wolf howl and growl/snarl too but I may be well overstepping my novice skills
It's definitely possible to do everything you want. :) just message me your email and I'll help you put it together.
Email me at spyderskiss@gmail.com <br>I found an online dealer who had the led lights prewired to 9voltr cap with switch so I have them but will still need help on the sound and synching the eyes up to the sound. I am very tempted to just order an animated halloween prop that seems to have most of what I want..but would need to disassemble the whole thing and cannabalized the animatronics. (lunging cemetary dog prop)
email me anytime with the list @ spyderskiss@gmail.com. <br>Thanks again for the help. I can't wait ti get started.
That would be so great. Any suggestions on where I could pick up the parts I would need? Then if you can show me how to wire it up I would be so grateful. I am just totally lost when it comes to this type of thing.

About This Instructable


402 favorites


Bio: I'm a former bicycle industry designer turned professional jeweler. I like working with my hands and am happiest when I'm in the shop ... More »
More by Honus: Science Fair Air Rockets DIY functional Sonic Screwdriver Rose cut natural raw Diamond ring
Add instructable to: