Laser Tag
Introduction
A laser tag system based on an AVR microcontroller - specifically, the AVR Atmel ATmega328p. For prototyping I’m using an Arduino Uno board, but I plan to make a custom circuit board with the microcontroller placed directly on it. The software is written in C and does not use the Arduino/Wiring library - it uses AVR libc directly. This means the code has direct control over the timers, interrupts and other features of the microcontroller, which allows many improvements over existing AVR-based systems I have seen (e.g. the code is capable of simultaneous infrared reception and transmission).
Technical details
Infrared communication
The infrared signals are encoded on top of a 38 kHz carrier wave. A packet starts with a 1200 microsecond burst and is then followed by 16 more bursts, each representing a single bit. A burst of 800 microseconds indicates a binary 1, a burst of 400 microseconds indicates a binary 0. There is a 400 microsecond gap between these bursts. The most significant bit is sent first and the least significant bit is sent last.
This is similar to the underlying protocol used by other hobby Laser Tag systems, however, not quite compatible (due to the fixed 16 bit length and slightly different timings to account for the properties of the detector). The protocol that is eventually used on top of this will probably vary significantly from that of other systems - interoperability is not a concern of this project.
A Vishay TSAL6100 infrared LED is actually used for transmission. A timer on the AVR chip is used to generate the 38 kHz carrier, and the software turns the carrier on and off at the appropriate times to generate the bursts. Vishay TSOP4838 sensors are used for reception. These demodulate the signal such that their output is low when the carrier is on, and high when the carrier is off. An interrupt is fired on a rising and falling edge, and some simple timing and decoding code allows the packet to be read.
LCD screen
The LCD screen uses a Hitachi HD44780-compatible controller connected to a 74HC595 shift register to conserve pins on the AVR chip. The code can only write commands/data to the controller because of this, but all of the required functionality can be implemented without read support.
Speaker
The speaker is connected to a pin, which in turn is connected to a timer. The timer is configured to produce a square wave at varying frequencies, so a variety of flat tones can be generated, but no complex waveforms.
LEDs
The LEDs are connected to a 74HC595 shift register, just like the LCD screen. There are two LEDs for each team (red, green, blue, yellow) giving eight in total. The code implements an alternate flashing effect for the team colour. In the future, for complex game modes, a particular colour could signal someone as having captured the flag, for example.
Connected directly to the AVR chip there is also a muzzle flash LED with a small viewing angle and high intensity.
Radio communication
In order for live scoring/hit feedback, complex game modes, etc., radio communications between the guns and a central server computer will be used. I’m currently looking at using HopeRF RFM12B chips for this.
Photos
Source code
The work-in-progress code is available on GitHub.