Preparing to make the 'Duino tag gun
If you've never worked with Arduino or any other microcontroller, this might seem like a big project to use as a starting point. It is. This project presents several interesting challenges to overcome. But this project will be equally rewarding — personally and socially. Let's look at these challenges and rewards. In this section, we start making the 'Duino tag gun.
The official Arduino page is loaded with sample projects, most of which would be easier than diving into something like a laser-tag gun. Building a 'Duino tag gun will present some unique challenges, as well as offering some awesome extra benefits.
For one thing, working with infrared is complicated. (Sorry, no actual lasers will be used during the course of this tutorial.) Infrared is more complicated than you may realize (certainly more complicated than I thought when I first set out on this project). For one thing, infrared light is all over the place, and it bounces off everything (if you've ever bounced the signal from a remote control off a wall or picture, you already know this). It's one thing to deal with a complex data algorithm, or to work on code that has to handle millions of requests per second. It's something else completely to try and deal with a real-world source of interference like the sun. The same problem-solving approaches used when writing code can be useful in trying to work with physical-world problems.
Additionally, once you are able to wrap your hands around working with infrared, you open up a huge range of potential projects you might never have considered — from something as simple as interacting with your TV to creating inexpensive interactive devices that communicate with each other over IR to controlling different parts of your computer using a remote control of your own design.
In addition to dealing with the complexities of infrared, you will find that there is a timing issue in play. The goal is to build one device that acts as both a gun that emits infrared and a detector that registers hits from another legitimate infrared source. There will be a bit of a challenge in dealing with this particular issue, and you will find some benefit (and hopefully some pleasure) in working through the various elements of this particular challenge.
Socially speaking, this is a great project to work on with friends. I quite enjoy creating devices in my own workshop, but sometimes it's fun to sit around the table with some friends and work on something together. Because these devices are intended to interact with each other, it's almost impossible to build only one. By involving friends, you make your own work easier. You've got more sensors to shoot and more guns to test your own sensor. That leads to the inevitable conclusion: It's fun. Once your 'Duino tags are up and running, you will be compelled to fire on your friends immediately.
And finally, rather than buying a ready-made, unhackable device from a store, you've collectively created your own thing. If you don't like how it works, you change the device or change the rules. You may end up spending a little more than you would for a cheap off-the-shelf unit, but in the end, you'll have something you can field-strip, reprogram, and bend to your will. That's just not something you can buy from your favorite national chain of toy stores.
Now that you're sold on the project, let's talk about the 'Duino tag gun. What will it do? How will it work? What components will you need? How will you case the electronics?
Before we can start designing the gun, we need to talk about how we want the whole thing to work. I've made some statements and assumptions along the way, so let's spell everything out so it's clear. Let's talk about how this gun works:
- When the player pulls a trigger, a single shot is fired.
- When the gun is a fired, it should make a cool sound like "PEW PEW."
- The gun will also be used to detect hits.
- When a hit is detected, the gun should make a different cool sound, like "KZZKH KZZKH."
- Each gun has a certain amount of shots that can be fired.
- When the gun is out of ammo, and the player pulls the trigger, the gun should play a third sound like "EEERK EEERK."
- When the player is eliminated, the gun should play one final sound, like "BOOM KAPOW" (OK — that's two sounds).
There are more rules variations that could be added here, but this is a great place to start. In the code we will write, we will establish the following ruleset:
- Each gun has six safe shots. There is no reload. These shots may be fired without danger.
- Each player can take six hits. Once you have take six hits, you are eliminated.
- Each shot a player fires past the sixth increases the possibility of catastrophic gun failure. In the event of catastrophic gun failure, the player is eliminated.
In somewhat more plain English, you can be hit six times, and you can fire six times. After you have used your six safe shots, each time you fire a shot, the odds of your gun failing increase. If your gun fails, you are eliminated.
Based upon these simple rules and some statements from earlier in the tutorial, we can establish some basics about the hardware:
- 'Duino tag is based on infrared.
- The gun acts as an emitter and a sensor.
- The gun needs some kind of trigger.
- The gun has sounds.
- The gun should be durable
This tutorial will not spend too much time talking about how to case your 'Duino tag gun. Once we have the electronics worked out, we cover options for creating or appropriating different cases for the project. Now that we have the behavior laid out, it is time to spec the hardware. But we won't get very far without a bit of a discussion about how infrared sensors work.
As mentioned, infrared radiation surrounds us. The sun emits it, as do lamps, TVs, and animals (the "pit" in pit viper refers to the shape of the sensor this family of snakes has that they use for finding prey). If we set up a sensor triggered whenever any infrared was detected, it would be triggered constantly, and, hence, be virtually useless.
So, if this is the case, how do infrared remote controls work? The remote control for your TV contains a specifically designed sensor built to detect infrared being emitted at a certain frequency. Sony, for example, standardizes its infrared interfaces at 40 KHz. In other words, the infrared LED is turned on and off 40,000 times per second. By only sensing input within a given frequency, the TV can ignore infrared that is not coming from the remote. The remote transmits different codes to the TV by pulsing the IR signal.
This is essentially how the 'Duino tag gun works. This means require a particular type of IR sensor. We discuss that now as we cover the parts needed and where to get them.
As mentioned, we need an Arduino board. Let's look at what else is required.
- Infrared LED
- There's nothing special about the LED. I used a T1 three-quarter IR LED from All Electronics.
- Infrared sensor
- This series was written using a TSOP2138YA Infrared Sensor (also from All Electronics).
- Single-pole momentary switch
- This is the trigger, so we want something that's not too small and not too big.
- Piezo element
- We use this to make sounds. I suggest using a small, encased one.
- 22-gauge solid or stranded wire
- We need two colors. We don't need much — a meter at most.
- We need a couple different resistors. One 100Ω resistor (that's 100 ohm, or Brown-Black-Brown), one 10kΩ resistor (that's 10000 ohm, or Brown-Black-Orange), and one 82Ω resistor (that's 82 ohm, or Grey-Red-Black).
- We will need one 0.1uF capacitor.
- A small magnifying lens (three-quarters to 1 inch in diameter) — for this first time through, you can use a cheap plastic one given as a party favor.
- A short length of PVC or other rigid tubing.
These parts cost $5 or less, depending on where you shop.
You should be able to walk into Radio Shack and find what you need to complete this series. If you'd rather order from an online dealer, here are three recommendations:
- Offers a variety of electronic components and reasonable prices
- Another excellent source of electronic components online
- All Electronics Corp.
- Selection is a little more narrow than the other two, but I have been a happy customer
See Resources for these online retailers. Alternately, a simple Web search will turn up many options. If you decide to order elsewhere, keep these four points in mind:
- Check the delivery time, especially when ordering from eBay sellers. You can find many electronic components from eBay sellers, but frequently the items are shipped directly from China, which can take a week or two.
- Don't order anything that doesn't have a spec sheet. All electronic components have what's known as a spec sheet that lists a lot of vital information about voltage and wiring and so forth. If you don't have this information on hand, you may find working with your components challenging.
- Shop around. Component prices vary widely. Don't be afraid to cross-reference the prices offered on different sites. Unless you are placing large orders, it won't make much sense to order sensors from one site and LEDs from another. But you should still verify that you're getting a competitive price.
- Be precise with model numbers, especially with the IR sensor. That may seem really obvious if you have worked with electronics before, but it may be less obvious if you are new to this. IR sensors have many makes and models, and are similar in appearance but dissimilar in frequency. Frequency is important.
While waiting for parts to arrive, let's do something neat with your Arduino. This will help whet your appetite for the project, as well as introduce a little-known capability of the LED. This experiment won't end up being part of the finished project, but it should help you come to a better understanding of how frequency works. Plus, it lets you get your hands dirty working with Arduino software and hardware.