IR Battle Tanks

Time frame of project: April – May 2019

Summary

This was one of the first projects I worked on using my newly acquired 3D printer. The tanks are built around a tank chassis I purchased online. The tank body, however, was designed by me. They are powered by an 11.4V LiPo battery, and are controlled via a custom wireless protocol using hacked Wii Nunchuks that can move the robot forward, backward, left, right, and rotate in place. Each tank can fire a six degree narrow beam infrared pulse from its turret that is detected by one of four sensors on each face of the tank body. The turret can also be rotated left and right. An on-board amplified speaker plays simple audio sounds when the tank fires a shot, when it’s hit, or when the health meter reaches zero (at which point the tank spins out for a few seconds).

See the Youtube video here.

Details

The tanks are controlled using hacked Wii Nunchuks, read more about that project here. The Nunchuks’ main() continuously loops, and inside the loop it first waits a random amount of time between 5 and 63 milliseconds. Then, my code reads the values of the X/Y joystick and button states. It then transmits that information via a custom RF protocol. There is a field in the packet that indicates which tank the packet is meant for. IDs can be set on the controllers and tanks using a crude button/led feedback mechanism.

With only two tanks, there is a small (but albeit non-zero) chance two controllers will transmit their information in such a way they will interfere with each other. If this happens, it means the tanks will not receive any new commands within that (up to) 63 millisecond window. My design ignores this possibility, as there will be another transmission coming right behind it within (up to) 63 milliseconds. If this happens often, I do not notice it, because the tanks are very responsive…so…I don’t care. I could see this being an issue if there were ten tanks driving around at the same time…

Now that the tanks can be controlled, and instructed to fire their infrared beams, the challenge is to detect those infrared pulses on each tank. This is solved by mounting four infrared sensors, one on each face of the tank. The IR protocol is very simple, a start bit ~3ms, and 4 data bits of either ~2ms or ~3ms, depending on whether its sending ones or zeros. This 4 bit protocol was designed for use up to sixteen tanks, with future development possibly recording which tank shot which tank and keeping a global score. The firing tank also emits a laser sound.

For now, if a tank is hit, it reduces its “health meter” by 1, and spins out for half a second. It also plays a crashing sound but it’s somewhat muffled by the spin out. If a tank’s health meter hits zero, the tank spins out for a couple seconds and plays a crude death knell of decreasing note frequencies.

The sound is implemented very crudely – I simply toggle an I/O pin to a transistor that is wired to a speaker. It works well enough for my use.

I also rolled my own servo controller code, using interrupts on the microcontroller. The servo is attached to the turret, so it can rotate left/right approximately 180 degrees.

I fit all that code into an 8K ATTINY88! See the tanks in action here.

Schematic

PCB

The PCB on the left resides on the tank, and the PCB on the right goes in the Nunchuk.

%d bloggers like this: