Introduction: Arduino Avengers: Laser Tag

Have you ever wanted to become a superhero? This Arduino Laser tag project immerses you in game where you can act as a superhero firing at your opponents to victory.

Using a flex sensor, you can reenact the famous Spiderman web shooter and Iron Man repulsor beam. You are also able to keep track of your ammunition and life count on the LCD screen on your wrist. Every time you’re hit, you can feel the impact through a vibration motor. When you win, the speaker will play your theme song.


This project won best laser tag project (out of 12) at Binghamton University's Freshman Engineering Design Arduino Exposition.

Step 1: Parts

Everything but the tools were bought on Amazon and the total project was $140 (Arduinos were knockoffs).

Electronics

  • Arduino Uno (x2)
  • Protoboard (x2)
  • Flex Sensor (x2)
  • I2C LCD Display (x2)
  • IR Emitter (x2)
  • IR Receiver (x4) - 3 prong NOT 2 prong
  • Vibration Motor (x2)
  • Enclosed Piezo (x2)

Costume

  1. Spiderman Shirt
  2. Spiderman Mask
  3. Spiderman Gloves
  4. Iron Man Shirt
  5. Iron Man Mask
  6. Iron Man Gloves

Other

  • Arduino Housing (x2)
  • Latex Gloves
  • Lots of wire

Tools

  • Soldering iron and solder
  • Breadboard and Jumper Wires for prototyping
  • Wire Strippers

Step 2: Prototyping

Picture of Prototyping

I would suggest first testing each component (Piezo, Flex Sensor, LCD, Vibration IR Emitter and Receiver) separately before you begin. There's plenty of sample code all over the internet to test each.

Wire everything to the breadboard as you see in the diagram above.

Note:

  • The I2C LCD only has 4 pins, so wire accordingly
  • The vibration motor has a 3V max, so wire it to the 3V pin and ground it to pin 13 (this means the code to control it is reversed)
  • The flex sensor is denoted as a potentiometer in the schematic

Here's a link to the circuits.io schematic.

Step 3: Code

Codebender Link

#include <IRremote.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include "pitches.h"

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

int RECV_PIN = 11;
int RECV_PIN2 = 10;
IRrecv irrecv(RECV_PIN);
IRrecv irrecv2(RECV_PIN2);
decode_results results;
IRsend irsend;

const int flexSensor = A0;
int lastFlexNum = 0;
int lives = 5;
int ammo = 50;

int buzzerPin = 13;

String superhero = "Spiderman";
//String superhero = "Iron Man";

void setup(){
    digitalWrite(buzzerPin, HIGH);
    pinMode(buzzerPin,OUTPUT);
    
	irrecv.enableIRIn();
	irrecv2.enableIRIn();
	
  	lcd.begin(16,2);
	lcd.backlight();
    lcd.clear();
    updateLCD();
    
    Serial.begin(9600);
}

void loop(){
	int flexVal = analogRead(flexSensor);
	if((lastFlexNum>350)&&((flexVal>100)&&(flexVal<350))){
		if(ammo>0){
			irsend.sendSony(0xa90, 12);
			
			irrecv.enableIRIn();
			irrecv2.enableIRIn();
			
			ammo = ammo - 1;
			updateLCD();
			delay(3000);
		}
	}
	lastFlexNum = flexVal;
	
    if (irrecv.decode(&results)) {
    	if ((results.value == 4045713590)||(results.value == 316007967)||(results.value == 2704)){
    		lives = lives - 1;
    		
    		lcd.setCursor(0,1);
  			lcd.print("                ");
  			lcd.setCursor(1,1);
  			lcd.print(">Front Shot<");
  		
    		digitalWrite(buzzerPin, LOW);
    		delay(2000);
    		digitalWrite(buzzerPin, HIGH);
    		updateLCD();
    	}
    	irrecv.resume(); // Receive the next value
    }
    if (irrecv2.decode(&results)) {
    	if ((results.value == 4045713590)||(results.value == 316007967)||(results.value == 2704)){
    		lives = lives - 1;
    		
    		lcd.setCursor(0,1);
  			lcd.print("                ");
  			lcd.setCursor(1,1);
  			lcd.print(">Back Shot<");
    		
    		digitalWrite(buzzerPin, LOW);
    		delay(2000);
    		digitalWrite(buzzerPin, HIGH);
    		updateLCD();
    	}
    	irrecv2.resume(); // Receive the next value
    }
    
    delay(100);
}

void updateLCD(){
    lcd.clear();
	if(superhero == "Spiderman"){
		lcd.setCursor(4,0);
		lcd.print("Spiderman");
	}
	else{
		lcd.setCursor(4,0);
		lcd.print("Iron Man");
	}
	
  	if (lives == 0){
  		lcd.setCursor(2,1);
  		lcd.print("You Died :(");
  		
  		playMusic();
  		
  		lcd.setCursor(0,1);
  		lcd.print("                ");
  		lives = 5;
  	}
	
  	lcd.setCursor(0,1);
  	lcd.print("Lives:");
  	lcd.setCursor(6,1);
  	lcd.print(lives);
    lcd.setCursor(9,1);
  	lcd.print("Ammo:");
  	lcd.setCursor(14,1);
  	lcd.print(ammo);
}

void playMusic(){
	if(superhero == "Spiderman"){
		int melody[] = {NOTE_D4, NOTE_F4, NOTE_A4, 0, NOTE_GS4, NOTE_F4, NOTE_D4, 0, NOTE_D4, NOTE_F4, NOTE_A4, NOTE_A4, NOTE_GS4, NOTE_F4, NOTE_D4,0, NOTE_G4, NOTE_AS4, NOTE_D5, 0, NOTE_C5, NOTE_AS4, NOTE_G4, 0, NOTE_D4, NOTE_F4, NOTE_A4, 0, NOTE_GS4, NOTE_F4, NOTE_D4, NOTE_AS4, NOTE_G4, NOTE_G4, NOTE_F4, NOTE_G4, NOTE_F4, NOTE_D4};
		int noteDurations[] = {4, 8, 4, 4, 4, 8, 4, 4, 4, 8, 4, 4, 4, 8, 4, 4, 4, 8, 4, 4, 4, 8, 4, 4, 4, 8, 4, 4, 4, 8, 4, 8, 2, 4, 6, 4, 6, 2};
		
		for (int thisNote = 0; thisNote < 38; thisNote++) {
			int noteDuration = 1200 / noteDurations[thisNote];
			tone(8, melody[thisNote], noteDuration);
			int pauseBetweenNotes = noteDuration * 1.30;
			delay(pauseBetweenNotes);
			noTone(8);
		}
	}
	else{
		int melody[] = {NOTE_B3, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_G4, NOTE_FS4, NOTE_G4, NOTE_FS4, NOTE_G4, NOTE_D4, NOTE_D4, NOTE_E4, NOTE_E4, NOTE_B5, NOTE_D5, NOTE_D5, NOTE_E5, NOTE_E5, NOTE_G5, NOTE_FS5, NOTE_G5, NOTE_FS5, NOTE_G5, NOTE_D5, NOTE_D5, NOTE_E5, NOTE_E5};
		int noteDurations[] = {4, 4, 8, 8, 4, 16, 16, 16, 16, 8, 8, 8, 8, 4, 4, 4, 8, 8, 4, 16, 16, 16, 16, 8, 8, 8, 8, 4};
		
		for (int thisNote = 0; thisNote < 29; thisNote++) {
			int noteDuration = 1200 / noteDurations[thisNote];
			tone(8, melody[thisNote], noteDuration);
			int pauseBetweenNotes = noteDuration * 1.30;
			delay(pauseBetweenNotes);
			noTone(8);
		}
	}
}

Step 4: Soldering

Picture of Soldering

Solder wires and components to a protoboard the same way you did with a breadboard. This makes your project compact and ensures that all the wires stay connected.

Step 5: Build Housing and Attach to Costume

Picture of Build Housing and Attach to Costume
  • Enclose the Arduino in a box or some sort of casing (it can be as simple as a decorated envelope which is what was used in this project)
  • Attach a battery pack to the side which will also act as the Arduino power button.
  • Sew the LCD to Latex glove and wire it to the Arduino
  • Put the superhero glove over the latex glove and put on the rest of the costume
  • Wire the IR emitter to the bottom of the superhero glove (to aim and shoot IR beam)
  • Wire the IR receivers through the costume (one to front and one to back)

Step 6: Playing Instructions

Picture of Playing Instructions

You're all done!!

  • The goal of the game is to hit the other player’s sensor 5 times
  • When a person wants to fire a shot, they must bend the flex sensor which causes the IR emitter to send a signal
  • Players must aim the emitter at the receivers embedded within their opponent’s shirt
  • Each time a person is hit, their life count decreases by one
  • The game continues until one person has lost all of their lives (their super hero’s theme song will play indicating they lost)

Comments

DavidG626 (author)2017-02-06

Forgive me if this is a dumb question. But, would I be able to have for example, two spiderman and two iron man all play each other? Two players is fun. But four is better =)

jacobrichman (author)DavidG6262017-02-06

Yes. Very easy to do. In the code there's a variable at the beginning that you either set to "Superman" or "Iron Man." All you have to do is change it for each Arduino. This has no affect on the actual game. It just sets the name on the LCD and it dictates what music will play.

DanielB694 (author)2016-12-23

What libraries are needed for this? I am getting compliing errors. Seems like a great project.

jacobrichman (author)DanielB6942016-12-27

I struggled a lot with the libraries for this project and that's why I strongly suggest that you use Codebender to run the code with my included custom libraries.

1. The IR remote library needs to be modified so that pin 3 is used to send signals instead of pin 9 (which conflicts with the Piezo speaker). There's more information here: https://forum.arduino.cc/index.php?topic=120955.0

2. Make sure that you have the right I2C library because there's so many different versions that each work with different models.

knottd0506 (author)2016-10-29

Are you able to place the script online too?

jacobrichman (author)knottd05062016-10-29

I completely forgot to do that. So sorry

knottd0506 (author)jacobrichman2016-10-29

Legend---wait for it---ary!!

Cheers

About This Instructable

964views

20favorites

License:

More by jacobrichman:Arduino Avengers: Laser TagMaking a Soldering StationRestoring Old Fire Alarm Bell
Add instructable to: