IR code help

I'm working on making a laser tag game with arduino. My basic idea is to have each player has a gun which can do two things, fire and a secondary fire depending on what button is pushed. I'm new to using IR with arduino, but I have a firm grasp on how it all works. My question is how to have the IR send out two different signals, and how to have the receiver differ the two. Any help on the code would be very helpful. I am totally lost on how to do this so even just the command on how to set up the signals, and the receiver would be a huge help, just with that I should be able to figure the rest out.

What hardware do you have for the sender? Are you expecting the Arduino to do the modulation, too?

I have an IR led for sending, and yes I would like to have the arduino do the modulation.

Well IR modulation is fairly straightforward - you can design a simple code (lookup IR remote codes but that is probably overkill ), use ATMEGA timer registers to create the carrier signal at say 38khz and modulate signal with your program - ie signal on and off pattern of your 38khz carrier - and connect it through say a transistor switch to your signal circuitry and have something like TSOP1738 at the receiving end. ATMEGA PWM intro - http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

Google for IR Remote code too.

However, i see that you mention you are using IR LED not some laser - with LED, won't you lose directionlaity?

I think I will have it in the barrel with a lens at the end to bend the light hopefully, what would you think work better? Like I said I'm new to using IR.

srinathdevelopment: Well IR modulation is fairly straightforward - you can design a simple code (lookup IR remote codes but that is probably overkill ), use ATMEGA timer registers to create the carrier signal at say 38khz and modulate signal with your program - ie signal on and off pattern of your 38khz carrier - and connect it through say a transistor switch to your signal circuitry and have something like TSOP1738 at the receiving end. ATMEGA PWM intro - http://arduino.cc/en/Tutorial/SecretsOfArduinoPWM

Google for IR Remote code too.

However, i see that you mention you are using IR LED not some laser - with LED, won't you lose directionlaity?

Why 38Mhz and not lower? say like.. 8 maybe?

38khz, not Mhz … it is the standard carrier frequency for IR remotes with typically low ambient interference. Most importantly you can get really convenient standard and fairly cheap receiver ICs like the TSOP1738 and similar that take a whole lot of pain away in decoding a 38khz modulated signal into simple carrier signal on and signal off pattern to do this manually , you would need photodiode+preamp+some kind of noise filter +comparator

Why 38Mhz and not lower? say like… 8 maybe?

Because there are readily available demodulators and complete receivers for 38kHz

Ok thanks.

jiokl: I think I will have it in the barrel with a lens at the end to bend the light hopefully, what would you think work better? Like I said I'm new to using IR.

hmmm.... dunno whether there are easily available IR laser modules. Will look forward to learn from your experiment on this.... as i said, my experiments in IR have been in the remote control land where the problem is getting wider emission angle for greater ease of use :)

That said, many IR LEDs have a emission angle of only 20-30 degrees, so if you pick one of those (look into the datasheets) and avoid the "wide" emission angle LEDs, may still work out well

Look at this for an hint of IR code

http://www.eng.utah.edu/~cs1410/Labs/lab09.html

I'm sorry I'm just having trouble understanding all of this. It should be possible to send out two different messages threw the IR led, I don't understand how write the code to make the different messages? If some one could help me step by step that would be amazing.

Check out this web page for a near infinite amount of information on how IR remote controls work:

http://www.sbprojects.com/knowledge/ir/index.php

And for a snapshot of my work on building the ultimate universal remote with an arduino, check out:

http://home.comcast.net/~tomhorsley/hardware/arduino/arduino.html

I understand how IR works that's not my problem, my problem is what is the code to declare what the signal is? When button 1 is pressed I want it to send out one wave that tells the sensor that button one is pressed and when button 2 is pressed the sensor will know that button 2 is pressed. Basically I want the IR led to be able to send out different messages, that is where I'm stuck on how to code it.

This excellent piece of work by Ken has everything you need. Make sure you check out his other IR posts that are linked on the left hand side of this site.

http://www.arcfn.com/2009/08/multi-protocol-infrared-remote-library.html

Thank you very much JoeO...I think I understand it so basically I would have something like

define buttonOne 0x20df10ef

define buttonTwo 0xa10cd00f

...

if (results.value == buttonOne) { ... }

else if (results.value == buttonTwo) { ... }

if I understand it correctly