The Office Sentinel – A Motion Sensor Equipped Dart Gun

Is it possible to have too many fully automatic foam dart guns?

A month ago, I would have told you that it is absolutely not possible.  Then my wife gave me an awesome Nerf gatling gun for Christmas; last year she gave me an automatic chain gun.  I realized that since both of these really require two hands to operate, I had one two many.

There was only one thing to do obviously: attach my Arduino Uno with a passive infrared motion sensor to the gun so that it will automatically open fire on anybody who walks into my office.

The Overlord

The Overlord

Fortunately this turned out to be rather simple to do.  I’ve done several projects with Raspberry Pi, and have been rather skeptical of the capabilities of Arduino.  To be perfectly honest, that hasn’t changed all that much…. comparing the two really is a like holding up a refrigerator to a full restaurant.  But when you need cold food quickly, the refrigerator is exactly what you need!

The PIR sensor is a very simple thing, having only three pins.  Plugging it into the Arduino with ground, 5v, and one of the input pins allowed it to power up and send a HIGH on the input when it detects motion.  From there, it’s only a matter of using another pin to switch a relay which in turn triggers the gun.

PIR Sensor

PIR Sensor

Switching relay

Switching relay

This particular gun is perfect for such purposes.  It doesn’t require any sort cocking action, nor are the darts fired via compressed air.  Instead they are fed into place by a belt, then pushed into a chamber by a plunger of sorts.  The chamber is enclosed on the left and right by spinning treaded wheels which catch hold of the dart and eject it through the barrel in the same way a baseball pitching machine works.

When I opened the gun’s casing, I found that the motion of pulling trigger caused two sets of contacts to connect and close the respective circuits, engaging the motors.  There are three motors altogether: 1 which drives the belt and plunger assembly, and 2 (on the same circuit) which drive the ejection wheels.

Tying into that with the Arduino was a simple matter of soldering leads onto those contacts.  I shorted the two negative contacts so that there would only be two leads coming out of the gun.  Those leads were then hooked up to the relay so that when it is switched on, all three of the motors power up.

The Arduino code is very simple at this point.  It simply checks for a HIGH return and outputs HIGH on the pin connected to the relay until the state changes.

/*
 * PIR motion sensor for dart gun
 */
 
#include "pitches.h"
#define NO_SOUND 0 // make the rests in music
 
int triggerPin = 12;                // engage the trigger
int sensorPin = 2;               // choose the input pin (for PIR sensor)
boolean pirState = false;             // we start, assuming no motion detected
int val = 0;                    // variable for reading the pin status

boolean run = false;            // motion has been read, switch on
unsigned long runTime;
long interval = 575;            // run for 5 seconds

int calibrationTime = 30;       //the time we give the sensor to calibrate (10-60 secs according to the datasheet)
 
//array of notes
int melody[] = {
   //Introduction
  NOTE_B5,NOTE_F5,NOTE_F5,NOTE_F5,NOTE_E5,NOTE_D5,NOTE_C5,NOTE_E4,NOTE_E4,NOTE_C4
};

// note duration: 1 = whole note, 2 = half note, 4 = quarter note, 8 = eighth note, etc.
int noteDurations[] = {
  16,8,16,10,10,10,16,8,16,4
};
 
int pace = 1650; // change pace of music("speedy")
int playChance = 0; // the chance that the music will be played
int playPossibility = 5; // possiblity of playing the music
 
void setup(){
  Serial.begin(9600);
  pinMode(triggerPin, OUTPUT);      // declare LED as output
  pinMode(sensorPin, INPUT);     // declare sensor as input
  digitalWrite(triggerPin, LOW);

  //give the sensor some time to calibrate
  Serial.print("Calibrating ");
    for(int i = 0; i < calibrationTime; i++){
      Serial.print(".");
      delay(1000);
      }
    Serial.println(" done");
    Serial.println("SENSOR ACTIVE");
    delay(50);
}

void loop(){
  val = digitalRead(sensorPin);  // read input value
  if ( val == HIGH) {            // check if the input is HIGH
    if ( ( run == false ) && ( pirState == false ) ){
      Serial.println("Motion detected, start shooting");
      run = true;
      pirState = true;
      digitalWrite(triggerPin, HIGH);  // turn gun on
      runTime = millis();
    }
  } else {
     pirState = false;
  }
  if ( run == true ){
     if ( ( millis() - runTime ) > interval ) { 
         run = false;
         digitalWrite(triggerPin, LOW);
         Serial.println("Turning gun off");
         delay(1500);  //delay a bit to help prevent it from triggering again immediately
         playChance = random(playPossibility);
         Serial.println(playChance);
         if ( playChance == 0 ) {
           playMusic();
         }
     }
  }
}


void playMusic() {
  Serial.println("Playing music");
  for (int Note = 0; Note <10; Note++) {//counter of Notes (54 limit the array)
    int duration = pace/noteDurations[Note];//Adjust duration with the pace of music
    tone(8, melody[Note],duration); //Play note

// to distinguish the notes, set a minimum time between them.
    delay(duration*1.2);
  }
}

I intend to modify this to implement a better timer of sorts so that it only shoots two or three darts per motion event.  (I also have plans to add a Piezo buzzer to add some sound and further scare my victims!)

Trigger leads

Trigger leads

Leads

Leads

Breadboard

Breadboard

Sensor slot

Sensor slot

I have only used a breadboard at this point, although I intend to etch a board once I am done experimenting with further additions and enhancements.  A RadioShack project enclosure I had on hand turned out to be the perfect size to hold the Arduino and the breadboard; so I cut a slot in the end to mount the PIR sensor.  Finally I taped the whole thing on top of the gun.  I do have plans to build a swiveling mount of some sort so that I can aim the sensor independently of the gun’s barrel, but a bunch of tape works fine for the time being.

I set up The Sentinel and summoned a coworker from the neighboring office:

Unfortunately none of the darts actually fired.  You can hear that the motors powered up, and the belt feed engaged properly.  However, the plunger which loads each dart into the wheel drive is not moving at all.

Upon investigation, I discovered that the action of pulling the trigger unlocks a mechanism that allows the plunger to move.  So I found it necessary to move the location of the motor contacts and wire the trigger into the “pulled” position.   After that quick fix, the gun was ready to try out again!

And one more for good measure:

UPDATE:

I have added a Piezo buzzer to the gun so that it plays music.  There is a 1 in 5 chance that after it shoots it will play the “Mario Death” tune!


2014-01-16 14.30.452014-01-16 13.47.20

2014-01-15 17.38.59

2014-01-15 17.42.37

Cody (17 Posts)