loading

Let's make a arduino battle tank with which you can play with your friends and learn a bit more of programming,arduino and electronics on the way.

Hope you'll enjoy this instructable!

Step 1: Stuff You'll Need!

1)arduino uno (and a mega too,discussed later in the project)

2)DC motors geared (you'll need 2 of them)

3)Lots of wires(male to male,male to female,female to female)

4)IR led (one)

5)IR receiver(tsop)

6)Servo (9g)

7)Foam board( :D)

8) Batteries and a battery holder (preferably a 12v,my local shop did not sell 12v so I had to use a 6v in series with 3v)

9)Arduino bluetooth module(HC-05)

10)H-Bridge(L293d or l293n,I reckon you go with a l293n as it can allow 1A rather than .5A in l293d(In short,lesser chances of burning your IC))

Step 2: Let's Make the Tracks!!

1)Cut out a 2cm(width) 20cm(length) piece of foam board(:D)

2)In the piece of foam board (:D)you just cut,make a mark a every centimeter.

3)using a box cutter or an exacto knife make shallow cuts on the foam board.The cuts shouldn't be too deep or else the foam board may snap.

TIP:Add a layer of clear tape behind the tracks for added support and lesser chance of snapping

4)Join the open ends using the clear tape and you are DONE!

5)Repeat this for the other track.

Step 3: The Main Body

There won't be any specific instructions on this because you'll have to design your own tank,that will be a lot more fun.

If your too lazy to design or lack time follow this,here you can look a different models and print them out and make the tank.

OR

If you want follow my design then follow these images(I still want to you to use your creativity and design your own tank)

Step 4: The Brains of Your Tank!

As the title already says,we'll be using an arduino to act as our brains for this project.

The bluetooth module acts as our "translator" between the phone and the arduino

FUN FACT:The history of Bluetooth. Harald Blåtand, or Bluetooth, was king of Denmark from about 940 until about 986. He is remembered for converting his country to Christianity and also for giving his name to the technology that enables wireless communication between devices.

you can read more about this here.

Step 5: The Wiring

1)Connect your IR led to pin 10 on the arduino. And the negative pin to the ground pins on the arduino

2)Connect your DC motors to the H-bridge(If you decide to use L293D then follow this).

Pin 2 of L293D to pin 3 of arduino

Pin 7 of L293D to pin 4 of arduino

Pin 10 of L293D to pin 6 of arduino

Pin 14 of L293D to pin 7 of arduino

3)connect the signal of the servo(usually orange wire)to pin 9 on the arduino

4)The Rx of bluetooth module to Tx of arduino and Tx of bluetooth module to Rx of arduino.(The most common place where people make mistake.Make sure you don't do it :D )

5)The IR receiver(the right most pin if the bumpy side is facing you) to pin 11 on the arduino.The middle pin to 5v and the leftmost pin is the ground.

6)Connect a Red (any color doesn't matter)led to pin 13 of arduino(the longer leg)and the other one to the ground.

Step 6: The Program!

The code is pretty simple.Try to read it once before copy pasting ;)

<p>#include<Servo.h><br></p><p> Servo servo;
 #include<IRremote.h></p><p>int IRpin = 8;  // pin for the IR sensor</p><p><br>int LED = 13;    // LED pin  
IRrecv irrecv(IRpin);
decode_results results;</p><p>boolean LEDon = true; // initializing LEDon as true
//L293 Connection   
  const int motorA1  = 3;  // Pin  2 of L293
  const int motorA2  = 4;  // Pin  7 of L293
  const int motorB1  = 6; // Pin 10 of L293
  const int motorB2  = 7;  // Pin 14 of L293</p><p>  const int BTState = 2;</p><p> 
//Useful Variables
  int i=0;
  int j=0;
  int state;
  int vSpeed=200;     // Default speed, from 0 to 255</p><p>void setup() {
    // Set pins as outputs:
    pinMode(motorA1, OUTPUT);
    pinMode(motorA2, OUTPUT);
    pinMode(motorB1, OUTPUT);
    pinMode(motorB2, OUTPUT);
//    pinMode(lights, OUTPUT); 
    pinMode(BTState, INPUT);    
    // Initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
      servo.attach(9);
    irrecv.enableIRIn(); // Start the receiver
  pinMode(LED, OUTPUT);
   pinMode(10, OUTPUT);
}
 
void loop() {
  //Stop car when connection lost or bluetooth disconnected
     if(digitalRead(BTState)=='S') { state='S'; }</p><p>  //Save income data to variable 'state'
    if(Serial.available() > 0){     
      state = Serial.read();   
    }
 
   if (state == '0'){
    servo.write(0);
    }
    else if(state == '1'){
      servo.write(18);
    }
    else if(state == '2'){
      servo.write(36);
    }
    else if(state == '3'){
      servo.write(54);
    }
    else if(state == '4'){
      servo.write(72);
    }
    else if(state == '5'){
      servo.write(90);
    }
    else if(state == '6'){
      servo.write(108);
    }
    else if(state == '7'){
      servo.write(126);
    }
    else if(state == '8'){
      servo.write(144);
    }
    else if(state == '9'){
      servo.write(162);
    }
    else if(state == 'q'){
      servo.write(180);
    }
 	  
  /***********************Forward****************************/
  //If state is equal with letter 'F', car will go forward!
    if (state == 'F') {
    	analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0);
        analogWrite(motorB1, vSpeed);      analogWrite(motorB2, 0); 
    }
  /**********************Forward Left************************/
  //If state is equal with letter 'G', car will go forward left
    else if (state == 'G') {
    	analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0);  
        analogWrite(motorB1, 200);    analogWrite(motorB2, 0); 
    }
  /**********************Forward Right************************/
  //If state is equal with letter 'I', car will go forward right
    else if (state == 'I') {
      	analogWrite(motorA1, vSpeed); analogWrite(motorA2, 0); 
        analogWrite(motorB1, 0);      analogWrite(motorB2, 200); 
    }
  /***********************Backward****************************/
  //If state is equal with letter 'B', car will go backward
    else if (state == 'B') {
    	analogWrite(motorA1, 0);   analogWrite(motorA2, vSpeed); 
        analogWrite(motorB1, 0);   analogWrite(motorB2, vSpeed); 
    }
  /**********************Backward Left************************/
  //If state is equal with letter 'H', car will go backward left
    else if (state == 'H') {
    	analogWrite(motorA1, 0);   analogWrite(motorA2, vSpeed); 
        analogWrite(motorB1, 200); analogWrite(motorB2, 0); 
    }
  /**********************Backward Right************************/
  //If state is equal with letter 'J', car will go backward right
    else if (state == 'J') {
    	analogWrite(motorA1, 0);   analogWrite(motorA2, vSpeed); 
        analogWrite(motorB1, 0);   analogWrite(motorB2, 200); 
    }
  /***************************Left*****************************/
  //If state is equal with letter 'L', wheels will turn left
    else if (state == 'L') {
    	analogWrite(motorA1, 0);   analogWrite(motorA2, 0); 
        analogWrite(motorB1, 200); analogWrite(motorB2, 0); 
    }
  /***************************Right*****************************/
  //If state is equal with letter 'R', wheels will turn right
    else if (state == 'R') {
    	analogWrite(motorA1, 0);   analogWrite(motorA2, 200); 
        analogWrite(motorB1, 0);   analogWrite(motorB2, 0); 		
    }
    else if(state == 'W'){
    digitalWrite(10,HIGH);
    delay(500);
    digitalWrite(10,LOW);
       }
else if(state == 'w'){
    digitalWrite(10,HIGH);
    delay(500);
    digitalWrite(10,LOW);</p><p>}
  /************************Stop*****************************/
  //If state is equal with letter 'S', stop the car
    else if (state == 'S'){
        analogWrite(motorA1, 0);  analogWrite(motorA2, 0); 
        analogWrite(motorB1, 0);  analogWrite(motorB2, 0);
    }
         
  if (irrecv.decode(&results)) 
    {
      
      irrecv.resume();   // Receive the next value
    }
  
   if (results.value == 0)  // change zero to your IR remote button number
     {
       if (LEDon == true)   // is LEDon equal to true? 
         {
           LEDon = false;   
           digitalWrite(LED, HIGH);
           delay(100);      // keeps the transistion smooth
            
         }
         
        else
          {
            LEDon = true;
            digitalWrite(LED, LOW);
            delay(100);
            
          }
          
     }
     
  </p><p>    }</p>

Step 7: How It Works!

Using the bluetooth you connect your tank to your phone and you friend does the same.

you can play with any number of friends with this Just make sure you change the code as needed.

Use this app and install it on your phone.

AND LET THE BATTLE BEGIN!

The way it works

You send the signal from your phone,blue tooth module receives the signal and sends it to the arduino.

the arduino corresponds these signals to the signal written in the code and magic happens!

when you fire a signal(IR) towards your opponent's tank the IR receiver....well ..receives (DUH!) and sends it to the arduino.The arduino uses this signal and a LED lights up on your opponents tank and you get to know that they have been hit.YOU WIN!

Step 8: Practice Mode!

Use the arduino(another one)(remember I mentioned this in the stuff you need? ;) )

connect the IR receiver to this arduino

connect this receiver to a small target(like the one they use for darts and archery)

Now connect this target to a servo

And you are done.

Heres the code:

<p>#include<IRremote.h> <irremote.h>      //must copy IRremote library to arduino libraries<br>#include <Servo.h><servo.h>
int RECV_PIN = 2;       //IR receiver pin
Servo servo;

IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // Start the receiver
  servo.attach(9);     //servo pin
}
void loop() 
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    irrecv.resume(); // Receive the next value
    if (results.value == 0000) //replace zeros with the your IR led signal
    {
    servo.Write(0);</servo.h></irremote.h></p><p style="margin-left: 20px;"><irremote.h><servo.h>delay(5000); //5 sec delay</servo.h></irremote.h></p><p style="margin-left: 20px;">servo.Write(90);</p><p style="margin-left: 20px;">  }</p><p><irremote.h><servo.h>
}</servo.h></irremote.h></p>

Step 9: Thank You

If you made it this far CONGRATULATIONS!

I would love to see your tanks as well!

<p>how much is the cost of the materials?</p>
<p>Fun tank. I like how you made your own treads.</p>
<p>Thanks! :)</p>

About This Instructable

474views

6favorites

License:

More by FoamBoard:Arduino Battle Tank! 
Add instructable to: