Motion Decting Nerf Gun

by Computer Kid in Circuits > Raspberry Pi

734 Views, 2 Favorites, 0 Comments

Motion Decting Nerf Gun

P1010195[1].JPG

Hi! I'm Cameron. For this Instructable I show you how to make a motion activated Nerf gun. It is somewhat hard, but 100% AWESOME!!!

Supplies

1. electric Nerf gun

2. Raspberry Pi (b+ and newer)

3. Battery Bank (2 amp and above)

4. PIR module (5 volts)

5. relay (I used a Songle SRD-05VDC-SL-C)

6. bits and pieces (breadboard, jumper wires, micro sd card, etc)

Unscrew the Gun

P1010196[1].JPG

This step is probably the simplest thing in this instructable. Just unscrew all the screws (outside only!).

Remove the Battery Pack

P1010197[1].JPG

This step was annoyingly hard on my Nerf gun. Remove all the screws and or glue.

Attach the Battery Pack From the Nerf Gun

P1010201[1].JPG
P1010199[1].JPG
P1010198[1].JPG

Simple! Hook up the negative side of the battery pack to the negative wire on the Nerf gun, then the positive to the center of your relay (it's the center on mine, but you will want to double check to make sure).

Attach the MOTORS!!

P1010202[1].JPG

Attach the positive wire(s) of the Nerf gun to the NO (Normally Open) part of the relay (mine was the right side).

Attach the Relay

P1010208[1].JPG
P1010203[1].JPG
download.png

Hook up the data pin of the relay to GPIO 21 (bottom right) on the Raspberry Pi, GND up to Ground, and 5V to 5V.

Hook Up the PIR

P1010193[1].JPG
P1010189[1].JPG
download.png

Hook up the data pin on the PIR to GPIO pin 4, GND to Ground, and finally 5V to 5V.

Code It With Python

python code.PNG
############################Here's the code!#################################

print ("Welcome!)

print ("Importing modules...")

from gpiozero import MotionSensor

import RPi.GPIO as GPIO

from time import sleep

sleep(0.2)

print ("Complete!)

print ("Setting up GPIO...")

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM
GPIO.setup(21, GPIO.OUT)
sleep(0.3)
print ("Complete!!")
sleep(0.1)


print ("Please wait for PIR to settle...")
pir.wait_for_no_motion
sleep(1)
print ("settled!")
while True:
	print ("Ready to fire...")
	pir.wait_for_motion()
	print ("Motion detected!!!")
	print ("FIRE!!!")
	GPIO.output(21, True)
	sleep(1)print ("Powering off")
	GPIO.output(21, False)

Turn It On!

DSCF2269.JPG

Steps:

1. tie the trigger with rope so it's is stuck to the on position

2. run the Python code

3. sprint away... OR GET SHOT!!!

I hope you enjoyed this Instructable, bye!

-Cameron