NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » IR LED and IR Rx code for Laser combat game

March 20, 2010
by Solorbob
Solorbob's Avatar

Does anyone happen to have any IR send and receive example code I could use? I want to send 2 bits to the RX with either a 1 or 0 parity bit.

I'm trying to match the MilesTag laser combat system. Below are some links give a bit of info on what I want to do.

http://www.lasertagparts.com/mtformat.htm

http://www.lasertagparts.com/mtformat-2.htm

I would see the TX code as pulsing the IR LED for the correct amount of time while the RX code will be looking for the data pulses to look at and take action on.

Thanks, Shawn

March 20, 2010
by lcruz007
lcruz007's Avatar

Your best option is probably use a PWM of 38KHz for the controller (The standard frequency for an IR remote controller), and maybe use a pin change interrupt and a timer on the receiver for time constraints (maybe measure the time when the IR LED is on or off).

Just as the project I built from scratch (including the IR remote controller): http://www.youtube.com/watch?v=B7zokCnJdfc

March 21, 2010
by Solorbob
Solorbob's Avatar

lcruz007, That is what I was thinking of trying. Would you mind sharing your code just so I can see how you implemented the IR stuff. I saw it was for the 328 MCU, but I could still see some working code as an example. Or if you did some prototyping of the IR, that code would be just as good.

Thanks, Shawn

March 21, 2010
by Solorbob
Solorbob's Avatar

I've found some example code for an Arduino based tagger. I do have a question on how to get the timer set so I can send for 38kHz pulse/modulation (I'm not sure which is the correct term) using the basic nerdkit. I need to send a pulse the IR LED at 38kHz for a specific length of time. I'm just trying to figure out how to do that.

March 21, 2010
by bretm
bretm's Avatar

You can set up Timer/Counter0 to run at the full clock speed (14.7456 MHz with the Nerdkits crystal) and then divide by 194. This will cause the OC0A pin to output a square wave with a frequency of 38004.124 Hz. That's only 0.011% off, so it's probably close enough.

See section 14.9 of the datasheet. Register TCCR0A should have the COM0A0 bit set to cause square-wave output on the OC0A pin, and cleared to stop the square wave output. WGM01 bit should be set for clear-on-timer-compare-match (CTC) mode. Register TCCR0B should have bit CS00 set for no clock prescaling. Register OCR0A should be 193.

March 22, 2010
by lcruz007
lcruz007's Avatar

Sure, if still need it, you can contact me to my email and I could send you an example of the code I developed for the remote controller. Please visit my website: www.ees.intelsath.com, so you can see my contact information.

March 22, 2010
by Solorbob
Solorbob's Avatar

Thanks lcruz007. I've sent the email. Shawn

March 22, 2010
by lcruz007
lcruz007's Avatar

Ok, I sent you an email with the code! :)

Make sure to also see the servosquirter project and the real time clock project here on NerdKits so you can understand it better, as it was very helpful to develop this project (I used PWM and some timers).

March 25, 2010
by Solorbob
Solorbob's Avatar

First step done. With help from lcruz007, I was able to some test code turning on an LED via IR. Next, I'll be working on the timing, so I can tell what I'm sending across from 1 MCU to the other. I'm going to base this on some Arduino code that I found doing the same thing I'm trying to do.

I hope to have this part done by Friday night..

Shawn

March 26, 2010
by lcruz007
lcruz007's Avatar

Awesome :) Please let us know your progress and future projects with my code ;p

May 01, 2010
by Solorbob
Solorbob's Avatar

Well, I almost have my tagger and receiver code merged together and put on one MCU. I've decided to test this out just as an educational project vs. trying to make these to really use for prime time.
I want to test the range with just the IR LED vs. the IR led with the lens setup as in out door laser tagging systems.

I did add some basic sounds and LCD support so I can tell what is going on. I'll post a video of my setup thus far along with my range test.

Special thanks goes out to lcruz007 for sending me some example IR code. I've not got it modified like I want it yet, but it is working enough for my needs.

Thanks, Shawn

Post a Reply

Please log in to post a reply.

Did you know that first-order systems have a exponentially decaying response to step inputs? Learn more...