SALES INQUIRIES: 1 (888) 767-9864

Laser Tag and Arduino :: Student Project

It is great to take a fun game and add some twists.

Using an Arduino, James Greeve (a student of the Arduino Course for Absolute Beginners) created an “explosive” suite case fit for the movies.

James writes about the project:

“Earlier this year, I built some devices to be used in a Laser Tag game.

They had moderate success in the field.  The problem was to bring the players closer to the IR emitter.

The solution was a ARM / DISARM bomb scenario.

One team would take the bomb and place it down, enter a code and guard till detonation.  The other team would have to fight for control of the device, enter a special “dis-arm” code.”

Here is the Arduino code running on the project:

/* This is a Laser Tag suitcase bomb. 
In the begining, the referre will use his key to ARM the bomb then give it to one team.
They must place and start the countdown by entering a STARTCODE. 
The other team must find the bomb and enter a STOPCODE to stop the timer. 
If the time runs out, the bomb will detonate and emit the "explode player" IRcode.

By James Greeve
*/

// keypad library(s)
#include <Wire.h> 
#include "Adafruit_LEDBackpack.h"
#include "Adafruit_GFX.h"

// 7 segment display library(s)
Adafruit_7segment matrix = Adafruit_7segment();
#include "Arduino.h"
#include "Keypad.h"

// IR output pin
const int IRledPin = 10;

// the pre-programmed codes...
char* demoCode = "123A";
char* startCode = "1423"; // used to start countdown 
char* stopCode = "7891"; // used to stop countdown. Note: if this is changed beyond 4 digits, you must adjust the FOR loop statements
int currentPosition = 0; // this statement sets the inital position in the character array for key inputs
const int sound =12; // beeping sound (piezo buzzer)
const int redLeds =13; // red flashing leds (the 4 embedded in the plexiglass)

// the following is used to setup the numerical pad 
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins = {9, 8, 7, 6,}; //connect to the row pinouts of the keypad
byte colPins = {5, 4, 3, 2}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


void setup() {
  pinMode(IRledPin, OUTPUT);
  // the following is setting the 7 segment display to show all zeros at start
#ifndef __AVR_ATtiny85__
  Serial.begin(9600); // used during diagnosis of code
  #endif
  matrix.begin(0x70);
  matrix.drawColon(true); // turn to colon on display ON
  matrix.writeDigitNum(0,0); // for every position, set zero
  matrix.writeDigitNum(1,0);
  matrix.writeDigitNum(2,0);
  matrix.writeDigitNum(3,0);
  matrix.writeDigitNum(4,0);
  matrix.setBrightness(3); // brightness of display 0 being dark, 4 brightest
  matrix.writeDisplay(); // tell the display to WRITE
  pinMode(sound,OUTPUT);
  pinMode(redLeds, OUTPUT);
  digitalWrite(redLeds, LOW);
}  
  

void loop() {
  // tell the computer to look for a input on the numerical pad
  char key = keypad.getKey();
  // this NOT statement to avoid phantom inputs when no input being made on numerical pad
  if (int(key) != 0){
     if (key == startCode){  // Valid key in Password sequence
        ++currentPosition; // advanced the position in the array
        tone (12,2222,30); // make a sound everytime a key is pushed on keypad
        if (currentPosition == 4){ // if all 4 entries have been made move on...
        // launch the timer sub loop
        timer();
        currentPosition = 0;
        }
     } 
      else if(key == demoCode) {
        ++currentPosition; 
        tone (12,2222,30); // make a sound everytime a key is pushed on keypad
        if (currentPosition == 4){
        Demo();
        currentPosition = 0;
        }
       }
       else {
        longTimer();
        currentPosition = 0;
       }
      }
  }
  


void timer(){
   currentPosition = 0;
   for (uint16_t counter = 8715; counter > 0; counter--) { // the counter  is set to give approx 15 mins real time 
        tone(12,2222,30); // beeping sound as timer runs down
        matrix.println(counter);
        matrix.drawColon(true);
        matrix.writeDisplay();
        matrix.setBrightness(4);
        delay(100); // used to set time speed
        digitalWrite(redLeds, HIGH);
        // now while counting down, look to see if DISARM code has been entered correctly
        char key = keypad.getKey();
            if (int(key) != 0){
                if (key == stopCode){  
                ++currentPosition;
                tone (12,2222,30); // set the tone of the buzzer
                    if (currentPosition == 4){
                    // if yes, then break out of this loop and go back to main loop
                    break;
                    }
                } 
                else{
                currentPosition =0;
              }
            }     
   }
    // at the end of time display all zeros
    matrix.writeDigitNum(0,0);
    matrix.writeDigitNum(1,0);
    matrix.writeDigitNum(2,0);
    matrix.writeDigitNum(3,0);
    matrix.writeDigitNum(4,0);
    matrix.setBrightness(3); // brightness of display 0 being dark, 4 brightest
    matrix.writeDisplay(); // tell the display to WRITE
    
   // this is begining of laser command code to explode player
                  
            SendLaserCode();
  }


// this sub loop was added in case the wrong code was entered, resulting in a 10 min countdown
void longTimer(){
 currentPosition = 0;
   for (uint16_t counter = 5810; counter > 0; counter--) { // the counter 5810 is set to give approx 10 mins real time 
        tone(12,2222,30); // beeping sound as timer runs down
        matrix.println(counter);
        matrix.drawColon(true);
        matrix.writeDisplay();
        matrix.setBrightness(4);
        delay(100); // used to set time speed
        digitalWrite(redLeds, HIGH);
        // now while counting down, look to see if DISARM code has been entered correctly
        char key = keypad.getKey();
            if (int(key) != 0){
                if (key == stopCode){  
                ++currentPosition;
                tone (12,2222,30); // set the tone of the buzzer
                    if (currentPosition == 4){
                    // if yes, then break out of this loop and go back to main loop
                    break;
                    }
                } 
                else{
                currentPosition =0;
              }
            } 
   }
  // at the end of time display all zeros
    matrix.writeDigitNum(0,0);
    matrix.writeDigitNum(1,0);
    matrix.writeDigitNum(2,0);
    matrix.writeDigitNum(3,0);
    matrix.writeDigitNum(4,0);
    matrix.setBrightness(3); // brightness of display 0 being dark, 4 brightest
    matrix.writeDisplay(); // tell the display to WRITE
    
   // this is begining of laser command code to explode player
                  
            SendLaserCode();

}
// this is the sub routine for 10 second test
void Demo(){
  currentPosition = 0;
   for (uint16_t counter = 10; counter > 0; counter--) { // the counter 5810 is set to give approx 10 mins real time 
        tone(12,2222,30); // beeping sound as timer runs down
        matrix.println(counter);
        matrix.drawColon(true);
        matrix.writeDisplay();
        matrix.setBrightness(4);
        delay(100); // used to set time speed
        digitalWrite(redLeds, HIGH);
        // now while counting down, look to see if DISARM code has been entered correctly
        char key = keypad.getKey();
            if (int(key) != 0){
                if (key == stopCode){  
                ++currentPosition;
                tone (12,2222,30); // set the tone of the buzzer
                    if (currentPosition == 4){
                    // if yes, then break out of this loop and go back to main loop
                    break;
                    }
                } 
                else{
                currentPosition =0;
              }
            } 
   }
  // at the end of time display all zeros
    matrix.writeDigitNum(0,0);
    matrix.writeDigitNum(1,0);
    matrix.writeDigitNum(2,0);
    matrix.writeDigitNum(3,0);
    matrix.writeDigitNum(4,0);
    matrix.setBrightness(3); // brightness of display 0 being dark, 4 brightest
    matrix.writeDisplay(); // tell the display to WRITE
    
   // this is begining of laser command code to explode player
               
            SendLaserCode();
            


}   
// The following is copied from my original IR code

// this portion is needed to create the carrier frequency

void pulseIR(long microsecs){
                  while (microsecs > 0){
                  digitalWrite(IRledPin, HIGH);  // this takes about 3 microseconds to happen
                  delayMicroseconds(9);         // this is half the time T=1/f minus 3
                  digitalWrite(IRledPin, LOW);   // this also takes about 3 microseconds
                  delayMicroseconds(9);         // this is the other half
                  microsecs -= 26;
                   }
            }
     
// this is the actual IR codes being sent...
void SendLaserCode() {
  
  pulseIR(2350); // this is the HEADER
  delayMicroseconds(600);// the first gap between HEADER and actual code
    
  // 0x83, header info
  pulseIR(1000);  
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(1000);
  delayMicroseconds(850);
  // this is actual command to EXPLODE player
  pulseIR(1000); 
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(400); 
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(1000);
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(1000);
  delayMicroseconds(850);
  pulseIR(1000); 
   // 0xE8, footer info
  delayMicroseconds(850);
  pulseIR(1000);
  delayMicroseconds(850);
  pulseIR(1000);
  delayMicroseconds(850);
  pulseIR(1000);
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(1000);
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(400);
  delayMicroseconds(850);
  pulseIR(400);
}

 

I know James would love to hear any feedback, leave a comment and let him know your thoughts.

1 Comment

  1. […] example, James (a really quick study) who took the course has been making all types of cool Laser tag accessories using Arduino. Which is pretty awesome – and very […]

Leave a Comment