loading
Picture of Autonomous Paintball Sentry Gun
Make your own, custom AUTONOMOUS SENTRY GUN!

A Microcontroller Contest Finalist and Runner Up Winner.

This instructable is out-of-date. For the most recent version of the tutorial, see the website . Cheers!

This sentry gun autonomously tracks, aims, and shoots at targets, using:
-An airsoft or paintball gun
-A webcam to find targets
-A computer to process the video feed and aim the gun
-Servo motors to physically aim the gun and squeeze the trigger
-A sturdy tripod base
-A microcontroller to interface between the computer and the servo motors
-Lots of camo paint
The end result is a paintball/airsoft spewing robot, that can turn the tides of any match.

Video if it in action here .

Want to build your own?
You're in luck! All the help and information you will need is here, and the software is free and open-source. Lots of people have already used this system in their own sentry guns, with successful results.
So go ahead, make your own, and soon your own backyard will be no-man's land, too!


P.S. take pictures during the project, and when you are finished, send me a picture, and a description of your project, and I will feature it on the Successful Projects page of my website. Thanks!
 
Remove these adsRemove these ads by Signing Up

Step 1: Parts List

Picture of Parts List
          Airsoft / paintball gun, or other 'projectile dispenser'
$30   Webcam
$25   Arduino (or equivalent)
$27   3 Servo motors (pan, tilt, trigger) $9 ea.
$10   Assorted screws, nuts and bolts
$9     Wood/metal for construction
$5     USB A to B cable
$2     Some 22 gauge solid wire
$2     Servo battery box
$110 TOTAL

Also, you will need a laptop or computer to run the sentry gun program. $250 for a cheap netbook, if you don't have anything else...

Step 2: Arduino

Picture of Arduino

What's an Arduino? ...and how do you pronounce that, anyway?

An Arduino is a microcontroller. It plugs into a computer with a USB cord. On the Arduino board, shown below, there is an ATMega328 microchip, as well as 14 digital input/outputs, 6 analog inputs, and a USB port.
That's not all, but it's everything that you will need to know about, to build a sentry gun. For complete details on the Arduino board, go to http://arduino.cc/en/Main/ArduinoBoardUno.

You will use the Arduino board to take commands from the computer, and drive the servo motors as the commands dictate. Also, it will provide you with hookups for expanding your own ciruit easily afterwards.

Where to buy your own Arduino board


 

Step 3: Servo Motors

Picture of Servo Motors
servo.jpg
100_7064.JPG
To control the movement of the gun, you will use 2 servo motors.

The "pan" servo controls the side-to-side movement of the gun.
The "tilt" servo controls the up-down movement of the gun.

Your remaining servo motor will be used to squeeze the trigger of your gun.

For heavy guns, such as the paintball gun shown below, you might want to get some stronger servo's.

Step 4: Constructing the Base

Picture of Constructing the Base

Now is time to put everything together. How you do this is largely up to you.

Some design considerations:

The gun should be balanced on the tilt servo. Find the gun's center of gravity, and mount it at that point. This is so the servo dosn't have to waste energy trying to keep the gun level. IMPORTANT: when the servo has no power supplied to it, the gun should tilt freely, and when you move it with your hand it should not return to level - rather it should stay right where you let go. Spend a lot of time getting this balance just right, it is a major factor in the effectiveness of your finished sentry.

Stability is key. You want a strong, solid sentry. Vibration will cause a lot of issues with the camera later, if you don't suppress it now. I'm not going to teach you how to build well, but keep in mind that screws and bolts are better than nails, nails are better than zip ties, zip ties are better than staples, and even staples are better than duct tape.

The webcam must be solidly mounted to the base. You want it close to the gun, but the gun barrel can't ever move into the camera's view - it will see that as a target. Also, the webcam should be as solid as possible - vibration from the servo's and gun firing will mess it up.

Depending on the expected use for the sentry (airsoft? paintball? water jet? laser?), you may need to add a durable compartment to hold the electronics.

Finally: tripods are cool, but they can be prone to a lot of shaking if built badly, or if you use a flimsy camera tripod. Surveyor's tripods are great for sentry guns - they are heavy, stable, and often adjustable too.

Step 5: Wiring

Picture of Wiring
100_7040.JPG
Arduino :
The Arduino connects to the computer through the USB A to B cord. This also powers the Arduino. Various other things wire to the Arduino:

Here's a wiring schematic , and you can get a sentry shield if you want an easy solution.


Servos :
You will need a seperate power source for your servo's. I reccomend 4 C-cell or D-cell batteries, wired in series to make 6V. Check the data sheet to find the power consumption for your servo's!
Servo motors have three wires: power, ground, and signal. Each servo's power wire is typically red, and should be connected to the (+) wire from your servo power source. The ground wire is typically black or brown and should be connected to a ground pin on the Arduino board, and to the (-) wire of your power source. The signal wire is typically yellow, orange or white and should be connected as follows: The x-axis servo's signal wire goes to the Arduino's digital I/O pin 3, the y-axis servo to pin 4, and the trigger servo to pin 6.

You can also add some optional switches and LED's , but they are not necessary:
-USB status indicator LED to digital I/O pin 5
-firing indicator LED to digital I/O pin 2
-a "power switch" between the (+) from the servo power source and the servo's, to turn off the servo's and save battery power
-a "safety switch" between the (+) from the servo power source, and the trigger servo, (but after the 'power switch'), to turn off the firing functionality easily and quickly (in an emergency)
-a 'reload' switch, wired between +5V from the Arduino and digital I/O pin 7, to set the gun in a programmable position convenient for reloading



Solder everything if you can. If you want, make your own arduino 'shield' with all the conections. This allows you to "plug in" the Arduino, and "unplug" it when it is needed elsewhere, without losing track of which wires go to which pins.

Step 6: Software

Picture of Software
Now you have your sentry gun built, the wiring finished, and no doubt you want it to do something!

Before you plug your Arduino into your computer, go download the Arduino IDE .

If you have a Diecimila or older board, set the Power Jumber to USB.
Now, plug your Arduino in -  the green Power LED on the Arduino should light up, and the orange LED might flash a few times. Good job!


The Arduino IDE is what you will use to load the Arduino program onto your board. However, you will need the seperate, Processing IDE to run the computer side of the code. This does the camera tracking, and sends commands to the Arduino.
Go download the Processing IDE .


Open both Processing IDE and Arduino IDE. They should look very similar.


With a little bit of trial-and-error on the code, you should have a working sentry in no time! So get started typing!






Just kidding, of course.

The next thing you need to do is download the JMyron, blobDetection, and controlP5 libraries  from processing.org. Find the link to each library on that page. The instructions for downloading each one can be found by clicking on it's link.


You are ready to go get the code!  Download the latest version it from my website . After you have saved it to your computer, unzip the folder, and follow the directions in the strategically placed README.txt files.


Open the Arduino code in the Arduino IDE. Make sure you have selected the proper board and serial port from the Tools menu. Next, click 'Verify', wait for it to say "done compiling", then click 'Upload'. The RX and TX LED's on the Arduino board should pulse a little, then stop.


Congrats! You have finished programming the Arduino!

Plug in your webcam. Install the drivers, if you haven't already.

Now, open the Processing code in the Processing IDE. Click 'Run', and watch the magic happen!


Of course, for many of you this will not work on the first try. Don't get upset, it's normal. Pop me an email with any problems, or leave a comment below.


A tip for Windows 7 users, from ljfa321:

If you are getting this error when you try to run: processing.app.debug.RunnerException: UnsatisfiedLinkError: D:\Software\processing-1.2.1\libraries\JMyron\library\JMyron.dll: Can't find dependent libraries:

"Reason : Windows 7 doesn't come with MicroSoft C libraries, which were normally include in the other (older) Windoes system.
This means there are two files missing in the Windows 7 system: MSVCP71.DLL and Msvcr71.dll
Solution : Download these two files from here:
http://www.addictivetips.com/?attachment_id=38105
AND!
For Windows 7 32-bit OS: put both dll files inside Windows/System32 folder
For Windows 7 64-bit OS: put both dll files inside Windows/SysWOW64 folder."

Step 7: Using the Software

Picture of Using the Software

When you run the code, two windows should pop up. One is the Webcam View and the other is the Control Panel.

In Manual Mode, you can aim and fire by pointing and clicking on the webcam view. In Autonomous Mode, the software takes over, and your gun gains a life of it's own! Give it a little time to adjust to the background, and then it will shoot at anything that enters its view.

Play around with the other functions as well - Auto/Semi-auto, hide camera view, etc.



Calibrating - your servo and camera arrangement is probably unique, so you will need to calibrate it the first time.
You can do this by adjusting the values of xMin, xMax, yMin, and yMax, at the beginning of the code. Play around with them untill you have the gun aiming where you point the mouse on the webcam view. A useful tool to do this is to watch the numbers scrolling by at the bottom of the Processing IDE while you run the code.

You may also need to calibrate the servo positions set in the Arduino code:

To set the reloading position, change these lines :
    if(digitalRead(7) == HIGH) {
        xPosition = 110 ;
        yPosition = 135 ;
        fire = 0;
    }


To set the home position (no USB communication), change these lines :
    if(idle) {
        idleCounter++;   
        if(idleCounter > 10000) {
            analogWrite(5, 50);
            delay(250);
            digitalWrite(5, LOW);
            idleCounter = 0;
        }
        else{
             digitalWrite(5, LOW);
        }
        xPosition = 110 ;
        yPosition = 100 ;
        fire = 0;
    }


To set the 'squeezed' and 'not squeezed' positions for the trigger servo, change these lines :
    void Fire(int selector) {
        if(selector == 1) {
            fireTimer++;
            if(fireTimer >=0 && fireTimer <= triggerTravelMillis) {
                trigger.write( 90 );
                digitalWrite(2, HIGH);
            }
            if(fireTimer > triggerTravelMillis && fireTimer < 1.5*triggerTravelMillis) {
                trigger.write( 140 );
                digitalWrite(2, LOW);
            }
            if(fireTimer >= 1.5*triggerTravelMillis) {
                fireTimer = 0;
            }
        }
        if(selector == 3) {
            trigger.write( 90 );
            digitalWrite(2, HIGH);
        }
    }
    void ceaseFire(int selector) {
        if(selector == 1) {
            fireTimer = 0;
            trigger.write( 140 );
            digitalWrite(2, LOW);
        }
        if(selector == 3) {
            trigger.write( 140 );
            digitalWrite(2, LOW);
        }
    }

1-40 of 116Next »
gaieb1 month ago

link is broke.

This instructable is out-of-date. For the most recent version of the tutorial, see the website . Cheers!

https://sites.google.com/site/sites/system/errors

Site not found



We're sorry, we were unable to locate the site /projectsentrygun/.

You can return to your sites.

/WebspaceNotFound?path=%2Fprojectsentrygun%2F

Could you post another link for the code?

Could you provide a new link for the code? The link provided is no longer available

Hi im using windows 7 and i just keep getting " a library relies on a native code thats not available" any help would be much appreciated!

NuruzzamanF6 months ago

Can't download the Code. Showing invalid link.

Please, provide the valid link to downlaod the code

StephanM19 months ago

my processing code keep saying "A library used by sketch is not installed properly" probably not going to get replay ??

vdancev10 months ago

Здравствуйте,

мне очень нравится Arduino но я в нём абсолютно не понимаю.

Помогите пожалуйста, хочу самостоятельно изготовить дистанционно управляемую подставку для видеокамеры и закрепить на штатив. Стобы эта подставка поворачивалась горизонтально 120 градусв и вертикально 60 градусов. И чтобы данное устройство управлялось с андроида.

Подскажите мне новичку какие устройства мне понадобятся, желательно с ссылками где можно приобрести.

nivang1 year ago

is it possible to use a raspberry pi as the processor and hard drive for the software? Without using a note book?

catshark11 year ago
does this work using a raspberry pi instead of an arduino?
Hi ,
I'll build a turret using your tutorial, but from where i can buy the Controller and motors and all other stuff ?!
Sir I am facing an Error Message saying "Error inside Serial.ports" and the compiler shows

java.lang.UnsatisfiedLinkError: D:\Workshops\processing-1.5.1\rxtxSerial.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform thrown while loading gnu.io.RXTXCommDriver
java.lang.UnsatisfiedLinkError: D:\Workshops\processing-1.5.1\rxtxSerial.dll: Can't load AMD 64-bit .dll on a IA 32-bit platform
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1728)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at gnu.io.CommPortIdentifier.(CommPortIdentifier.java:123)
at processing.serial.Serial.list(Unknown Source)
at Turret_06_04.retryArduinoConnect(Turret_06_04.java:1917)
at Turret_06_04.setup(Turret_06_04.java:188)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)
Exception in thread "Animation Thread" java.lang.RuntimeException: Error inside Serial.ports()
at processing.serial.Serial.errorMessage(Unknown Source)
at processing.serial.Serial.list(Unknown Source)
at Turret_06_04.retryArduinoConnect(Turret_06_04.java:1917)
at Turret_06_04.setup(Turret_06_04.java:188)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:662)

PLEASE HELP ME OUT
I'm a highschool student looking for a senior project and I think this is what I want to do! Our goal is to find something we are interested in but know little about and become experts. My questions are would someone with little experience with computer programming do alright pulling this off? It seems easy enough but then again what do I know? :P Also approximately how much time does this project take? If you could get back to me soon that would be great! Thanks!
habs191 year ago
How much does this project cost, total?
ledfreak013 years ago
im geting an error running procesing
"unsatisfiedlinkerror: C:\users\owener\documents\processing\libraries\jmyron\library\jmyron.dll: cant find dependent libraries "
why is this?

ME TO.
fishguy3552 years ago
how would I go about changing the servo pins? the code calls for pins 8,9,10 for pan tilt and trigger servos, but me servo shield only has pins 10,11,12,13.
Hello... i am a beginner too. Im having problems with the mechanical design of .the robotic sentry im making... any advice?? Please... thanks... how can i make it more stable?
starkec4 years ago
when trying to run i keep getting this error,

processing.app.debug.RunnerException: UnsatisfiedLinkError: D:\Software\processing-1.2.1\libraries\JMyron\library\JMyron.dll: Can't find dependent libraries
at processing.app.Sketch.placeException(Sketch.java:1543)
at processing.app.debug.Runner.findException(Runner.java:582)
at processing.app.debug.Runner.reportException(Runner.java:558)
at processing.app.debug.Runner.exception(Runner.java:498)
at processing.app.debug.EventThread.exceptionEvent(EventThread.java:367)
at processing.app.debug.EventThread.handleEvent(EventThread.java:255)
at processing.app.debug.EventThread.run(EventThread.java:89)
Exception in thread "Animation Thread" java.lang.UnsatisfiedLinkError: D:\Software\processing-1.2.1\libraries\JMyron\library\JMyron.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1803)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1728)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1028)
at JMyron.JMyron.(JMyron.java:14)
at Turret_05_03.setup(Turret_05_03.java:142)
at processing.core.PApplet.handleDraw(Unknown Source)
at processing.core.PApplet.run(Unknown Source)
at java.lang.Thread.run(Thread.java:619)

I have installed jmyron as instructed in the file but i still get this error :(
Your help would be greatly appreciated :)
sentryGun53 (author)  starkec4 years ago
Hey there, The .txt file in theJMyron download has an inaccuracy:

Copy the "JMyron" folder found in this directory into the Processing/libraries directory.
NO! Put that folder instead at C:\Users\USERNAME\Documents\processing-1.1\processing-1.1\libraries

Copy the "JMyron Examples" folder into your Processing Examples folder.

IMPORTANT FOR WINDOWS USERS: there is a folder called "Extra DLLs" - those are DLLs that JMyron depends on so make sure they're copied into your system's DLL search path - such as the Processing root directory, or even C:\windows\System32.

If Processing is already running, then restart it.
I just run into that problem yesterday, seems like they doulbe do the packaging work
sentryGun53 (author)  ljfa3214 years ago
Well, the library was originally made for older versions of Processing. Newer versions store the libraries in a different palce. The instructions and file packaging were not updated on the JMyron site, and many other libraries as well.
ok, that make sence XD

BTW, do you know what kind of souce I will be able to find a air solenoid?

I want to use it to control the release of compressed air.

Ask every shops I can think of in my town and still no luck.

Roshy10 ljfa3212 years ago
sorry for the late reply, but couldn't you just use a water solenoid(for irrigation) and put air through it instead?
Roshy10 ljfa3212 years ago
sorry for the late reply, but couldn't you just use a water solenoid(for irrigation) and put air through it instead?
sentryGun53 (author)  ljfa3214 years ago
FESTO, AndyMark, SMC, Automation Direct
thx alot
ljfa321 ljfa3214 years ago
Something funny happen, I have no problem with this setting in my Windows VISTA machine, but fail to work when I try to install it to my Windows 7 machine.

The error message is exactly the same
(processing.app.debug.RunnerException: UnsatisfiedLinkError: D:\Software\processing-1.2.1\libraries\JMyron\library\JMyron.dll: Can't find dependent libraries)

I event try to copy the entire working folder from VISTA to 7, but still no luck, and I do put the DLLs in to both process root and C:\Windows\System32.

Any idea how this happened?

BTW, my windows 7 machine is completly clean, I only install the new version of JAVA since the one come with the installing CD is old I think.
ljfa321 ljfa3214 years ago
Also, my Windows7 machine don't have a webcam installed, perhaps thats the reason of the error message?
sentryGun53 (author)  ljfa3214 years ago
well, it could very posssibly be the lack of a webcam. Try running the code on the vista machine, without the webcam plugged in, and see if you get the same error.
I actually bought a webcam to connect to the windows7 machine this morning. The webcam work like a charm, but the process still show the same error massage.

Also, I try to put the two dll files all over the place, but still got no luck so far.

I will keep trying tonight~
ljfa321 ljfa3214 years ago
OK, problem solved, you might want to add this to your tutorial, since all windows 7 machine should inconter this problem.


Reason: Windows 7 doesn't come with MicroSoft C libraries, which were normally include in the other (older) Windoes system.
This means there are two files missing in the Windows 7 system: MSVCP71.DLL and Msvcr71.dll

Solution: Download these two files from here:
http://www.addictivetips.com/?attachment_id=38105

AND!

For Windows 7 32-bit OS: put both dll files inside Windows/System32 folder

For Windows 7 64-bit OS: put both dll files inside Windows/SysWOW64 folder

Than the program should run with no problem.

==========================================

New problem occurs now, but not a very big deal to me though.

Still, in Windows 7 machine, the behavior of the portal sound track is weired.

When start the program, the first sound track (deploying~) plays no problem, but whatever the sound track comes after that, tent to lag forever at the end of it.

Example: press RUN > First sound: "Deplaying" > Second sound: "Will you come over herererererererererererererererererererer................"


The tracking still works fine and smooth while the sound is lagging, it just really creeped me out when I first heard this at 1:30am by myself XD"
sentryGun53 (author)  ljfa3214 years ago
Ok, thanks for the tip, I'll put that on the software step. Nice work researching the problem!
Can't wait to do your build.
However, I did the same thing and no results
can you explain a little more on your instructions:

"IMPORTANT FOR WINDOWS USERS: there is a folder called "Extra DLLs" - those are DLLs that JMyron depends on so make sure they're copied into your system's DLL search path - such as the Processing root directory, or even C:\windows\System32."

Place "Extra DLLs" to system's DLL search path" I don't understand this.

a video tutorial would be great for your instrucable
sentryGun53 (author)  torivc4 years ago
Put them inside system32, that should be inside the search path. Actually, a lot of the time it will work fine without doing this anyways.
Cheers. Any more questions, let me know!
So i've done that and various ways to get this program off the ground. Unfortunately, no avail can you make a screen cast of exactly how to successfully acomplish this project. There nothing but endless failures on my attempts on this project. I'm really looking forward to this.
firerage8082 years ago
what would be really great is if you could make an app to wirelessly control the sentry and see the camera veiw from any mobile device that you sync with
AJMansfield3 years ago
What would be cool is if you then got an IR camera, so it can track body heat, and then some sort of marker (UV led vest? Tracking dots?) you can use to distinguish between your own team and others.
I would think a special hat or helmet with an IR bulb on top would do just fine.
tayyab002 years ago
Hello,
I am a beginner in these things, I want to know that how u have managed to pull the trigger of the gun as soon as it sense something ? is it something to change with the mechanical design or what, How have u taken that as input to the board? I will be obliged to you for the answer

Thanks
tayyab002 years ago
hello,
I am a beginner in making these things, one thing that i want to know is how u have manged to pull the trigger automatically as soon as the target is detected ? is there any mechanical alteration that is actually doing it or what ? i will obliged if you can answer to clear me

Thanks
1-40 of 116Next »