TagIR: Laser Tag with Adafruit Trinkets

tagIR lit up

tagIR is one of our summer tech learning projects. We're hoping that you will join our adventure by building a tagIR badge, or a bunch of them. The project is a low cost way to create an infrared laser tag game.  Wear it when you venture out in the evening so other geeks can tag you, head for the park with friends to run around laughing, or make it with your family and play at home!  To tag each other you grab any ol' infrared remote control from your junk drawer and mash some buttons.  For shorter range indoor play try out an IR emitter soldered to a 3.5 mm stereo plug (I used udirc-ir app on my iPhone to run it; more on this after the break).

The kit is based around the Adafruit Trinket which is programmable using the Arduino IDE.  We chose this board to base our kits around because it is versatile, Arduino based, and very affordable. This is a great, low cost way to experiment and learn with a microcontroller this summer.  Even if you are familiar with Arduino, this is a fun little kit to play around with and there are lots of possible expansions and transformations.  

By uploading new sketches to your Trinket you can tweak game play, effectively modifying the rules of your game.  We have a few ideas on how you can do that, but we are also sure that our creative community will come up with changes we never considered -- so please share your experiment with us!!

Read on for the details, and check out all the photos we snapped at the workbench.

Note for those following the project: we did switch from the fast blinking RGB leds, which were very cool, to the sequins. We liked the small form factor and we also had a number of requests for badges that matched Ingres colors.

parts_with_square.jpg

What's Inside?

You can get most everything we use from Adafruit, but we did not end up using the IR receiver they had in their shop at time of writing this.

Adafruit Trinket (3v)

3x LED Sequins (these have resistor built in - if you use regular LEDs be sure to add a resistor!)

1x Vibrating Disc

IR Receiver (we used this one)

Headers (like these)

Small Mint Tin Perma-Proto board

A little bit of 20 or 22 gauge wires for jumpers

(solder, soldering iron, wire strippers. a breadboard is very helpful and highly recommended)

How to Assemble It

Step 1: Prep your stuff by soldering the breadboard pins to Trinket and LEDs (optional)

First off, solder the header pins included to your Trinket. This will allow you to use it on a breadboard making it possible to test your project prior to assembly, and allow you to use the Trinket in future projects.

I like to use (solder) the extra pins on the LED sequins. It makes them much easier to test and solder to your finished board. If you're doing that, solder those pins on while you're soldering up the Trinket.

Step 2: Breadboard it up!

Next we put it all in the breadboard. See the diagram above for how we wired it all together. REMEMBER - if you used regular LEDs you need to add in those resistors!

Upload the sketch to your Trinket and test everything out.  If your upload fails double check the Adafruit Trinket intro and make sure you've got the right board selected (in the settings, all the details in the Adafruit Learning System). Another thing to note is that, if you have problems uploading, go ahead and pop your Trinket out of the breadboard and upload it without anything connected. The GPIO shares with USB, so depending on what you have on those GPIO ports it may cause issues with uploading sketches (another great reason to make it easy to pop the Trinket off the rest of the badge by using headers).  

(See below for some sample code)

Step 3: Test fit your gear

When you transfer the breadboard layout to the perma-proto board you probably want to put everything on the board to make sure you know where you will place everything.

Pay special attention to where you need jumper wires.  That is: from the ground pin to the ground rail, from pin 3 to the first LED in series, connecting each LED along the positive rail, a jumper from 3v to the positive rail, and (depending upon layout) one from pin 2 to where your IR receiver's left leg will go.  For the wire jumpers use little pieces of 20 or 22 gauge solid core wire.

Step 4: Solder

This is my suggested order for soldering the parts onto the perma-proto board.

Solder those jumper wires!  

Solder the headers onto the perma-proto board.

Solder the LEDs to the board.

Solder the vibrating disc leads (red to pin 4, blue to ground)

Solder the battery leads (Bat+:red and Ground:black)

Solder IR Receiver (do it last because it sticks up off the board most)

Step 5: Test it out, play tagIR and share

We want to see it! Use #tagIR on Twitter, Instagram or post it to our Facebook wall over at facebook.com/thelocalsbe -- we want to see what you create.  Additionally you'll notice that we provide no case design. A small mint tin is a great place to start, but we think you will come up with all sorts of cool stuff.

Shoutouts!

thanks.jpg

We will clean up this code, but this gives you a basic starting point and a way to experiment with the number of 'hits' before you are 'out', how it flashes and buzzes, etc.  Since we have been changing it and playing around with different patterns a lot it gets messy! After our workshop and some conversations with others we will put up a GitHub page with code that is properly commented and clean.

Here is the (again, not the most beautiful or efficient) sample:

int led1 = 3;
int redled = 1;
int ir = 2;
int buzz = 4;
int hits = 0;


void setup() {
pinMode(led1, OUTPUT);
pinMode(ir, INPUT);
pinMode(buzz, OUTPUT);
pinMode(redled, OUTPUT);
}

void ledOn() {

digitalWrite(led1, HIGH);


}
void buzzOn() {
digitalWrite(buzz, HIGH);
}
void ledOff() {
digitalWrite(led1, LOW);

}
void buzzOff() {
digitalWrite(buzz, LOW);
}
void redOn() {
digitalWrite(redled, HIGH);
}
void redOff() {
digitalWrite(redled, LOW);
}

void loop() {
digitalWrite(redled, LOW);
if( digitalRead(ir) == LOW){
hits = hits + 1;
int time = 500;
buzzOn();
for (int i = 0; i < hits; i++) {
ledOn();
delay(time+(i*25));
ledOff();
buzzOn();
delay(time/(i+1));
buzzOff();

}
}
else if (hits > 4) {
for (int i = 0; i < 5; i++) {
buzzOn();
delay(250*(1+i));
buzzOff();
redOn();
delay(200);
redOff();
}
delay(2000);
hits = 0;
}

else {
digitalWrite(redled, HIGH);

}
delay(50);

}

Do you like this post?

Be the first to comment