Laser Tag Sending IR Pulses

I'll keep it short.

-making laser tag on a nano ATmega328p

-need suggestions on how to send and receive IR signals in such a way that will maximize range

-I have used IRLibrary 2.8 but it only supports actual complex signals/protocols for tv remotes, whereas I just need a way to send the most basic signal for minimum distortion.

-I've got the hardware all sorted out (diodes, receivers, etc), and the laser guns did work, so I'm specifically looking for the code aspect of sending ir pulses/"signals" here. Thanks in advance.

-TLDR, i need a way of sending SIMPLE pulses for max range, instead of complex TV signals that the IR library is used for.

Well, the most basic signal is just on, or off.
The sender can be on or off depending on the whether the trigger is squeezed or not.
Can you set up the receiver to indicate that is has detected a signal anytime it sees an incoming level?
Or is that too basic?
Maybe have each gun output a different frequency, like 50 Hz, 75 Hz, 100Hz, and the recievers can use pulseIn() to detect how long a pulse it sees and indicate which gun it was shot with.

CrossRoads:
Well, the most basic signal is just on, or off.
The sender can be on or off depending on the whether the trigger is squeezed or not.
Can you set up the receiver to indicate that is has detected a signal anytime it sees an incoming level?
Or is that too basic?
Maybe have each gun output a different frequency, like 50 Hz, 75 Hz, 100Hz, and the recievers can use pulseIn() to detect how long a pulse it sees and indicate which gun it was shot with.

That's exactly what I was looking for. So let's start with sending. Say I want to send the 50Hz signal, simply timing it for every fraction of a second, and then doing digitalWrite(HIGH) will work? As for receiving, I simply add a pulseIn(pin, HIGH) and check to see if the duration of the signal is 1/50th of a second? Or am I confusing something?

Yes, that's pretty much it. You might want to check for a couple of pulses on the receive side to make sure you got a real hit and not just part of a pulse if you are having multiple pulse lengths.

Thanks so much!

The problem with ir light is that it is all around us, especially if there is any sunlight or other heat sources around. A simple ir receiver would get constant false hits if it was simply detecting the presence of ir light. So what tv remotes do is they "modulate" the ir signal, ie switch it on/off at a high frequency of around 30~50KHz. What the receiver does is, rather than simply detecting the presence of ir light, is detect that light being switched on/off at that specific frequency. This is much more sensitive and reliable because natural ir light is not modulated, so does not cause false hits.

The ir receivers you can buy are not simple ir light detectors. They also have a built-in circuit that detects a specific modulation frequency, and their outputs change from low to high when they detect that frequency. If the ir light is not modulated at the right frequency, it is ignored.

So you need to modulate your ir leds at the correct frequency to trigger your receivers. That's one of the things the the ir library does, in addition to encoding data on to the modulated "carrier" frequency. You may not need the latter. But you must have the former.

Ok, so after a whole day of tinkering with the laser guns, no matter what I try, I'm getting some wierd results with pulseIn(). I'm constantly getting random microseconds instead of the 26 that it should be printing. I've got one test program running on a led:

digitalWrite(laser, HIGH);
delayMicroseconds(26.315);
digitalWrite(laser, LOW);
delayMicroseconds(26.315);

It is 26 microseconds because my receivers are designed to receive 38khz.
When i tried doing it in milliseconds the same problems occured.

When the recievers recieve the pulse, pulseIn returns something based on how high the timeout parameter of pulseIn is. So when the timeOut is say 1000 microseconds, it returns a number 343 or 788, for example. If i set the timeout to 300 microseconds, it'll return a number usually around 150 or 200. I think I have no choice but to retreat back to the IRLibrary. Yes, i've tried keeping the pulseIn timer at default, yes, I've tried setting the receiver to input_pullup. Is there a way to use the IRLibrary to send raw simple signals/wavelengths instead of complex codes?

We seem to be missing detail.
Earlier you wrote

I've got the hardware all sorted out (diodes, receivers, etc),

.
And that's about it.

delayMicroseconds(26.315);akadelayMicroseconds(26);

Hi,
Have you looked at the tone function.

Can you post your circuit diagrams please, noting the make/model of the IR tx and rx units?

What is your local mains power frequency, 50 or 60Hz?

Thanks.. Tom... :slight_smile:

I second Tom's suggestion. From that page:

tone(pin, frequency, duration)

Parameters
pin: the Arduino pin on which to generate the tone.
frequency: the frequency of the tone in hertz. Allowed data types: unsigned int.
duration: the duration of the tone in milliseconds (optional). Allowed data types: unsigned long.

So try

tone(laser, 38000, 50);

Hopefully that will send a 50ms pulse your receiver can detect.