Mind-controlled Nerf gun

Published: April 18, 2011 22:17
Modified: April 23, 2011 21:07


Bill of Materials

Part Supplier Cost Number Total Cost Alternates
Modified Nerf Stampede $55.10 1 $55.10
NeuroSky MindSet NeuroSky $199.00 1 $199.00 [NeuroSky MindWave]
Arduino board Sparkfun $29.95 1 $29.95 [MakerShed]
BlueSMiRF Silver Sparkfun $39.95 1 $39.95
Breadboard Sparkfun $3.95 1 $3.95 [MakerShed] [Mouser] [Jameco]
Jumper wires Sparkfun $3.95 1 $3.95 [MakerShed]

Tools Required

Time Estimates

Novice: an afternoon
Advanced: 30 minutes
Expert: 10 minutes


Before I start this article, there's something I have to admit. I'm a junky.

Like many geeks who came of age in the early 90s, I got roped into doing cyberpunk. It started out as an occasional thing, maybe a Gibson novel every now and then, but before I knew it I was in deep with no hope of surfacing. Shadowrun, Deus Ex, Neil Effing Stephenson... I did it all, man. I even watched Mick Jagger scowl his way through Freejack a couple of times.

Hell, I even publicly admit I still like Johnny Mnemonic.

With my imagination held captive by this constant techno-high, I started cultivating a perhaps unhealthy obsession with cybernetics. You know, human augmentation, driving machines with your mind, implanting nanites in your body, piping the internet directly into your brain... basically, all the stuff your mother told you would bring about the downfall of humanity.

On second thought, now that 4chan exists maybe it's not a great idea to let the internet into your brain.

So of course when I heard that there is now a commodity-level, non-invasive brain-computer interface, well... you know where I'm going with this.

The NeuroSky Mind[Wave|Set]

First, let's clear up a couple of misconceptions. When many people hear the words "brain-computer interface," those that don't start grabbing their guns and preparing for the inevitable robot invasion will often say "wow, cool, so the computer can read my thoughts?"

No. That's wrong. You're thinking of a psychic.

Less accurate than the NeuroSky equipment, but at least your suits come back pressed.

So what are some of the differences between a head-mounted EEG device and a self-proclaimed psychic? Let's review:

Reads several brainwave frequencies corresponding to very general neural activity Reads your face, tea leaves, stars, horoscopes, and pretty much everything except your brainwaves
Sits comfortably on your head with a sensor against the forehead and ground contacts on your ear Not very comfortable when sitting on your head
Feeds you useful information about your mental state, including a reliability measure If these guys gave you a reliability measure, they'd be out of business
Includes a convenient API for programmability and hacking Not a platform conducive to opening up and hacking (warning: trying to do so may lead to criminal charges)

The NeuroSky equipment in particular can read most of the things that an amateur psychologist would be interested in: alpha waves (high and low), beta waves (high and low), delta waves, gamma waves (high and low), and theta waves, as well as a couple of derived measures: eye blinks, attention, and meditation. These last two are aggregate values calculated on the chip in the device.

For our purposes we're really only interested in the attention value, which corresponds very roughly to how much you concentrate. Interestingly, it's not exclusive of the meditiation value, so you can have both a high attention and a high meditation value. This is what some of the NeuroSky people described to me as "being in the zone."

The two widely-available NeuroSky devices as of this writing: the MindWave and the MindSet

Notice that there's only one forehead-mounted sensor, however, which does extremely poorly at differential analysis and reading signals from some of the more interesting parts of the head like the motor cortex. No, this can't understand what you're thinking; it can only measure activity in one part of your brain. You could be imagining strawberries, giant robots, or a dancing tyrannosaurus for all that it can tell. The intensity of the brain activity is what we'll use in our setup today.

One more note: I used the more expensive MindSet for this project because it comes with Bluetooth built-in. The MindWave is about half the price, but it uses proprietary RF communications rather than Bluetooth, which makes it fine for desktop computers but a little painful to use in hardware projects. If you feel like saving three Grants, though, there are instructions located all over the internet for hacking the MindWave into Arduino projects.

The Setup

Hardware setup is pretty easy for this--it's nothing compared to what you've just done for the Nerf gun. Grab your breadboard, plug in your Bluetooth module (assuming you've soldered some headers onto the six-pin interface), and connect some wires according to the following diagram:

Note that the TX of the Arduino goes to RX on the BlueSMiRF and vice-versa. The three wires going off the top lead to the gun.
A close-up of the breadboard. It sure would have been great if I'd owned some multi-colored wires, huh?
If you have superhuman vision and can read the labels on the BlueSMiRF, note that it has the pins in a different order than the stock Sparkfun part. They sent me a slightly different version with an alternate pinout to what's shown above.

Hook the Arduino up to your computer of choice, download the associated program, and open it up in the Arduino IDE. If this is the first time you've programmed your Bluetooth module, you'll have to set the line

#define BTBAUDRATE 57600

to read 115200 instead of 57600. The factory settings on the BlueSMiRF module are set to 115,200 bps by default, but we'll be much happier running at 57,600bps. Therefore we have to tell the Arduino that initial communication with the BlueSMiRF will be at the higher speed; after the Arduino has programmed into the BlueSMiRF once, all future communications will take place at the new rate (even if you turn it off). If you ever use the SF,1 command to restore factory settings, however, the BlueSMiRF will be set back to 115,200bps.

You'll also want to change the following line so it contains your MindSet's MAC address instead of a random one:

#define MACADDR 0013ef004ba7

Finally, set the program bit to 1:

#define PROGRAM 1

This will program the Bluetooth module so that every time it powers up, it will automatically go into master mode and start scanning for the MAC address you gave it. If your MindSet is turned on, the BlueSMiRF should find it in a matter of seconds and connect. You should only need to do this once.

So load your program onto the Arduino, and if all has gone well then you'll see the status light on the BlueSMiRF blink rapidly a few times. It will continue to flash rapidly until it either drops out of command mode ("---" if you have terminal access) or until it gets turned off and back on.

A BlueSMiRF being programmed. Note that the status light's flashing frequency is extremely fast (too fast to be captured by this camera).

Now remember that PROGRAM parameter you changed earlier? We'll have to change that back to load the actual software on-board:

#define PROGRAM 0

This will set the program to begin collecting data through the BlueSMiRF and analyzing the attention value. If the attention value exceeds the FIRE_THRESHHOLD value (on a scale of 1-100) then the Arduino will send a fire command to the gun.

There are other things the included software can do (explained on the software page), as well as a variety of easy hacks you can do to make it more useful or interesting, but I'll leave that as an exercise to you, the reader.

Otherwise, that's it! You can now terrorize Mick Jagger with your very own hacked-together smartgun.


While I can't actually offer much in the way of troubleshooting help, allow me to describe the tortuous and torturous process of getting this to work. Almost everything was an issue with the BlueSMiRF module, so if you're banging your head against something I suggest you begin investigating there.

I started out with the sample programs included in the Arduino developers' section of the NeuroSky developer site. The first one to program the BlueSMiRF didn't seem to work at first, no matter whether I set it to 57,600bps or 115,200bps. It actually took me a couple of weeks to work through this problem, not least because I at one point accidentally reversed the Vcc and ground wires; half a second and a puff of smoke later, I was out one BlueSMiRF chip and $40. Lesson learned: never do that.

A dramatic re-enactment of reversing Vcc and ground.

At some point in all this foolishness I tried using an Arduino library called NewSoftSerial which basically emulates a second serial port on any two arbitrary pins. This was extremely useful for writing a pass-through debugger to chat with the Bluetooth module: with the BlueSMiRF sitting on NewSoftSerial ports, the hardware serial ports were free to chat with the serial console in the Arduino environment. With this I could drop into command mode when the module first powered on, send commands and queries through the Arduino to the Bluetooth module, and get status responses relayed back. Handy!

What wasn't so handy, however, was interfacing with the BlueSMiRF. Even though NewSoftSerial did what I wanted it to, I was still having difficulty getting into command mode. It turns out I was having line termination problems, although not the sort that one normally thinks of when the issue of line termination comes up. In this case, I had been appending a carriage return (\r) to everything that got sent from the serial console in the Arduino IDE, since it strips out line endings on sending data. While the line terminator is necessary for commands, it turns that to get into command mode in the first place you need to send a series of three dollar signs (by default) without a line terminator--everything else requires a line terminator, however. If you do add a line terminator to the end, the BlueSMiRF basically throws up its metaphorical hands and yells "I don't understand your crazy moon language!" The solution: add a flag to the program and make terminal mode a dedicated state in the program.

Roundabout midnight on a Saturday I finally uncovered one particular post on the Sparkfun forums which set me straight. At this point the NeuroSky documentation had me (rather cleverly) connecting Vcc on the BlueSMiRF to a digital pin on the Arduino so that it could be powered on and off programatically (Note: this is also what the Make magazine article in volume 26 has you doing). However, that didn't seem to be making any contact with the MindSet--the status LED on the Bluetooth module just kept blinking as if it was scanning and not finding anything. The I/O pins run at 5V, though, so I connected Vcc to the 3.3V source on the Arduino and voilà! It connected almost instantly. Lesson learned: read the specs.

However, I now had a new problem facing me. Everything was coming out gibberish! Almost everything, anyway. I was getting checksum errors and over-long packets right and left, and almost nothing was registering. I could get some small values for meditation, but almost nothing for attention. It turns out that I still had the BlueSMiRF on a NewSoftSerial port which, while great for debugging, still runs a little bit slowly for the extreme amount of data that the MindSet is sending. I plugged it into the hardware serial port and started getting clean values almost immediately. Lesson learned: your brain puts out a serious amount of data!

Hopefully this will aid some of you in avoiding similar issues. The last piece of advice that I can give is that NeuroSky support is quite nice and they're very good about supporting developers and hackers--it's the main reason I chose their product over any of the other three available at the time.

Now go shoot some mind bullets!

Creative Commons License
Mindbullets by Chris Meyer is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.