Infrared Fighting Tank

26,383

433

17

Posted

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.

Share

Recommendations

  • Epilog Challenge 9

    Epilog Challenge 9
  • Sew Warm Contest 2018

    Sew Warm Contest 2018
  • Gluten Free Challenge

    Gluten Free Challenge
user

We have a be nice policy.
Please be positive and constructive.

Tips

Questions

15 Comments

Its engineering + fun ..... thats awesome

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 !

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.

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

other than that it is cool

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

it has to be too fun to play

WOOW! Amazing job!

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