Introduction: Infrared Fighting Tank

This project is to make two infrared fighting tanks with Starter Robot Kits, some mechanical parts and electric modules. They are controlled with 2.4G wireless joystick. So, how to make it?

BUY NOW

Step 1: Parts Required

Step 2: Assemble the Tank

Follow the instructions of Starter Robot Kit user manual to assemble the tank.

Assemble the tank gun with following parts:

Beam0808-136-Blue x 2

Beam0824-032-Blue x 1

Beam0808-024-Blue x 1

Socket Cap Screw M4x22-Button Head x 2

Socket Cap Screw M4x14-Button Head x 4

Nut 4mm x 2

Attach Beam0808-312 at the end of tank and install electronic modules.

Step 3: Soldering and Wiring

Solder a infrared transmitter with infrared LED, 330 Ω resistor and dupont wires. Wrap it with electric tape. Connect anode and cathode of infrared LED with black cable and red cable of dupont wire, respectively.

Connect electric modules with Orion board via RJ25 cables as follows:

Infrared transmitter: Port 2

Me RGB LED: Port 3

Me 7-Segment Serial Display: Port 4

Me Infrared Receiver Decode: Port 5

Me USB Host: Port 6

Me RJ25 Adapter: Port 7

LED RGB Strip: Me RJ25 Adapter Slot 2

Fix infrared transmitter with tape.

Step 4: Programing

Download Makeblock library and put it under Arduino libraries. The Arduino source code for infrared fighting tank is as follows:

#include "MeOrion.h"
#include <SoftwareSerial.h> #include "MeIR.h"
MeIR irsend;
MeDCMotor MotorL(M1);  
MeDCMotor MotorR(M2);
MeRGBLed ledBottom(PORT_3);
Me7SegmentDisplay disp(PORT_4);
MeInfraredReceiver infraredReceiverDecode(PORT_5);
MeUSBHost joypad(PORT_6);
//  Corresponding buffer data of keys on the Joystick
//  Default:128-127-128-127-15-0-0-128
//  L1:128-127-128-127-15-1-0-128
//  R1:128-127-128-127-15-2-0-128
//  L2:128-127-128-127-15-4-0-128
//  R2:128-127-128-127-15-8-0-128
//  Triangle key:128-127-128-127-31-0-0-128 (0001 1111)
//  Square key:128-127-128-127-143-0-0-128 (1000 1111)
//  X key:128-127-128-127-79-0-0-128 (0100 1111)
//  Circle key:128-127-128-127-47-0-0-128 (0010 1111)
//  Up:128-127-128-127-0-0-0-128 (0000 0000)
//  Down:128-127-128-127-4-0-0-128 (0000 0100)
//  Left:128-127-128-127-6-0-0-128 (0000 0110)
//  Right:128-127-128-127-2-0-0-128 (0000 0010)
//  Select:128-127-128-127-15-16-0-128
//  Start:128-127-128-127-15-32-0-128
//  Joystick:Right X-Right Y-Left X-Left Y-15-0-0-128
MeRGBLed ledTop(PORT_7, SLOT2, 15);
int moveSpeed = 200;
uint8_t ReceiverCode;
int bulletNumber = 16;
int khz = 38; // 38kHz carrier frequency for the NEC protocol
float lifeValue = 8;
boolean gotShootIndex = 1;
void setup()
{
  infraredReceiverDecode.begin();
  Serial.println("InfraredReceiverDecode Start!");
  Serial.begin(9600);
  joypad.init(USB1_0);
  disp.display(bulletNumber);
  displayLifeValue();
  int delayTime = 360;
  for (uint8_t t = 0; t < 16; t++) // blink led
  {
    ledBottom.setColor(200,0,0); // led on
    ledBottom.show();
    delay(delayTime);
    ledBottom.setColor(0,0,0); // led off
    ledBottom.show();
    delay(delayTime);
    delayTime -= 20;
  }
}
void shoot() { // shoot, bullet number -1
  bulletNumber -= 1;
  if(bulletNumber>=0) {
    unsigned int irSignal[] = {9000, 4500, 560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 560, 560, 560, 560, 560, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 560, 560, 1690, 560, 1690, 560, 1690, 560, 1690, 560, 39416, 9000, 2210, 560}; //AnalysIR Batch Export (IRremote) - RAW  
    irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz); // send ir signal
    ledBottom.setColor(0,0,200);
    ledBottom.show();
    Backward();
    buzzerOn();
    delay(100);
    Stop();
    Forward();
    delay(80);
    ledBottom.setColor(0,0,0);
    ledBottom.show();
    Stop();
    buzzerOff();    
  } else {
    bulletNumber=0;
  }
  disp.display(bulletNumber);
}
void gotShoot() {
  Serial.println(ReceiverCode);
  if(ReceiverCode == 0x08) {
    Serial.println("got shoot");
    
    lifeValue -= 0.5;
    if(lifeValue<0) {
      lifeValue = 0;
      
    }
    ledTop.setColorAt(lifeValue, 0, 0, 0);
    ledTop.show();
    if(gotShootIndex){
      ledBottom.setColor(200,0,0); // backward and flash red led
      ledBottom.show();
      Backward();
      delay(100);
      ledBottom.setColor(0,0,0);
      ledBottom.show();
      Stop();      
    }
    gotShootIndex = !gotShootIndex;
  }  
}
void displayLifeValue() {
   lifeValue = 8;
   for(int8_t t=0; t<lifeValue; t++) { // light led
     ledTop.setColorAt(t, 200,0,0);
     ledTop.show();
     delay(150);
   }
}
void loop()
{
  if(infraredReceiverDecode.available()) {
    ReceiverCode = infraredReceiverDecode.read();
    gotShoot();
  }
  if(!joypad.device_online) {
    joypad.probeDevice();
    delay(1000);
  } else {
    int len = joypad.host_recv();
    parseJoystick(joypad.RECV_BUFFER);
    delay(5);
  }
}
void parseJoystick(unsigned char *buf)   //Analytic function, print 8 bytes from USB Host
{
    //  print buffer data to debug
    // int i = 0;
    // for(i = 0; i < 7; i++)
    // {
    //     Serial.print(buf[i]);  
    //     Serial.print('-');
    // }
    // Serial.println(buf[7]);
    // delay(10);
    switch (buf[5])
    {
        case 1: // L1   reset life value
            displayLifeValue();           
            break;
        case 2: // R1  reset bullet number
            bulletNumber = 16;
            disp.display(bulletNumber);           
            break;
        case 4: // L2
            
            break;
        case 8: // R2
           
            break;
        default:
            break;
    }
    
    if ((128 != buf[0]) || (127 != buf[1]) || (128 != buf[2]) || (127 != buf[3]))
    {
        //  buf[0]-buf[3] corresponding to the left and right joystick
    }
    else
    {
        switch (buf[4])
        {
            case 79: // X
                Stop();
                break;
            case 0: // up
                Forward();
                break;
            case 4: // down
                Backward();
                break;
            case 6: // left
                TurnLeft();
                break;
            case 2: // right
                TurnRight();
                break;
            case 143: // square key
                break;
             case 31: // triangle key
                shoot();                
                break;
             case 47: // circle key
                
                break;                              
            default:
                Stop();
                break;
        }
    }
}
void Forward()
{
  MotorL.run(-moveSpeed);
  MotorR.run(moveSpeed);
}
void Backward()
{
  MotorL.run(moveSpeed);
  MotorR.run(-moveSpeed);
}
void TurnLeft()
{
  MotorL.run(moveSpeed);
  MotorR.run(moveSpeed);
}
void TurnRight()
{
  MotorL.run(-moveSpeed);
  MotorR.run(-moveSpeed);
}
void Stop()
{
  MotorL.run(0);
  MotorR.run(0);
}

Step 5: Upload Code and Fire

Follow the above steps to make another tank, upload code to Orion board with Arduino IDE, plug usb module into Me USB Host, connect joystick with tank, you're ready to fire and have fun.

Comments

author
laith+mohamed made it!(author)2016-03-16

Its engineering + fun ..... thats awesome

author
Eugene_Liu made it!(author)2016-03-06

Bro, this is one of most exciting project I even see here. I love. Just few quick thoughts: 1. could you let code to control one of the tank to fight with another one ? 2. further more, could these 2 tanks fight remotely through internet ? 3. maybe there is competition ?

Great work !

author
Makeblock+Robotics made it!(author)2016-03-08

Thanks for your advice. The tank gets shot if its infrared receiver module receive IR signal from another tank. Fighting remotely through internet is really cool. More work need to be done, like adding wifi module.

author
I-robostein made it!(author)2016-03-06

Amazing!!!!! but as the others... what is the effective range

other than that it is cool

author
Makeblock+Robotics made it!(author)2016-03-08

Do you mean the shooting range? They work fine within 1.5m.

author
Jonathanrjpereira made it!(author)2016-02-06

are those 2 PS3 controllers?

author
Makeblock+Robotics made it!(author)2016-02-09

No, they are ordinary 2.4G wireless Joysticks.

author
alpersunter made it!(author)2016-02-06

it has to be too fun to play

author
Imetomi made it!(author)2016-02-01

WOOW! Amazing job!

author
Alexander+heron+the+inventor made it!(author)2016-02-04

damn it bro,you didn't reply again,i failed again with your voice controlled drone.Btw i made my own instructables.Btw this project is wicked,you should make a drone laser tag

author
Srijal97 made it!(author)2016-02-01

Awesome! love the recoil!

What is the effective range?

author
Makeblock+Robotics made it!(author)2016-02-02

Thanks, they work fine within 1.5m.

author
Morealin made it!(author)2016-02-01

Really cool! What is the effective "shooting" range of the tanks ?

author
Makeblock+Robotics made it!(author)2016-02-02

They work fine within 1.5m.

author
Jedi_zombie85 made it!(author)2016-02-01

hahaha amazing

About This Instructable

26,124views

433favorites

License:

Bio: Makeblock was founded in 2012 as the world's first open-source robot and programing platform. With more than 400 mechanical components, electronic modules, and software ... More »
More by Makeblock Robotics:How to Use Scratch or Arduino to Program a MBot 3D Capture B by Makeblock How to do a cartoon project with Airblock and paper cups
Add instructable to: