LZRTag - Flexible DIY Lasertag

An easy to build, program, modify and use AVR and ESP based Lasertag system for everyone!

Similar projects worth following
Ever wanted to play Lasertag just ... Anywhere?
Maybe with a different game mode too, or for longer periods than those offered by arenas?
I know I wanted to - so I decided to create my own version of it!

LZRTag (and yes, I know, that's not really a good abbreviation but whatever) has been a long-running project of mine. It's actually a couple of years old, but only recently got started!

Its main motivation has always been, and will always be, to have an easily customizable, cheap to create Lasertag system whose capabilities rival those of professional sets, without adding proprietary software or complex hardware.
Based on an ATMega168P, an ESP-01 (soon to be replaced with an ESP32!), and a simple but powerful MQTT interface and Ruby-based server script, I am proud to say that I am managing just that!

The Hardware

In this regard, I fear, most people won't find my project particularly enticing.

Utilizing only a simple ATMega168 clocked at 4MHz, together with an ESP-01 is enough to perform most tasks. While the ATMega handles the "hard-side" work like flashing the built-in and external LEDs, sending and receiving IR pulses, and generating noise, the ESP is there for communication.

The interface between ESP and AVR is a simple bidirectional UART line, but will eventually be replaced with a I2C line to improve quality and make expanding the system easy.

The mainboard has been kept simple to keep things easy. With only a few passives like capacitors and oscillators, as well as a few driving components like transistors for the LEDs, and not even a voltage regulator (as the LiPo cell never quite exceeds the ESP's acceptable voltage range), it's pretty bare. The addition of a buzzer, vibration motor, and connector for a "trigger" button complete it.

Communication between sets is done via an easy but effective IR channel. A strong LED (OSRAM SFH 4346) sends out pulses at a 40kHz modulation, which are received by standard VISHAY TSOP 4840. Add a small checksum, a ID code for each set, and a small lens or other focus mechanism, and you have a surprisingly precise, long-range (about 40m in good conditions!) way for one set to hit another!

The Software

Now the software is where it gets interesting. While I tried to keep things somewhat simple, it's become a bit of a mess of C++, NodeMCU LUA and Ruby, so stick with me here for a bit.

The AVR Side

The ATMega168, controlling the core of the Lasertag Sets, was programmed in C++, using Eclipse IDE. All libraries are custom and self-created (even though that probably wasn't necessary >.<), but aside from that there isn't much magic here.

All tasks are handled in Interrupts, so the main loop is free for anyone to use, should that be necessary!

It mostly just listens for commands coming in from the ESP, and reports back events, like a detected hit or when the trigger button is pressed. 

Currently, the AVR handles the following tasks:

  • Blinking the RGB LEDs of the board in various patterns (configurable)
  • Beeping the buzzer and vibrating the haptic feedback
  • Sending out IR pulses and decoding received pulses
  • Detecting when the trigger button is pressed down.

The ESP Side

The ESP-01 is the most complex part of the module. It runs using NodeMCU, however it might eventually be switched over to a more powerful C++ code to alleviate some of the annoying limitations of the LUA language.

Using it's WiFi connection and MQTT, it connects to the lasertag server. It receives configuration of ... Basically everything, ranging from the Team and Client-ID, to how many shots per second the set can do. I'll probably write a bit more about the configuration options for the sets one day.

Aside from acting as a receiver for configuration, the ESP also handles all the logic of a client. 

It tells the AVR to shoot out in regular intervals, tracks ammunition and reloads, handles respawing the player after a specific time, and provides some other statistics like battery charge and ping of the set itself.

In theory, the ESP could even be configured to run in a sort-of stand-alone mode! Though that wouldn't allow for very dynamic or interesting games, as no tracking of scores or such are done :P

The Ruby side

The server side code of the lasertag system is written in Ruby. Utilizing my own mqtt-gem, it connects up to a Broker, using it to communicate with the lasertag sets. This is mainly to simplify hack-ability of the whole thing, as well as giving me a well-developed communication protocol with low overhead.

Once the Ruby server is started, it handles a multitude of tasks:

  • It hands out unique IDs to any connected lasertag sets. Up...
Read more »

  • Ready player one!

    Xasin05/03/2019 at 16:27 0 comments

    Boy, it's been a long time since my last project update, hasn't it?
    A good number of things came up, including but not limited to the DSKorder project (who's also getting a project log soon <.<), university exams, holiday ... A good bunch of stuff.

    But, there's one really important thing to note:

    The System is now fully functional!

    Read more »

  • Putting a proper case on things!

    Xasin03/04/2019 at 20:34 0 comments

    Whew, it's ... Been a month already?
    Oh boy, I better update you guys. I don't want people starting a mutany D: 

    In any case, progress has been going steadily and nicely! The last month did have a rather tough exam phase in it that kept my productive hours at bay, but I was able to tweak a number of systems!
    More precisely, the current state is:

    • WiFi and MQTT work (the data still needs to be interpreted, but that's a trivial task)
    • The IR system is starting to take shape - TX already works, I still need to solder up a receiver to test RX.
    • Sounds and weapon systems have been tuned a little to fit a new speaker I got.
    • The battery readout and status indicators now do what they're supposed to, but ...

    The most important change of the last few weeks is the completion of the first revision of my brand new casing!
    Just have a look at this gorgeous render:

    And, of course, the whole thing has been test-printed and assembled already!
    Yes, it looks as good as in the computer <3

    The Lasertag case, fully assembled <3
    That thing there? It's the antenna I ordered in the slightly wrong size. Doesn't fit inside the case, still works for testing purposes!

    Oh yeah and the actual lighting? Looks freaking awesome!
    The viewing angle is a bit disturbed at the moment, since the printer I was working with didn't have a fitting multi-material setup. In the second version of the print the slots will have some clear filament filling it, creating a bit of a better light diffusion. However, the whole thing is still quite impressive!

    In the gif above the test idle pattern is flashing, with a few "I WAS HIT!" markers flickering in between.
    Oh yeah, and of course the gun also reacts to shooting:

    Note: The front LED isn't installed in the nozzle section just yet. Usually the fire flashes will appear in the four front reliefs, this is just a dirty POC

    All in all I'm super happy with the progress this project is making, but I do feel like taking a small break.
    There's a different project (called the DYSKorder >:3) I wanted to work on for a while, and I got a bit veeeeryy into this ...

    But yeah, this is still alive and kicking some serious ass at this point!

  • Rev. 3 all ready!

    Xasin01/27/2019 at 11:24 0 comments

    My PCB materials finally arrived! A week later than expected, sure (gee thanks Aisler for no explanation), but the PCB's quality is impeccable!
    Traces are clean cut, the enig-finish is wonderfully shiny, and I think they even chose a thicker kind of copper than what you get from LCSC.
    Just look at that gorgeous chip:

    Aisler's PCB fresh out of the bag - and looking pretty good!

    Now, I didn't want to post an update until I had something interesting to show you guys, so I took a few days to solder up and program the chip.
    Just as I expected the ESP32 was an absolute pleasure to work with, and apart from a small reversed diode that caused one of the PMBT2222A to blow up, everything worked out really well!

    The fully finished piece looks fantastic, and has tons of new features, so I am incredibly happy about it!
    The only thing I'd like to change would be the audio amplifier chip. I discovered that the ESP32's DAC can only handle up to 10kHz of updates - after I had ordered the chip. Luckily the MAX98357A, a proper audio I2S DAC with up to 32 bits at 44.1kHz, is available on a breakout for just 5€, so I got one of those and wired it up.
    The next revision will obviously have the chip on-board, but for now, it works great!

    Have some pics of the current revision:

    Just look at those lights in action! This set has a proper connection status indicator (blue), battery charge indicator (red/green dual LED), and four WS2812 spread out over the body to provide lighting inside the casing. Hell yeah <3

    And a few quick videos of the audio system in action. It's really impressive what a few cheap but well-chosen components can do!

    I'll be working on completing the software for now, and will be ordering a second revision of the PCB with a few fixes, the new audio chip, etc.
    I suppose I could also already get started on designing a new casing for this PCB, but that's a secondary concern. 

    Besides, the huge speaker of this current version will be hard to fit into ... Anywhere :P
    The later versions will probably use a 3cm diameter speaker, but I just had this one laying around, and it seems to work fine!

  • Ordering some hardware

    Xasin01/05/2019 at 22:38 1 comment

    After a few days of intense number-crunching, I've finally wrapped up the PCB design. The new chips do everything I want them to on a small 35x50mm board.
    They'll be ordered from Aisler, and if you wanna grab a hold of a few of your own, the project's public! Find it here!
    All the necessary PCB Schematic files are on GitHub, and I'll be writing a code library soon.

    KiCAD 3D Render
    That feature is just too handy, isn't it? This is what the board will look like, with that gorgeous ESP32 WROOM on the side, and my brand new logo in the middle! <3

    I will be getting the boards after a good night's sleep. Aisler supposedly delivers within a week, and shipping from and to Germany won't take more than two days, so we'll be getting results very soon!

    I encourage you guys to go through my PCBs, found on GitHub. If you spot anything odd, or have an improvement, feel free to open an issue or leave a comment!

  • Revision 3 incoming!

    Xasin01/02/2019 at 20:30 0 comments

    I don't know about you guys, but I certainly always get a bit antsy when I got free time and nothing to do.

    Luckily, that's not the case!

    I might have mentioned that I wanted to rework the hardware to use the ESP32. After multiple very positive experiences, I am happy to say that I officially started working on the next version with said controller!

    The improvement will be noticeable, in a lot of aspects:

    • The RGB LEDs will be replaced by WS2812, which are going to make for MUCH better visual effects than before.
    • Using only one powerful MCU instead of an ESP8266 and an AVR will make developing and maintaining code easier.
    • The WiFi will be much better! (NodeMCU + MQTT loves to swallow up packets :c)
    • There'll be real sound! Instead of a piezo buzzer, I've decided to use the ESP32 I2S + a small audio amp chip (the TDA301) to be able to play back much nicer sound effects. I might even be buying myself a small unity asset for that ... Hehe
    • There'll be proper power filtering, 3.3V LDO, and a built-in charger + USB<->UART bridge. Again, all making developing and maintaining devices easier. Heck, maybe I'll even throw a charge indicator LED in there!

    I've got a small request: If any one of you guys knows a bit more than me (i.e. "nothing") about audio systems, I'd love a pair of second eyes on the amplifier, just to make sure it doesn't blow up.

    With a bit of luck those PCBs will be ready to go by the end of this week. I'll be ordering them from Aisler too, so expect assembled and beeping chips by the end of January!

  • App-solute progress

    Xasin10/02/2018 at 18:41 0 comments

    Finally, I got this lazy butt moving on something I've been wanting to have for my Lasertag project (or actually, anything that has the tiniest bit of WiFi capability) - a proper App!

    Thanks to my student helper job making me learn Qt, I recently found myself possessing that last tool I needed to make an appealing, responsive UI, without worrying about the graphics and the "how" behind it too much.
    QML is just too good in that regard.

    Enough of this though, let's have some pictures!

    Very WIP front page
    The front page - This'll hold the most important stats. Life, Ammo left, a small map, and a list of teammates and their status.
    The settings
    The slightly more developed settings page. Connection status, server IP and (later) login data, as well as a custom name and profile icon link can be entered here - all stored persistently!

    The whole thing is still in the works, but thanks to the Qt MQTT library, it was easy to integrate in the running system - it'll receive game data as quickly as the sets itself!

    As an added bonus, the "Material Style" was used to get a unified, sleek look, and some of the theme colors are adjusted live to match your current theme color. Pretty neat, huh?

    In the future I'll fine-tune the front page to be easy to read, while still holding the important information, and add other gimmicks like an enemy proximity radar, but ... That's still a while off.

  • Adding a few more bits

    Xasin09/05/2018 at 16:36 0 comments

    The lasertag MCU board, in its curent state, is powered by an AVR microcontroller, which is in control of all vital functions. It blinks the LEDs, creates the sounds and vibration patterns, and much more. To add Wi-Fi, an ESP-01 was added in the later versions, communicating via UART.

    Both are simple chips to use and program, and have always been my go-to device for projects that need a small but powerful processor, or need a little bit of Wi-Fi capability.
    Slowly though I am starting to feel like a device with more "juice" to it would provide more flexibility and more interesting features, as well as reduce some of the problems I am getting with for example the ESP<->AVR communication, the fairly slow Wi-Fi speed of the ESP-01, and the hardware limitations of the AVR.

    For this reason, over the next few weeks I will be working my way into the ESP32, programmed in C++
    If all goes well it will have enough power as well as hardware features to take over the job of both the ESP-01 AND the AVR, reducing the complexity of the main board and code!
    Additionally, it'll bring in juicy new features like Bluetooth, capacitive touch support, high-speed 16bit LED PWM, faster WiFi, and potentially even proper sound playback.

    Let's see how this goes, shall we!

View all 7 project logs

Enjoy this project?



Daren Schwenke wrote 05/04/2019 at 04:01 point

I am going to *have* to build this.  Good job!

  Are you sure? yes | no

Xasin wrote 05/04/2019 at 07:00 point


Oh, please do! But don't order the PCBs just yet. There's a bit of a redesign I need to do, since I switched to a different audio processor, and the current design has a PCB trace shorted to ground and needs fixing.

I'm assuming you can Solder QFN parts, but if not I'll include Solder points for a breakout board to be attached on. All other parts are hand-solderable though.

  Are you sure? yes | no

Daren Schwenke wrote 05/04/2019 at 07:53 point

At this point I'm pursuing the #P2 - Pick and Place for 3D Printers project mainly to attempt to compensate for my rapidly failing ability to solder anything small without screwing it up.  :)

  Are you sure? yes | no

Boris van Galvin wrote 03/04/2019 at 21:20 point

What an amazing project! 
Many many moons ago I built the first generation of laser tag units down here in NZ, they used a 8080 processor and ran a HeNe laser tube. A real pain in the rear as after a few big knocks the mirrors would go out of alignment. The vest was constructed from motor cross armor and had a pile of small solar sensors installed to register hits.

We later changed the system to something a little more simple and used a strobe light constructed from an engine timing light. These were a little more robust but there was no communications as to who hit who.

Your project is really cool, having it set up like you have creates so many opportunities to expand on it.  

  Are you sure? yes | no

Xasin wrote 03/04/2019 at 21:33 point

Gha, your version sounds like a heck of a lot of fun too though!
I haven't done much in terms of vest equipment yet, but the connector at the back exposes a WS2812 signal for as many vest LEDs as wanted, as well as a general purpose I2C connector for other peripherals.

All source files are available for others to work with, mainly on the Github site! The PCB uses mostly hand-solderable components, so feel free to take some inspiration from it :D

  Are you sure? yes | no

Daren Schwenke wrote 05/04/2019 at 08:00 point

All the HeNe lasers I used in the 8080 era already had bonded optics.  I guess I was privileged and didn't even realize it..

  Are you sure? yes | no

Michael Obed wrote 09/25/2018 at 12:04 point

This looks awesome, man! Very promising!

I've implemented a Laser Tag project myself using a very similar method...I initially used an ESP8266 + Arduino IDE for the hardware side and C for the software side. It worked well, but for scalability and reliability I re-did the server side in C++ and implemented checksums and a HTTP web server. I want to do the hardware with the ESP-32 as well, as the extra power and comms are attractive...

Who knows, maybe that project will make it here too! ;)

  Are you sure? yes | no

Xasin wrote 10/02/2018 at 18:27 point

You made the server with HTTP and in C? 
Now that's kind of impressive! I had no idea how to make something like that, so I chose Ruby for my server software. I intend to stick with it though, as it is a lot more flexible than C or C++ in terms of live reloading of software - something that could come in very useful for custom servers or similar.

At least I didn't use the Arduino IDE - I prefer the cleaner, more professional environment of Eclipse (as well as the C++ autocompletion it offers <3)

  Are you sure? yes | no

HP (@banjohat) wrote 09/12/2018 at 05:23 point

This is great!

Some interresting details in your build - how uncool of visahy to call the IR receiver TSOP >_< it's not even an SMD package :P

Are you only registering hits on the gun? I would love to see a vest with targets as well!

  Are you sure? yes | no

Xasin wrote 09/13/2018 at 17:04 point

Oh, thanks for pointing out my mistake!
I accidentally called it that because the vendor I buy my parts from has their own naming scheme. Their IDs vary quite a bit from the original ones, I must have mistaken that!

Also, it's exactly the opposite - the guns don't have any built-in sensors (although adding one is trivial), and it's only the "vest piece" (or in this case a tiny strap-on shoulder sensor) that registers the hits.
Since the sensors I use have a pull-down output they're easy to connect in parallel, to have as much sensor coverage as you need.

  Are you sure? yes | no

dlhavema wrote 09/08/2018 at 05:30 point

post some code.  Super cool start man

  Are you sure? yes | no

Xasin wrote 09/08/2018 at 06:49 point

The link to the GitHub is already there. I'm still working on a bit of documentation, but it's mostly self-explanatory. 

There's also a directory with one or two example game scripts ^^

  Are you sure? yes | no

dendad51 wrote 09/07/2018 at 07:54 point

Oh, the IR camera is just to be used to sight the gun in as the "image" is invisible.

I use these sort of flashlights and have IR LEDs to put in them. Just the LED and lens is used, in a 3D printed housing.

And that feeds into one of these...

Yes, the WT558D modules are great. But don't forget to buy a programmer too.

  Are you sure? yes | no

Cor van Essen wrote 09/07/2018 at 07:16 point

That looks cool. I made something similar with everything stuffed in a toy gun. And the receiver LED were on the gun itself. Yours looks way nicer. I used an Adafruit board to connect to my phone which would then upload to the internet.  I have a proof of concept, but then other things came along. So this is inspiration to pick it up again.
How good is your IR range? 

  Are you sure? yes | no

Xasin wrote 09/07/2018 at 07:32 point

I'm using a strong IR led, probably over driving it a bit, and it's run through a fairly small hole (0.7mm diameter) to focus it. 

That gives me about 40m of range in low light conditions, some 20m if the sun is out. 

I'm still looking for a good IR lens though. With it I could focus a much larger beam, and the range could skyrocket. How much I sadly don't know.

  Are you sure? yes | no

Nick wrote 09/09/2018 at 11:08 point

Im not sure  how well they work, but have you tried lens's for arcade light guns?

They can usually be bought for cheap used on ebay,, or from local arcade operators.

  Are you sure? yes | no

Xasin wrote 09/09/2018 at 11:37 point

@Nick, that lens looks fairly good, thanks for the hint! But I fear glass lenses aren't the best option for IR - some materials don't let those wavelengths through very well. It's also a bit very expensive, so I'll stick with a simple lense-less design for the time being

  Are you sure? yes | no

denys wrote 09/06/2018 at 22:35 point

This is really interesting. I've stalled a bit on my Laser Tag system that was aimed at being finished last Christmas!

Mine is built into Nerf guns and uses an Arduino Pro Mini driving the IR LED from one of those metal flashlights. The LED and lens from the flashlight is mounted in a 3D printed housing that is stuck on the end of a mobile phone telephoto lens so it shows the "picture" of the LED at quite long range. Visible LEDs are used to setting up, but an IR enabled camera will be the way to go.

Sound is from a WT588D module. Various gunshot sounds can be selected, along with an empty click, and any other sound wanted.

It may be worth looking at these for your gun.

Power is an 18650 call with a USB charger/protector board.

But I like your ESP8266 idea.

Maybe I'll get back to it so my son gets it for this Christmas ;)

  Are you sure? yes | no

Xasin wrote 09/07/2018 at 07:32 point

The WT588D module is definitely something I'll have to look at! 

Sound is still something that my project is lacking at, I'm just using a variable frequency PWM output for the buzzer. 

I like the idea of using nerf gun casings, but my system doesn't care about what it's inside. 

As for using the IR LED of a flashlight together with a IR camera, I'm not sure if that is a good idea. A camera wouldn't be capable of decoding a modulated IR signal, meaning that any source of IR light would look like a shot. 

Plus, you wouldn't be able to discern individual players, which would not allow for different weapon types or teams to be used effectively.

Isn't a IR camera a bit expensive too? >.<

If you want, you can look at the code of my AVR chip. With a few modifications it can run in stand-alone mode, without the need for an ESP and server. 

You'd have to change it a bit to work with the sound module too, but that's doable.

  Are you sure? yes | no

Similar Projects

Does this project spark your interest?

Become a member to follow this project and never miss any updates