author
14Comments

Tell us about yourself!

  • Klebers8 commented on j44's instructable Arduino Laser Tag - Duino Tag1 year ago
    Arduino Laser Tag - Duino Tag

    All my guns use arduino nano.

    View Instructable »
  • Klebers8 commented on j44's instructable Arduino Laser Tag - Duino Tag1 year ago
    Arduino Laser Tag - Duino Tag

    You need to use IRremote library 1.0. If you use another version of the library, it doesnt work.

    View Instructable »
  • Klebers8 commented on j44's instructable Arduino Laser Tag - Duino Tag1 year ago
    Arduino Laser Tag - Duino Tag

    //the last code that i use// changelog//23/07/2018//fixed support to recoil frag grenade//17/07/2018//add support to recoil frag grenade//27/12/2017//corrigido o envio de rf para não enviar mais de uma vez.//26/12/2017//alterado o pino de RF para A0/*11/12/2017 foi decodificado o sinal enviado pelo IR de acordo com o time e/ou jogar codigos:enviado TIME jOGADOR2399713221 1 52385866694 1 42490605183 1 34195798586 1 21807987366 1 1 2103698458 0 51232964497 0 4 3111617568 0 3521843677 0 2 1517537329 0 1Recoil Frag Grenade 1783582990*///10/12/2017 adicionado suporte a rf através da biblioteca rc-switch//toda vez que toma um tiro, envia por rf de quem tomou o tiro//02/12/20017//c...

    see more »

    //the last code that i use// changelog//23/07/2018//fixed support to recoil frag grenade//17/07/2018//add support to recoil frag grenade//27/12/2017//corrigido o envio de rf para não enviar mais de uma vez.//26/12/2017//alterado o pino de RF para A0/*11/12/2017 foi decodificado o sinal enviado pelo IR de acordo com o time e/ou jogar codigos:enviado TIME jOGADOR2399713221 1 52385866694 1 42490605183 1 34195798586 1 21807987366 1 1 2103698458 0 51232964497 0 4 3111617568 0 3521843677 0 2 1517537329 0 1Recoil Frag Grenade 1783582990*///10/12/2017 adicionado suporte a rf através da biblioteca rc-switch//toda vez que toma um tiro, envia por rf de quem tomou o tiro//02/12/20017//corrigido o problema dos leds que exibem a munição. um pino (9) foi usado para o dfplayer, assim sao tres pinos atualmente para munição//01/12/2017//adicionado suporte ao dfplayer necessario 4 arquivos no cartao//26/11/2017// removido o barulho de tiro do speaker pin//16/11/2017// adicionado um digital write low no led team pin caso alguem morra e o flair esteja ligado.// mp3 player para o tiro deve ser ligado em paralelo com o pino do muzzle flair no pino 11 do dfplayer mini (IO 2)// -------------------------------// Start of code (copy and paste into arduino sketch)//// Duino Tag release V1.01// Laser Tag for the arduino based on the Miles Tag Protocol.// By J44industries: www.J44industries.blogspot.com// For information on building your own Duino Tagger go to: https://www.instructables.com/member/j44///// Much credit deserves to go to Duane O'Brien if it had not been for the excellent Duino Tag tutorials he wrote I would have never been able to write this code.// Duane's tutorials are highly recommended reading in order to gain a better understanding of the arduino and IR communication. See his site http://aterribleidea.com/duino-tag-resources///// This code sets out the basics for arduino based laser tag system and tries to stick to the miles tag protocol where possible.// Miles Tag details: http://www.lasertagparts.com/mtdesign.htm// There is much scope for expanding the capabilities of this system, and hopefully the game will continue to evolve for some time to come.// Licence: Attribution Share Alike: Give credit where credit is due, but you can do what you like with the code.// If you have code improvements or additions please go to http://duinotag.blogspot.com//#include <IRremote.h>//*******************************************codigo df player#include "Arduino.h"#include "SoftwareSerial.h"#include "DFRobotDFPlayerMini.h"byte piezo=0; // variavel que habilita o piezo caso o dfplayer não funcione no setupSoftwareSerial mySoftwareSerial(3, 9); // RX, TXDFRobotDFPlayerMini myDFPlayer;void printDetail(uint8_t type, int value);//*******************************************codigo df player//-----------------------------------------codigo RF#include <RCSwitch.h>RCSwitch mySwitch = RCSwitch();//-----------------------------------------codigo RF// Digital IO's//int lifePin = ; // An analogue output (PWM) level corresponds to remaining life. Use PWM pin: 3,5,6,9,10 or 11. Can be used to drive LED bar graphs. eg LM3914N//int ammoPin = ; // An analogue output (PWM) level corresponds to remaining ammunition. Use PWM pin: 3,5,6,9,10 or 11.//int trigger2Pin = ; // Push button for secondary fire. Low = pressed//int IRtransmit2Pin = 8; // Secondary fire mode IR transmitter pin: Use pins 2,4,7,8,12 or 13. DO NOT USE PWM pins!!int IRreceive2Pin = 99; // Allows for checking external sensors are attached as well as distinguishing between sensor locations (eg spotting head shots)//int audioPin = 9; // Audio Trigger. Can be used to set off sounds recorded in the kind of electronics you can get in greetings card that play a custom message.int x=0;//const byte led1 = 9; // os leds do pino 10 e nove estao ligados em paralelo devido ao pino 9ser utilizado pelo df playerconst byte led2 = 10;const byte led3 = 11;const byte led4 = 12;const byte teamPin = 3; //if you hold trigger when start, you ll be team 2 , led red onint triggerPin = 4; // teste correto 4 // Push button for primary fire. Low = pressedint speakerPin = 5; // Direct output to piezo sounder/speakerint hitPin = 13; // LED output pin used to indicate when the player has been hit.int IRtransmitPin = 7; // Primary fire mode IR transmitter pin: Use pins 2,4,7,8,12 or 13. DO NOT USE PWM pins!! More info: http://j44industries.blogspot.com/2009/09/arduino-frequency-generation.html#moreint IRreceivePin = 6;int recarga = 8; // teste correto 8String recebido="0";// The pin that incoming IR signals are read from// Minimum gun requirements: trigger, receiver, IR led, hit LED.int ledTeamPin =2; // utilizado para o flare da arma. piscar quando atira// Player and Game detailsint myTeamID = 0; // 1-7 (0 = system message) //0 red team - 1 blue teamint myPlayerID = 1; // Player IDint myGameID = 0; // Interprited by configureGane subroutine; allows for quick change of game types.int myWeaponID = 0; // Deffined by gameType and configureGame subroutine.int myWeaponHP = 0; // Deffined by gameType and configureGame subroutine.int maxAmmo = 0; // Deffined by gameType and configureGame subroutine.int maxLife = 0; // Deffined by gameType and configureGame subroutine.int automatic = 0; // Deffined by gameType and configureGame subroutine. Automatic fire 0 = Semi Auto, 1 = Fully Auto.int automatic2 = 0; // Deffined by gameType and configureGame subroutine. Secondary fire auto?int registroRF =0; // variável que envia por rf quem acertou (unidade), quem levou o tiro (dezena) e qual o time que acertou - time do atacante (centena) //Incoming signal Detailsint received[18]; // Received data: received[0] = which sensor, received[1] - [17] byte1 byte2 parity (Miles Tag structure)int check = 0; // Variable used in parity checking// Statsint ammo = 0; // Current ammunitionint life = 0; // Current life// Code Variablesint timeOut = 0; // Deffined in frequencyCalculations (IRpulse + 50)int FIRE = 0; // 0 = don't fire, 1 = Primary Fire, 2 = Secondary Fireint TR = 0; // Trigger Readingint LTR = 0; // Last Trigger Readingint T2R = 0; // Trigger 2 Reading (For secondary fire)int LT2R = 0; // Last Trigger 2 Reading (For secondary fire)int Trecarga=0;float ultimaRecarga=0;// Signal Propertiesint IRpulse = 600; // Basic pulse duration of 600uS MilesTag standard 4*IRpulse for header bit, 2*IRpulse for 1, 1*IRpulse for 0.int IRfrequency = 38; // Frequency in kHz Standard values are: 38kHz, 40kHz. Choose dependant on your receiver characteristicsint IRt = 0; // LED on time to give correct transmission frequency, calculated in setup.int IRpulses = 0; // Number of oscillations needed to make a full IRpulse, calculated in setup.int header = 4; // Header lenght in pulses. 4 = Miles tag standardint maxSPS = 10; // Maximum Shots Per Seconds. Not yet used.int TBS = 270; // Time between shots. Not yet used.float ultimoTiro =0;// Transmission dataint byte1[8]; // String for storing byte1 of the data which gets transmitted when the player fires.int byte2[8]; // String for storing byte1 of the data which gets transmitted when the player fires.int myParity = 0; // String for storing parity of the data which gets transmitted when the player fires.// Received dataint memory = 10; // Number of signals to be recorded: Allows for the game data to be reviewed after the game, no provision for transmitting / accessing it yet though.int hitNo = 0; // Hit number// Byte1int player[10]; // Array must be as large as memoryint team[10]; // Array must be as large as memory// Byte2int weapon[10]; // Array must be as large as memoryint hp[10]; // Array must be as large as memoryint parity[10]; // Array must be as large as memorybyte enviouRF = 0; // variavel usada para que o codigo rf seja enviado uma única vez //IRIRrecv irrecv(IRreceivePin);decode_results results;//IRvoid setup() { // Serial coms set up to help with debugging. //*******************************************codigo df playermySoftwareSerial.begin(9600); Serial.begin(115200); Serial.println(); Serial.println(F("DFRobot DFPlayer Mini Demo")); Serial.println(F("Initializing DFPlayer ... (May take 3~5 seconds)")); if (!myDFPlayer.begin(mySoftwareSerial)) { //Use softwareSerial to communicate with mp3. Serial.println(F("Unable to begin:")); Serial.println(F("1.Please recheck the connection!")); Serial.println(F("2.Please insert the SD card!")); // while(true); Serial.println(F("Habilitando piezo")); piezo=1; } Serial.println(F("DFPlayer Mini online.")); myDFPlayer.volume(30); //Set volume value. From 0 to 30//*******************************************codigo df player//-----------------------------------------codigo RF mySwitch.enableTransmit(A0);//-----------------------------------------codigo RF //Serial.begin(9600); Serial.println("Startup..."); irrecv.enableIRIn(); // Start the receiver // Pin declarations //pinMode(audioPin, OUTPUT); //pinMode(trigger2Pin, INPUT); //pinMode(IRreceive2Pin, INPUT); //pinMode(IRtransmit2Pin, OUTPUT); //pinMode(lifePin, OUTPUT); //pinMode(ammoPin, OUTPUT); pinMode(triggerPin, INPUT); pinMode(speakerPin, OUTPUT); pinMode(recarga, INPUT); pinMode(hitPin, OUTPUT); pinMode(IRtransmitPin, OUTPUT); pinMode(IRreceivePin, INPUT); //pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(teamPin, INPUT); digitalWrite(teamPin, LOW); pinMode(ledTeamPin, OUTPUT); digitalWrite(ledTeamPin, LOW); digitalWrite(triggerPin, HIGH); // Not really needed if your circuit has the correct pull up resistors already but doesn't harm// digitalWrite(trigger2Pin, HIGH); // Not really needed if your circuit has the correct pull up resistors already but doesn't harm digitalWrite(recarga, HIGH); frequencyCalculations(); // Calculates pulse lengths etc for desired frequency configureGame(); // Look up and configure game details tagCode(); // Based on game details etc works out the data that will be transmitted when a shot is fired for (int i = 1;i < 254;i++) { // Loop plays start up noise //analogWrite(ammoPin, i); playTone((3000-9*i), 2); } // Next 4 lines initialise the display LEDs // analogWrite(ammoPin, ((int) ammo)); // analogWrite(lifePin, ((int) life)); // lifeDisplay(); ammoDisplay(); Serial.println("Ready....");}// Main loop most of the code is in the sub routinesvoid loop(){ receiveIR(); if(FIRE != 0){ shoot(); ammoDisplay(); } triggers();}// SUB ROUTINESvoid ammoDisplay() { // Updates Ammo LED output if(ammo==8 || ammo==7) { // digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, HIGH); } else if(ammo==6 || ammo==5) { //digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, LOW); } else if(ammo==4 || ammo==3) { //digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, LOW); digitalWrite(led4, LOW); } else if(ammo==2 || ammo==1) {// digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, LOW); digitalWrite(led4, LOW); } else if(ammo==0) { // digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); }}/*void lifeDisplay() { // Updates Ammo LED output float lifeF; lifeF = (260/maxLife) * life; if(lifeF <= 0){lifeF = 0;} if(lifeF > 255){lifeF = 255;} analogWrite(lifePin, ((int) lifeF));} */void receiveIR() { // Void checks for an incoming signal and decodes it if it sees one. if (irrecv.decode(&results)) { Serial.println(results.value); recebido=results.value; //value received by IR sensor Serial.println(recebido); irrecv.resume(); // Receive the next value }if(myTeamID==0 && (recebido=="2399713221" || recebido=="2385866694" || recebido=="2490605183" || recebido=="4195798586" || recebido=="1807987366" || recebido=="1783582990")) //values send by team 1 gun. From player 5 to player 1ast frag grenade{ //verificação de quem acertou o tiro para ser enviada por RF time 100 time 1 if (recebido=="2399713221") registroRF=100+(myPlayerID*10)+5; if (recebido=="2385866694") registroRF=100+(myPlayerID*10)+4; if (recebido=="2490605183") registroRF=100+(myPlayerID*10)+3; if (recebido=="4195798586") registroRF=100+(myPlayerID*10)+2; if (recebido=="1807987366") registroRF=100+(myPlayerID*10)+1; // mySwitch.send(registroRF, 24); // primeiro numero time, segundo IDdoPlayer - vitima, terceiro id_Do_player - Atirador hit();}if(myTeamID==1 && (recebido=="2103698458" || recebido=="1232964497" || recebido=="3111617568" || recebido=="521843677" || recebido=="1517537329" || recebido=="1783582990")) //value send by team 0 gun. from player 5 to player 1 1ast frag grenade{ //verificação de quem acertou o tiro para ser enviada por RF time 200 time 0 if (recebido=="2103698458") registroRF=200+(myPlayerID*10)+5; if (recebido=="1232964497") registroRF=200+(myPlayerID*10)+4; if (recebido=="3111617568") registroRF=200+(myPlayerID*10)+3; if (recebido=="521843677") registroRF=200+(myPlayerID*10)+2; if (recebido=="1517537329") registroRF=200+(myPlayerID*10)+1; //mySwitch.send(registroRF, 24); // primeiro numero time, segundo IDdoPlayer - vitima, terceiro id_Do_player - Atirador hit();}}void shoot() { if(FIRE == 1){ // Has the trigger been pressed? Serial.println("FIRE 1"); sendPulse(IRtransmitPin, 4); // Transmit Header pulse, send pulse subroutine deals with the details delayMicroseconds(IRpulse); for(int i = 0; i < 8; i++) { // Transmit Byte1 if(byte1[i] == 1){ sendPulse(IRtransmitPin, 1); //Serial.print("1 "); } //else{Serial.print("0 ");} sendPulse(IRtransmitPin, 1); delayMicroseconds(IRpulse); } for(int i = 0; i < 8; i++) { // Transmit Byte2 if(byte2[i] == 1){ sendPulse(IRtransmitPin, 1); // Serial.print("1 "); } //else{Serial.print("0 ");} sendPulse(IRtransmitPin, 1); delayMicroseconds(IRpulse); } if(myParity == 1){ // Parity sendPulse(IRtransmitPin, 1); } sendPulse(IRtransmitPin, 1); delayMicroseconds(IRpulse); Serial.println(""); Serial.println("DONE 1"); myDFPlayer.play(1); } if(FIRE == 2){ // Where a secondary fire mode would be added Serial.println("FIRE 2"); sendPulse(IRtransmitPin, 4); // Header Serial.println("DONE 2"); }FIRE = 0;ammo = ammo - 1;}void sendPulse(int pin, int length){ // importing variables like this allows for secondary fire modes etc.// This void genertates the carrier frequency for the information to be transmitted int i = 0; int o = 0; while( i < length ){ i++; while( o < IRpulses ){ o++; digitalWrite(pin, HIGH); delayMicroseconds(IRt); digitalWrite(pin, LOW); delayMicroseconds(IRt); } }}void triggers() { // Checks to see if the triggers have been presses // adicionado em 29/10/2017 para o flare e som de tiro if(digitalRead(ledTeamPin) == HIGH && (millis()-ultimoTiro) > (TBS - 170) ) { digitalWrite(ledTeamPin,LOW); // digitalWrite(speakerPin,LOW); } // fim de adicionado em 29/10/2017 para o flare e som de tiro LTR = TR; // Records previous state. Primary fire // LT2R = T2R; // Records previous state. Secondary fire TR = digitalRead(triggerPin); // Looks up current trigger button state// T2R = digitalRead(trigger2Pin); // Looks up current trigger button state // Code looks for changes in trigger state to give it a semi automatic shooting behaviour if(TR != LTR && TR == LOW && (millis()-ultimoTiro) > TBS){ FIRE = 1; ultimoTiro=millis(); //adicionado em 29/10/2017 para o flare e som de tiro if (ammo > 0){ digitalWrite(ledTeamPin,HIGH); // digitalWrite(speakerPin,HIGH); } } if(T2R != LT2R && T2R == LOW){ FIRE = 2; } if(TR == LOW && automatic == 1){ FIRE = 1; } if(T2R == LOW && automatic2 == 1){ FIRE = 2; } if(FIRE == 1 || FIRE == 2){ if(ammo < 1){FIRE = 0; noAmmo();} if(life < 1){FIRE = 0; dead();} // Fire rate code to be added here } //verifica se recarregou a arma Trecarga=digitalRead(recarga);if((Trecarga==LOW) && (millis() - ultimaRecarga) > TBS){ ultimaRecarga=millis(); //playTone(500, 100); //playTone(500, 100); if(piezo==1) { playTone(500, 100); } else { myDFPlayer.play(2); } ammo=8; ammoDisplay();}}void configureGame() { // Where the game characteristics are stored, allows several game types to be recorded and you only have to change one variable (myGameID) to pick the game. if(myGameID == 0){ x=digitalRead(recarga); Serial.println("Valor de X"); Serial.println(x); // if(digitalRead(triggerPin)==LOW) //define the team based in the triger, if its pressed when start // if(x==0) //verifica o time baseado na chave normal aberto time 0 normal fechado time 1 // { // digitalWrite(ledTeamPin,HIGH); // myTeamID=0; // } // else // { // myTeamID=1; // } myWeaponID = 1; maxAmmo = 30; ammo = 8; maxLife = 1; life = 1; myWeaponHP = 1; } if(myGameID == 1){ myWeaponID = 1; maxAmmo = 100; ammo = 8; maxLife = 1; life = 1; myWeaponHP = 2; } Serial.print("team "); Serial.print(myTeamID);}void frequencyCalculations() { // Works out all the timings needed to give the correct carrier frequency for the IR signal IRt = (int) (500/IRfrequency); IRpulses = (int) (IRpulse / (2*IRt)); IRt = IRt - 4; // Why -4 I hear you cry. It allows for the time taken for commands to be executed. // More info: http://j44industries.blogspot.com/2009/09/arduino-frequency-generation.html#more Serial.print("Oscilation time period /2: "); Serial.println(IRt); Serial.print("Pulses: "); Serial.println(IRpulses); timeOut = IRpulse + 900; // Adding 50 to the expected pulse time gives a little margin for error on the pulse read time out value}void tagCode() { // Works out what the players tagger code (the code that is transmitted when they shoot) is byte1[0] = myTeamID >> 2 & B1; byte1[1] = myTeamID >> 1 & B1; byte1[2] = myTeamID >> 0 & B1; byte1[3] = myPlayerID >> 4 & B1; byte1[4] = myPlayerID >> 3 & B1; byte1[5] = myPlayerID >> 2 & B1; byte1[6] = myPlayerID >> 1 & B1; byte1[7] = myPlayerID >> 0 & B1; byte2[0] = myWeaponID >> 2 & B1; byte2[1] = myWeaponID >> 1 & B1; byte2[2] = myWeaponID >> 0 & B1; byte2[3] = myWeaponHP >> 4 & B1; byte2[4] = myWeaponHP >> 3 & B1; byte2[5] = myWeaponHP >> 2 & B1; byte2[6] = myWeaponHP >> 1 & B1; byte2[7] = myWeaponHP >> 0 & B1; myParity = 0; for (int i=0; i<8; i++) { if(byte1[i] == 1){myParity = myParity + 1;} if(byte2[i] == 1){myParity = myParity + 1;} myParity = myParity >> 0 & B1; } // Next few lines print the full tagger code. Serial.print("Byte1: "); Serial.print(byte1[0]); Serial.print(byte1[1]); Serial.print(byte1[2]); Serial.print(byte1[3]); Serial.print(byte1[4]); Serial.print(byte1[5]); Serial.print(byte1[6]); Serial.print(byte1[7]); Serial.println(); Serial.print("Byte2: "); Serial.print(byte2[0]); Serial.print(byte2[1]); Serial.print(byte2[2]); Serial.print(byte2[3]); Serial.print(byte2[4]); Serial.print(byte2[5]); Serial.print(byte2[6]); Serial.print(byte2[7]); Serial.println(); Serial.print("Parity: "); Serial.print(myParity); Serial.println();}void playTone(int tone, int duration) { // A sub routine for playing tones like the standard arduino melody example for (long i = 0; i < duration * 1000L; i += tone * 2) { digitalWrite(speakerPin, HIGH); delayMicroseconds(tone); digitalWrite(speakerPin, LOW); delayMicroseconds(tone); }}void dead() { // void determines what the tagger does when it is out of lives // Makes a few noises and flashes some lights if (enviouRF==0) //certifica que o codigo rf será enviado só uma vez { mySwitch.send(registroRF, 24); // primeiro numero time, segundo IDdoPlayer - vitima, terceiro id_Do_player - Vitima Envia Por RF enviouRF==1; } if(piezo==1) { for (int i = 1;i < 254;i++) { // analogWrite(ammoPin, i); playTone((1000+9*i), 2); } } else { myDFPlayer.play(4); // som de morto }// analogWrite(ammoPin, ((int) ammo)); // analogWrite(lifePin, ((int) life)); Serial.println("DEAD"); digitalWrite(ledTeamPin,LOW); // caso morra enquanto esta o muzzle flair ligado for (int i=0; i<10; i++) { // digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, HIGH); digitalWrite(hitPin,HIGH); delay (500); // digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); digitalWrite(hitPin,LOW); delay (500); }}void noAmmo() { // Make some noise and flash some lights when out of ammo if(piezo==1) { digitalWrite(hitPin,HIGH); playTone(500, 100); playTone(1000, 100); digitalWrite(hitPin,LOW); } else { digitalWrite(hitPin,HIGH); myDFPlayer.play(3); delay(200); digitalWrite(hitPin,LOW); }}void hit() { // Make some noise and flash some lights when you get shot digitalWrite(hitPin,HIGH); Serial.println("HIT"); life = life - 1; Serial.print("Life: "); Serial.println(life); playTone(500, 500); if(life <= 0){dead();} digitalWrite(hitPin,LOW);// lifeDisplay();}

    In the last post

    View Instructable »
  • Klebers8 commented on j44's instructable Arduino Laser Tag - Duino Tag1 year ago
    Arduino Laser Tag - Duino Tag

    I Think the problem is the frequency. I use 38 kHz sensor.

    View Instructable »
  • Klebers8 commented on j44's instructable Arduino Laser Tag - Duino Tag1 year ago
    Arduino Laser Tag - Duino Tag

    No. Because with Laser, you ll need a big "receptor". The "coverage" area is greater in IR receptors.

    Hello. A good guns for this are the Cabala´s dungeron Hunts. But you need a lens to this. Some guys uses google glass Lens.

    I dont know. But It works. I have 8 guns running with This.

    View Instructable »
  • Klebers8 commented on j44's instructable Arduino Laser Tag - Duino Tag2 years ago
    Arduino Laser Tag - Duino Tag

    Is needed if you want that you project is compatible with miles tag. If you just want to play ( like me) isnot needed.

    This is the lens that im using https://www.aliexpress.com/item/Educational-Optical-Glass-Prisms-Defective-Prism-RGB-Combiner-Decoration-Glass-Beam-splitter/32605585175.html?spm=2114.13010708.0.0.8IUZtD . It fits in a regular 3/4 inch pc tube. You need to know how many miliamps your battery can suplie.

    View Instructable »
  • Klebers8 commented on j44's instructable Arduino Laser Tag - Duino Tag2 years ago
    Arduino Laser Tag - Duino Tag

    what kind of batteries are you using?

    View Instructable »
  • Klebers8 made the instructable Arduino Laser Tag - Duino Tag2 years ago
    Arduino Laser Tag - Duino Tag

    I hope it helpsI made 3 guns. I use Sega Saturn Guns and PS3 Top Shot Guns.// Start of code (copy and paste into arduino sketch)//// Duino Tag release V1.01// Laser Tag for the arduino based on the Miles Tag Protocol.// By J44industries: www.J44industries.blogspot.com// For information on building your own Duino Tagger go to: https://www.instructables.com/member/j44///// Much credit deserves to go to Duane O'Brien if it had not been for the excellent Duino Tag tutorials he wrote I would have never been able to write this code.// Duane's tutorials are highly recommended reading in order to gain a better understanding of the arduino and IR communication. See his site http://aterribleidea.com/duino-tag-resources///// This code sets out the ba...

    see more »

    I hope it helpsI made 3 guns. I use Sega Saturn Guns and PS3 Top Shot Guns.// Start of code (copy and paste into arduino sketch)//// Duino Tag release V1.01// Laser Tag for the arduino based on the Miles Tag Protocol.// By J44industries: www.J44industries.blogspot.com// For information on building your own Duino Tagger go to: https://www.instructables.com/member/j44///// Much credit deserves to go to Duane O'Brien if it had not been for the excellent Duino Tag tutorials he wrote I would have never been able to write this code.// Duane's tutorials are highly recommended reading in order to gain a better understanding of the arduino and IR communication. See his site http://aterribleidea.com/duino-tag-resources///// This code sets out the basics for arduino based laser tag system and tries to stick to the miles tag protocol where possible.// Miles Tag details: http://www.lasertagparts.com/mtdesign.htm// There is much scope for expanding the capabilities of this system, and hopefully the game will continue to evolve for some time to come.// Licence: Attribution Share Alike: Give credit where credit is due, but you can do what you like with the code.// If you have code improvements or additions please go to http://duinotag.blogspot.com//#include <IRremote.h>// Digital IO's//int lifePin = ; // An analogue output (PWM) level corresponds to remaining life. Use PWM pin: 3,5,6,9,10 or 11. Can be used to drive LED bar graphs. eg LM3914N//int ammoPin = ; // An analogue output (PWM) level corresponds to remaining ammunition. Use PWM pin: 3,5,6,9,10 or 11.//int trigger2Pin = ; // Push button for secondary fire. Low = pressed//int IRtransmit2Pin = 8; // Secondary fire mode IR transmitter pin: Use pins 2,4,7,8,12 or 13. DO NOT USE PWM pins!!int IRreceive2Pin = 99; // Allows for checking external sensors are attached as well as distinguishing between sensor locations (eg spotting head shots)//int audioPin = 9; // Audio Trigger. Can be used to set off sounds recorded in the kind of electronics you can get in greetings card that play a custom message.int x=0;const byte led1 = 9; const byte led2 = 10; const byte led3 = 11; const byte led4 = 12;const byte teamPin = 3; //if you hold trigger when start, you ll be team 2 , led red onint triggerPin = 4; // Push button for primary fire. Low = pressedint speakerPin = 5; // Direct output to piezo sounder/speakerint hitPin = 13; // LED output pin used to indicate when the player has been hit.int IRtransmitPin = 7; // Primary fire mode IR transmitter pin: Use pins 2,4,7,8,12 or 13. DO NOT USE PWM pins!! More info: http://j44industries.blogspot.com/2009/09/arduino-frequency-generation.html#moreint IRreceivePin = 6; int recarga = 8;String recebido="0";// The pin that incoming IR signals are read from// Minimum gun requirements: trigger, receiver, IR led, hit LED.int ledTeamPin =2;// Player and Game detailsint myTeamID = 1; // 1-7 (0 = system message)int myPlayerID = 5; // Player IDint myGameID = 0; // Interprited by configureGane subroutine; allows for quick change of game types.int myWeaponID = 0; // Deffined by gameType and configureGame subroutine.int myWeaponHP = 0; // Deffined by gameType and configureGame subroutine.int maxAmmo = 0; // Deffined by gameType and configureGame subroutine.int maxLife = 0; // Deffined by gameType and configureGame subroutine.int automatic = 0; // Deffined by gameType and configureGame subroutine. Automatic fire 0 = Semi Auto, 1 = Fully Auto.int automatic2 = 0; // Deffined by gameType and configureGame subroutine. Secondary fire auto?//Incoming signal Detailsint received[18]; // Received data: received[0] = which sensor, received[1] - [17] byte1 byte2 parity (Miles Tag structure)int check = 0; // Variable used in parity checking// Statsint ammo = 0; // Current ammunitionint life = 0; // Current life// Code Variablesint timeOut = 0; // Deffined in frequencyCalculations (IRpulse + 50)int FIRE = 0; // 0 = don't fire, 1 = Primary Fire, 2 = Secondary Fireint TR = 0; // Trigger Readingint LTR = 0; // Last Trigger Readingint T2R = 0; // Trigger 2 Reading (For secondary fire)int LT2R = 0; // Last Trigger 2 Reading (For secondary fire)int Trecarga=0;float ultimaRecarga=0;// Signal Propertiesint IRpulse = 600; // Basic pulse duration of 600uS MilesTag standard 4*IRpulse for header bit, 2*IRpulse for 1, 1*IRpulse for 0.int IRfrequency = 38; // Frequency in kHz Standard values are: 38kHz, 40kHz. Choose dependant on your receiver characteristicsint IRt = 0; // LED on time to give correct transmission frequency, calculated in setup.int IRpulses = 0; // Number of oscillations needed to make a full IRpulse, calculated in setup.int header = 4; // Header lenght in pulses. 4 = Miles tag standardint maxSPS = 10; // Maximum Shots Per Seconds. Not yet used.int TBS = 300; // Time between shots. Not yet used.float ultimoTiro =0;// Transmission dataint byte1[8]; // String for storing byte1 of the data which gets transmitted when the player fires.int byte2[8]; // String for storing byte1 of the data which gets transmitted when the player fires.int myParity = 0; // String for storing parity of the data which gets transmitted when the player fires.// Received dataint memory = 10; // Number of signals to be recorded: Allows for the game data to be reviewed after the game, no provision for transmitting / accessing it yet though.int hitNo = 0; // Hit number// Byte1int player[10]; // Array must be as large as memoryint team[10]; // Array must be as large as memory// Byte2int weapon[10]; // Array must be as large as memoryint hp[10]; // Array must be as large as memoryint parity[10]; // Array must be as large as memory//IRIRrecv irrecv(IRreceivePin);decode_results results;//IRvoid setup() { // Serial coms set up to help with debugging. Serial.begin(9600); Serial.println("Startup..."); irrecv.enableIRIn(); // Start the receiver // Pin declarations //pinMode(audioPin, OUTPUT); //pinMode(trigger2Pin, INPUT); //pinMode(IRreceive2Pin, INPUT); //pinMode(IRtransmit2Pin, OUTPUT); //pinMode(lifePin, OUTPUT); //pinMode(ammoPin, OUTPUT); pinMode(triggerPin, INPUT); pinMode(speakerPin, OUTPUT); pinMode(recarga, INPUT); pinMode(hitPin, OUTPUT); pinMode(IRtransmitPin, OUTPUT); pinMode(IRreceivePin, INPUT); pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); pinMode(led4, OUTPUT); pinMode(teamPin, INPUT); digitalWrite(teamPin, LOW); pinMode(ledTeamPin, OUTPUT); digitalWrite(ledTeamPin, LOW); digitalWrite(triggerPin, HIGH); // Not really needed if your circuit has the correct pull up resistors already but doesn't harm// digitalWrite(trigger2Pin, HIGH); // Not really needed if your circuit has the correct pull up resistors already but doesn't harm digitalWrite(recarga, HIGH); frequencyCalculations(); // Calculates pulse lengths etc for desired frequency configureGame(); // Look up and configure game details tagCode(); // Based on game details etc works out the data that will be transmitted when a shot is fired for (int i = 1;i < 254;i++) { // Loop plays start up noise //analogWrite(ammoPin, i); playTone((3000-9*i), 2); } // Next 4 lines initialise the display LEDs // analogWrite(ammoPin, ((int) ammo)); // analogWrite(lifePin, ((int) life)); // lifeDisplay(); ammoDisplay(); Serial.println("Ready....");}// Main loop most of the code is in the sub routinesvoid loop(){ receiveIR(); if(FIRE != 0){ shoot(); ammoDisplay(); } triggers();}// SUB ROUTINESvoid ammoDisplay() { // Updates Ammo LED output if(ammo==8 || ammo==7) { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, HIGH); } else if(ammo==6 || ammo==5) { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, LOW); } else if(ammo==4 || ammo==3) { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, LOW); digitalWrite(led4, LOW); } else if(ammo==2 || ammo==1) { digitalWrite(led1, HIGH); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); } else if(ammo==0) { digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); }}/*void lifeDisplay() { // Updates Ammo LED output float lifeF; lifeF = (260/maxLife) * life; if(lifeF <= 0){lifeF = 0;} if(lifeF > 255){lifeF = 255;} analogWrite(lifePin, ((int) lifeF));} */void receiveIR() { // Void checks for an incoming signal and decodes it if it sees one. if (irrecv.decode(&results)) { Serial.println(results.value); recebido=results.value; //value received by IR sensor Serial.println(recebido); irrecv.resume(); // Receive the next value }if(myTeamID==0 && recebido=="2399713221") //value send by team 1 gun{ hit();}if(myTeamID==1 && recebido=="2103698458") //value send by team 0 gun{ hit();}}void shoot() { if(FIRE == 1){ // Has the trigger been pressed? Serial.println("FIRE 1"); sendPulse(IRtransmitPin, 4); // Transmit Header pulse, send pulse subroutine deals with the details delayMicroseconds(IRpulse); for(int i = 0; i < 8; i++) { // Transmit Byte1 if(byte1[i] == 1){ sendPulse(IRtransmitPin, 1); //Serial.print("1 "); } //else{Serial.print("0 ");} sendPulse(IRtransmitPin, 1); delayMicroseconds(IRpulse); } for(int i = 0; i < 8; i++) { // Transmit Byte2 if(byte2[i] == 1){ sendPulse(IRtransmitPin, 1); // Serial.print("1 "); } //else{Serial.print("0 ");} sendPulse(IRtransmitPin, 1); delayMicroseconds(IRpulse); } if(myParity == 1){ // Parity sendPulse(IRtransmitPin, 1); } sendPulse(IRtransmitPin, 1); delayMicroseconds(IRpulse); Serial.println(""); Serial.println("DONE 1"); } if(FIRE == 2){ // Where a secondary fire mode would be added Serial.println("FIRE 2"); sendPulse(IRtransmitPin, 4); // Header Serial.println("DONE 2"); }FIRE = 0;ammo = ammo - 1;}void sendPulse(int pin, int length){ // importing variables like this allows for secondary fire modes etc.// This void genertates the carrier frequency for the information to be transmitted int i = 0; int o = 0; while( i < length ){ i++; while( o < IRpulses ){ o++; digitalWrite(pin, HIGH); delayMicroseconds(IRt); digitalWrite(pin, LOW); delayMicroseconds(IRt); } }}void triggers() { // Checks to see if the triggers have been presses LTR = TR; // Records previous state. Primary fire // LT2R = T2R; // Records previous state. Secondary fire TR = digitalRead(triggerPin); // Looks up current trigger button state// T2R = digitalRead(trigger2Pin); // Looks up current trigger button state // Code looks for changes in trigger state to give it a semi automatic shooting behaviour if(TR != LTR && TR == LOW && (millis()-ultimoTiro) > TBS){ FIRE = 1; ultimoTiro=millis(); } if(T2R != LT2R && T2R == LOW){ FIRE = 2; } if(TR == LOW && automatic == 1){ FIRE = 1; } if(T2R == LOW && automatic2 == 1){ FIRE = 2; } if(FIRE == 1 || FIRE == 2){ if(ammo < 1){FIRE = 0; noAmmo();} if(life < 1){FIRE = 0; dead();} // Fire rate code to be added here } //verifica se recarregou a arma Trecarga=digitalRead(recarga);if((Trecarga==LOW) && (millis() - ultimaRecarga) > TBS){ ultimaRecarga=millis(); playTone(500, 100); playTone(500, 100); playTone(500, 100); ammo=8; ammoDisplay();}}void configureGame() { // Where the game characteristics are stored, allows several game types to be recorded and you only have to change one variable (myGameID) to pick the game. if(myGameID == 0){ x=digitalRead(recarga); Serial.println("Valor de X"); Serial.println(x); // if(digitalRead(triggerPin)==LOW) //define the team based in the triger, if its pressed when start if(x==0) //verifica o time baseado na chave normal aberto time 0 normal fechado time 1 { digitalWrite(ledTeamPin,HIGH); myTeamID=0; } else { myTeamID=1; } myWeaponID = 1; maxAmmo = 30; ammo = 8; maxLife = 1; life = 1; myWeaponHP = 1; } if(myGameID == 1){ myWeaponID = 1; maxAmmo = 100; ammo = 8; maxLife = 1; life = 1; myWeaponHP = 2; } Serial.print("team "); Serial.print(myTeamID);}void frequencyCalculations() { // Works out all the timings needed to give the correct carrier frequency for the IR signal IRt = (int) (500/IRfrequency); IRpulses = (int) (IRpulse / (2*IRt)); IRt = IRt - 4; // Why -4 I hear you cry. It allows for the time taken for commands to be executed. // More info: http://j44industries.blogspot.com/2009/09/arduino-frequency-generation.html#more Serial.print("Oscilation time period /2: "); Serial.println(IRt); Serial.print("Pulses: "); Serial.println(IRpulses); timeOut = IRpulse + 900; // Adding 50 to the expected pulse time gives a little margin for error on the pulse read time out value}void tagCode() { // Works out what the players tagger code (the code that is transmitted when they shoot) is byte1[0] = myTeamID >> 2 & B1; byte1[1] = myTeamID >> 1 & B1; byte1[2] = myTeamID >> 0 & B1; byte1[3] = myPlayerID >> 4 & B1; byte1[4] = myPlayerID >> 3 & B1; byte1[5] = myPlayerID >> 2 & B1; byte1[6] = myPlayerID >> 1 & B1; byte1[7] = myPlayerID >> 0 & B1; byte2[0] = myWeaponID >> 2 & B1; byte2[1] = myWeaponID >> 1 & B1; byte2[2] = myWeaponID >> 0 & B1; byte2[3] = myWeaponHP >> 4 & B1; byte2[4] = myWeaponHP >> 3 & B1; byte2[5] = myWeaponHP >> 2 & B1; byte2[6] = myWeaponHP >> 1 & B1; byte2[7] = myWeaponHP >> 0 & B1; myParity = 0; for (int i=0; i<8; i++) { if(byte1[i] == 1){myParity = myParity + 1;} if(byte2[i] == 1){myParity = myParity + 1;} myParity = myParity >> 0 & B1; } // Next few lines print the full tagger code. Serial.print("Byte1: "); Serial.print(byte1[0]); Serial.print(byte1[1]); Serial.print(byte1[2]); Serial.print(byte1[3]); Serial.print(byte1[4]); Serial.print(byte1[5]); Serial.print(byte1[6]); Serial.print(byte1[7]); Serial.println(); Serial.print("Byte2: "); Serial.print(byte2[0]); Serial.print(byte2[1]); Serial.print(byte2[2]); Serial.print(byte2[3]); Serial.print(byte2[4]); Serial.print(byte2[5]); Serial.print(byte2[6]); Serial.print(byte2[7]); Serial.println(); Serial.print("Parity: "); Serial.print(myParity); Serial.println();}void playTone(int tone, int duration) { // A sub routine for playing tones like the standard arduino melody example for (long i = 0; i < duration * 1000L; i += tone * 2) { digitalWrite(speakerPin, HIGH); delayMicroseconds(tone); digitalWrite(speakerPin, LOW); delayMicroseconds(tone); }}void dead() { // void determines what the tagger does when it is out of lives // Makes a few noises and flashes some lights for (int i = 1;i < 254;i++) {// analogWrite(ammoPin, i); playTone((1000+9*i), 2); } // analogWrite(ammoPin, ((int) ammo)); // analogWrite(lifePin, ((int) life)); Serial.println("DEAD"); for (int i=0; i<10; i++) { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); digitalWrite(led4, HIGH); digitalWrite(hitPin,HIGH); delay (500); digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); digitalWrite(led4, LOW); digitalWrite(hitPin,LOW); delay (500); }}void noAmmo() { // Make some noise and flash some lights when out of ammo digitalWrite(hitPin,HIGH); playTone(500, 100); playTone(1000, 100); digitalWrite(hitPin,LOW);}void hit() { // Make some noise and flash some lights when you get shot digitalWrite(hitPin,HIGH); Serial.println("HIT"); life = life - 1; Serial.print("Life: "); Serial.println(life); playTone(500, 500); if(life <= 0){dead();} digitalWrite(hitPin,LOW);// lifeDisplay();}

    View Instructable »