Laser Tag IR Capture the Base Game With Arduino

1,138

12

2

I made this to go along with some laser tag guns, but you can use any IR remote or other IR device.

Step 1: Decode the IR Signal

Things you will need for this step:

  1. Three (3) Male to male jumper wires
  2. Arduino Uno
  3. IR Receiver
  4. The IR library that can be found here

Software:

Download the library, copy the zipped file, and place it under your library folder in the following directory:

C:\Program Files (x86)\Arduino\libraries

In your IDE (where you write your code) go to Sketch/ Include library/ Add .ZIP library, and find the zipped file you just placed in the library folder.

After writing my own code, I found a demo for the library called, "IRrecvDemo" that can be found here you can us this demo to decode the IR signal.

Hardware:

  • Arduino Pin 11 to I on IR receiver(signal)
  • Arduino 5v pin to V on IR receiver(VCC)
  • Arduino ground to G on IR receiver (ground)

You may need to find the documentation for your IR receiver to insure the proper pin configuration.

upload the code to your board and open the serial monitor under the tools tab

Copy the codes that you receive.

Note: If you see FFFFFFFF, you are holding the button down and it indicates a continuance.

Step 2: Making the Connections.

Things you will need for this step:

  1. Arduino Micro
  2. LCD screen, I am using a 16x2
  3. Nineteen (19) male to male jumper wires
  4. Three (3) 250 ohm resistor
  5. One (1) red LED
  6. One (1) blue LED
  7. One (1) IR receiver

Arduino Connection:

Arduino 5V to + side of your bread board
Arduino Ground to - side of your Bread board

LCD Connections:

Ground to VSS (pin1) on LCD board,
5V to VDD (pin2) on LCD board,
Arduino pin 5 to VO (pin 3) on the LCD board,
Arduino pin 6 to pin RS (pin 4) on the LCD board,
Ground to RW (pin5) on LCD board,
Arduino pin 7 to pin E (pin 6) on the LCD board,
Pin 7 through pin 10 leave open
Arduino pin 8 to pin D4 (pin 11) on the LCD board,
Arduino pin 9 to pin D5 (pin 12) on the LCD board,
Arduino pin 10 to pin D6 (pin 13) on the LCD board,
Arduino pin 11 to pin D7 (pin 14) on the LCD board,
250 ohm resister from 5V to A (pin 15) on the LCD board, and
Ground to K (pin 16) on the LCD board.

LED connections:

Arduino Pin 2 to the anode ("positive" marked by the longer lead) of the Red LED
250 ohm resistor from Ground to cathode (negative" marked by the short lead) of the Red LED.
Arduino Pin 3 to the anode ("positive" marked by the longer lead) of the Blue LED
250 ohm resistor from Ground to cathode (negative" marked by the short lead) of the Blue LED.

IR receiver:

Arduino Pin 12 to I on IR receiver(signal)
Arduino 5v pin to V on IR receiver(VCC)
Arduino ground to G on IR receiver (ground)

You may need to find the documentation for your IR receiver to insure the proper pin configuration.

Step 3: Code:

I will be using millis() to turn off the LEDs after a set amount of time, using delay will stop the program from running until the time is up.

I use delay for the irrecv.resume(); to stabilize the loop.

//include the LiquidCrystal library see photo<br>#include <LiquidCrystal.h>
//include the IRemote library, this is not the IRrobotRemote that<br>//is installed when you install the Arduino IDE
#include <IRremote.h>
/* 
   Setting up the pins for the LCD, the following pins are for the Arduino Micro.
   Ground to VSS (pin1) on LCD board,
  5V to VDD (pin2) on LCD board,
  Arduino pin 5 to VO (pin 3) on the LCD board,
  Arduino pin 6 to pin RS (pin 4) on the LCD board,
  Ground to RW (pin1) on LCD board,
  Arduino pin 7 to pin E (pin 6) on the LCD board,
  Pin 7 through pin 10 leave open
  Arduino pin 8 to pin D4 (pin 11) on the LCD board,
  Arduino pin 9 to pin D5 (pin 12) on the LCD board,
  Arduino pin 10 to pin D6 (pin 13) on the LCD board,
  Arduino pin 11 to pin D7 (pin 14) on the LCD board,
  250 ohm resister from 5V to A (pin 15) on the LCD board, and
  Ground to K (pin 16) on the LCD board.
*/
LiquidCrystal lcd(6,7,8,9,10,11);
int RedP = 0; // RedP and BlueP are variables to keep count
int BlueP = 0;
int contrast = 100; //Defining contrast for LCD. 
int RledState = LOW; // This is a variable to set the state of the red LED, i.e. on or off (HIGH, or LOW)
int BledState = LOW; // This is a variable to set the state of the blue LED, i.e. on or off (HIGH, or LOW)
const int RedLed = 2; // Arduino Pin 2 to the anode("positive" marked by the longer lead) of the Red LED
const int BlueLed = 3; // Arduino Pin 3 to the anode("positive" marked by the longer lead) of the Blue LED 
const int RECV_PIN = 12; // Arduino pin 12 to data pin of ir receiver
const long interval = 3000; // Interval to turn the LEDs on and off in milliseconds 
unsigned long PrevMils = 0; // Will store the last time the LED was updated
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup() 
{
  lcd.begin(16,2); // Change this to the size of your LCD, the LCD I am using is 16x2
  lcd.clear(); // Clear screen
  pinMode(5, OUTPUT); // Setting contrast pin 5 to an output (Arduino Pin 5 to LCD board pin VO (pin 2)) 
  analogWrite(5, contrast); //Setting contrast
  pinMode(RedLed,OUTPUT);
  pinMode(BlueLed,OUTPUT);
  Serial.begin(10420); // Tell the Arduino to communicate with PCB
  irrecv.enableIRIn(); // Start the receiver
}
void loop() 
{
  /*
  I am using millis() to turn the LEDs off after a set time, if I used delay(3000)
  it would hold up the rest of the program for 3000 milliseconds (3 seconds).
  */
  unsigned long CurntMils = millis(); // Records the current time in milliseconds 
            if (CurntMils - PrevMils >= interval) 
            {     
              // Will check to see what LED is on, it will then turn the LED off
              if (BledState == HIGH) 
              {
                BledState = LOW;
              } 
              if (RledState == HIGH) 
              { 
                RledState = LOW;
              }                        
            }        
        digitalWrite(RedLed,RledState);
        digitalWrite(BlueLed,BledState);
  if (irrecv.decode(&results))
  {
      switch(results.value)
      {
        case 0x3D9AE3F7:
          RedP++;
          RledState = HIGH;
          BledState = LOW;          
          PrevMils = CurntMils; // This will save the last time you turned the LED on
          digitalWrite(RedLed,RledState);
        break;
  
        case 0x9716BE3F:
          BlueP++;
          BledState = HIGH;
          RledState = LOW;
          PrevMils = CurntMils; // This will save the last time you turned the LED on
          digitalWrite(BlueLed,BledState);
        break;
         
      }
                 
      lcd.setCursor(2,0); //Setting cursor
      lcd.clear(); //Clearing screen
      lcd.setCursor(2,0); //Setting cursor
      lcd.print("Red: "); //Printing text
      lcd.print(RedP);
      lcd.setCursor(2,1);
      lcd.print("Blue: ");
      lcd.print(BlueP);
      lcd.setCursor(1,0);  
      irrecv.resume();
      delay(100);
  }
}

Share

    Recommendations

    • Make it Glow Contest 2018

      Make it Glow Contest 2018
    • PCB Contest

      PCB Contest
    • Big and Small Contest

      Big and Small Contest

    2 Discussions

    0
    None
    band22DIY Hacks and How Tos

    Reply 10 months ago

    Thank you for your comment. I am brainstorming a larger project that will go along with this one. If or when it is completed, I will post it here. :0)