BLOG > Nerf Sentry Gun…be afraid.

The nerf sentry gun was developed as a final project for Cornell University’s CS1114 Matlab Robotics class.  Jason Wright and I worked on the gun together, and were awarded “coolest final project”.

Check out the video of the gun in action, and see how we built it:



Authentication Mode
This tells the gun to actively prompt things that move in front of the camera for badges and then shoots them if they fail to present a badge. Anybody who enters has their image uploaded to the web ( along with the date of entry, and whether or not they were approved to enter. This information is twittered as well (

Freefire Mode
Tracks and shoots anything that moves.

Panic Mode
Plays a siren, turns on the gun, and rotates the gun semi-randomly.

Manual Mode
Allows you to control the gun manually.  Arrow keys rotate the gun and the space bar fires.


Matlab Image Tracking
A matlab program is responsible for performing all image tracking tasks.  A USB webcam and the image acquisition toolbox allow matlab to capture a video stream and analyze frames to ascertain velocity vectors.  Scale-Invariant Feature Transform (SIFT) image recognition software is used to identify a badge in authentication mode.  A custom matlab GUI is used to switch between modes, change color maps, and more.

National Instruments USB DAQ-6008
This digital I/O device was interfaced to matlab using the data acquisistion toolbox to allow for control of the trigger and gun.  Channel 0 outputs a 5V signal to a mosfet in the handle of the gun that activates the trigger.  Outputs 1 and 2 connect to a basic stamp motherboard for control of the rotation servo.  Matlab can be used to turn these outputs on or off at the appropriate times.

Basic Stamp 2 and Motherboard
A basic stamp was responsible for controlling the rotation servo.  Upon receiving an input signal from the DAQ, it will rotate the servo right or left (depending on which input was activated).  It also interfaces to two hooks that sit behind the gun and act as limit switches.  When the gun rotates all the way in one direction, a hook on the gun attached to a 5V rail makes contact with a hook connected to the basic stamp.  This sends a 5V signal to the stamp on this channel so the stamp knows to stop rotating the motor.

Trigger Circuitry
A trigger circuit was assembled in the handle of the gun, it runs in parallel with the existing trigger, so the gun can still be fired manually.  Sending this circuit a 5V signal from the DAQ tells it to close the motor circuit and fire the gun.  The schematic for this circuit is included in the download below.

Physical Setup
A futaba servo is attached to the bottom of the gun.  Modifying the original tripod mount allowed us to attach it fairly easily.  Unfortunately, this motor does not provide a huge amount of torque.  This is why the gun turns somewhat slowly.  To compensate slightly for this, we made the battery pack external to reduce weight on the motor.  This motor setup is attached to two metal napkin holders (totally not stolen from a dining hall) using gorilla glue.  The entire setup is on a cardboard sheet to maintain proper spacing.


These materials are made available via a Creative Commons Attribution-Noncommercial-Share Alike 3.0 United States License.  Feel free to modify and improve upon this code as much as you like, but share your improvements and credit myself and Jason Wright as the original authors.  Please do not use this code for commercial purposes without first asking for our permission.
Creative Commons License
Download Nerf Sentry Gun Source Code and Schematics



MATLAB SIFT Function by
MATLAB twitter Function by Navan Ruthramoorthy
MATLAB passive FTP Function by Idin Motedayen


  1. Jeremy, will this work as a laser if equipped to a shark?

    Just kidding. Thanks for the inspiration, the STL Hacker Scouts have started this build and we’ll report back success soon!

  2. Would this gun possibly work mounted to a drone and aiming itself towards a target? Theoretically, of course…..

  3. Would this gun possibly work mounted to a drone and aiming itself towards a target? Theoretically, of course….

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.