Introduction: Das Uber Airsoft Gun Turret

Picture of Das Uber Airsoft Gun Turret

This Instructable will show you how to Design, Build and Trouble Shoot an Airsoft Gun Turret with a USB interface. The turret can be toggled between Manual Mode, where a Human interfaces with it using an Xbox 360 Controller, or Automatic Detect and Fire Mode, where the turret springs to life and detects any human presence in its surroundings. Firing at Humans is not advised.

A Special Thanks to Colin. For helping me with the WebCam calibration concept way back when.

Visit my blog, for all other details not contained in this instructable.

Update: HACK-A-DAYPost checking out the turret. Very flattered from these guys words.

Step 1: Get an "Electronic" Airsoft BB Gun. and Slice It Open.

If you are in the U.S. Say just as the title says, go to any Department Store and buy one.

Look for guns that look easy to cut or to take apart.

After you've got your gun, open it up (follow this guide).

As you can see, it is very simple. If you power the motor, you fire the pistol. Before you hack it open you do this by closing the circuit by pushing a switch with your finger as you pull the trigger. But there are many, many ways to close an electric circuit, and you can get very creative. In this project we are going to use Relays to do that.

If you are not in the U.S, this may take some doing.

I am obviously not in the U.S. but I got Lucky. A friend of mine gave me his.

'(Gracias Pinche Bronzon!! Ahi esta el Robot que te dije que iba a hacer con tu Pistola.)'

If you are in Mexico: 'jalense a los bazares o a los mercados y busquen a la gente que vende cuchillos y pistolas tipo militar. las tiendas de chucherias afuera de los super mercados (Soriana y la Comer y demas) a veces las tienen. De ultimas, preguntenle a algun amigo que le gusten las gotchas si tiene una o sabe donde comprarla. En Mexico es comun que vendan gotchas y Airsoft Guns en las mismas tiendas.'

Step 2: Get Phidgets.

Phidgets are a bunch of awesome USB interfaces that rock out.

They always send you stickers with their order.

The Phigets we are going to use for this project are the servo controller, and the relay controller, or InterfaceKit 0/0/4.

While your phidgets get to you through the mail, it's a good idea to get your computer ready. Follow the next step to do so.

I know you can fire a relay with the two extra ports of the servo controller, but that required an additional circuit and I was to lazy to make it. But YOU can make it. Just have something check the servo signal until it hits certain value and fire a relay from there. You can use a PIC or one of the AVR tiny uCs to do this.

Step 3: Prepare Your Computer.

We will use an Xbox 360 gamepad to control the Turret. I think it is serves very good as interface for a pistol.

Being this the case, we need to use a Windows environment to program. And we ALL know that is a bitch.

First, get your hands on the followings SDKs. Windows SDK and Direct X 9.0c or above.

Also, you will want to get the Phidget Library of your choice. I'm going to do this in VC++ because I can get it working with the two other libraries required to make this robot. The Direct X library, and the Intel OpenCV Library.

These are all powerful tools and are behind some very very cool things, so treat them with respect!

It's a good idea to get an IDE up and running now if you don't have one and go through some of the code examples.

All the code for this robot is done by mashing together the SimpleController example from the DirectX Xpad library, the Servo and the 0/0/4 Interface phidget code examples, and the face recognition code example from OpenCV.

Check Linker errors if you are using the Microsoft Visual Studio Express CD that comes with the Phidgets.

Once you have all of this working properly, your Phidget order should have arrived!

Step 4: Phidgets and Gun

Picture of Phidgets and Gun

Use the phidget relays to close the circuit between the motor and the power supply.

If for any reason you can't make your code work, and you really want to fire your BBs, go to the Phidget Manager, in the task bar next to the clock. You can fire the BB gun from there.

If you are using an AC/DC converter to power the gun instead of batteries, make sure it can draw at lears 1.5 Amps of current, since the motor needs a bit of current to start.

Remember to shoot when there is no one in front are anything stupid like that.

Don't fire at people.

Step 5: Phidgets and Gamepad

Use the SimpleGamepad example to change the boolean variables in the InterfaceKit example Code.

Once that is done.

You should have Gamepad + Phidgets and Airsoft gun all working in unison. And hopefully you can do something like the attached video.

If you are done, it's time you build our two DOF mechanism to mount our turret.

Step 6: The Mechanism.

Picture of The Mechanism.

We are going to make a two DOF mechanism similar to this one, and this one.

I used CAD to help me, and I share it with you.

It uses two Servo Motors, two bearings, wood and plexyglass.

I eliminated one of the 'Y' motors in the end and replaced it by a Ball Bearing.

The image also shows the gun facing backwards.

Step 7: The Push Bearing.

Picture of The Push Bearing.

The push bearing is the key to have a smooth control over the 'X' axis movement of the robot and it should be mounted on a cut round piece of Plexiglas.

Step 8: Attach the Plexy Glass

Picture of Attach the Plexy Glass

Attach a piece of round cut Plexiglass to the Push Bearing.

Step 9: Cut the Wood

Picture of Cut the Wood

Get your hand dirty and use some tools to cut the wood. I approached a professional to do this.

If you live in Mexico: ' Aqui es donde nos desquitamos. Ya que cortar madera de una manera de tal manera de que sea util y estetica despues, se necesitan herramientas mamonas. Y en Mexico hay muchas carpinterias pequenias donde se pueden hacer este tipo de cosas por un precio infimo! Nosotros nos pusimos a ayudar y nos hechamos unas chelas con el carpintero en Mexico.'

After you enjoy a Beer with your Local Carpenter, proceed to assemble the wood pieces.

These can be even be pasted with White Glue. I used it, at least. Use anything you think does the work best.

Step 10: Gun Bed.

Picture of Gun Bed.

Add pair of extensions to your BB Airsoft Gun.

One will be attached to a Bearing that will smooth out movement in the 'Y' Axis of the turret and the other will be attached to the Servo that will, well, create the 'Y' Axis movement.

Using hot Glue, Add a USB Web Camera PCB to the front, and run the cable under the Gun Bedding.

Step 11: Ball Bearing

Picture of Ball Bearing

A nice Ball Bearing to hold our turret.

Step 12: Couple the Shafts

Picture of Couple the Shafts

Couple the Servo Shaft with the Gen Bed arm.

Step 13: Mount the Push Bearing

Picture of Mount the Push Bearing

Now you should have a dry wood structure. Mount the Push bearing.

Step 14: Sand the Wood

Picture of Sand the Wood

Sand the wood, and add another Web Cam to the bottom of the structure.

Place it over some News Papers and get it ready to paint.

Step 15: Cover the Servos!

Picture of Cover the Servos!

Be nice to your servo motors and cover then (and their shaft) with a little paint.

Step 16: Paint the Thing

Picture of Paint the Thing

Have it reflect your favourite lenghtwave of the electromagnetic spectrum with a nice liquidy plastic coating.

I went with the same colors as the Gamepad.

Step 17: Leave It Out to Dry

Picture of Leave It Out to Dry

At least half an hour!! More of you can.

Step 18: Add Some Stickers

Picture of Add Some Stickers

Our robot has lasers, there is no such thing as a cool robot with out lasers. So the robot must carry the appropriate warning stickers.

Step 19: Get Some Lasers

Picture of Get Some Lasers

Get some cheap Laser.

Step 20: Cut Them Up

Picture of Cut Them Up

Cut them up with the Dremel and then short the switch, as shown in the third picture.

Warning! I don't know if this is dangerous.

Step 21: PCB

Picture of PCB

Print a PCB on a Toner Printer (a.k.a laser printer or Copy Machine).

Then, Iron the piece of paper on to a slab of copper. Then, drop it in the Acid.

Step 22: Clean and Sand the PCB

Picture of Clean and Sand the PCB

After putting the copper in the acid, keep rocking it for about 15 minutes.

Take it out carefully, sand it. and then drill it.

Step 23: Solder

Picture of Solder

Introduce all the component leads into the holes of the PCB and solder it.

Step 24: Stuffing

Picture of Stuffing

Stuff the inside of the robot with all the components.

Step 25: Attach the Lasers

Picture of Attach the Lasers

Use some thermofit and to fit the Lasers to the barrel of the pistol.

Step 26: Voila!

Picture of Voila!


If you have questions about the programing, just ask me. but you can do it just by following the examples very easily.

If you want to know how to wire up the indicator LEDs or decorative LEDs, follow my other instructable. Or any other one of the trillions of guides out there.

Happy Teleshooting!


oyu1 (author)2014-01-13

You should sell these dude... These are bad (as in good)

Miltron_B (author)oyu12014-03-30

Thanks! I don't think it would be profitable though.

GeckoLink (author)2011-06-06

can it be controlled without needing a computer on-site?

Miltron_B (author)GeckoLink2014-03-30

Yes. There are many solutions now days.

You cold use a Raspberry Pie!

PyroBuilder15 (author)2011-02-19

I will probably make this, for ultimate backyard supremacy, but with a stronger gun, prob a G&G ABS M4-A1. But really cool build anyway.

bighead5454 (author)2009-11-29

hey hook this up to a simple selfmade rc car being controlled by a friend and use the turret while it is gion through ur enemys house

Miltron_B (author)bighead54542011-01-20

I'm working on a Sentry Bot for my new Home.

I will post the results!

Cadillachearseguy (author)2010-03-20

resistance is futile....

It is ineed.

candyrandy (author)2010-08-04

Nice!! Do you think it would be possible to make a version of this that looks, sounds and talks like the turrets from Portal?

Miltron_B (author)candyrandy2011-01-20

Hey, sorry for the late response. Yes! This robot uses a PC for a brain. You simply need to add the DirectX code for sound playback.

TheInventor1997 (author)2010-08-04

can you do one on a mac?

Sorry for the late response. Yes you need to use the PHP APi for the Phidgets so you can control the turret from any plataform with a browser. Even an iPod Touch or an iPad would work.

Chowmix12 (author)2010-07-16

Can i use micro servos for the X and Y axis? Im pretty sure i can because the bearings take off most of the weight.

Miltron_B (author)Chowmix122011-01-20


Sorry for the very late response. yes, you can use micro servos.

The servos I used were way over caculated. The bearings help a lot with the load!

Be sure to use ball bearings for the Y Axis servo and push bearings for the X Axis Servo.

pyrocord (author)2010-05-17

 I am building an exoskeleton to mount airsoft guns on as "armor". Could this be mounted on a shoulder of an armor suit made of sheet metal? If so, how much does it weigh?

Miltron_B (author)pyrocord2010-05-20


I think the best choice you have is to use a "Pan and Tilt" mechanism and attach it directly to the Airsoft Gun's body.

It requires only two servos and the firing signal.

Lynxmotion has some sweet pre-made "Pan and Tilt" assemblies.

As for the weight, it depends on the servos, the mechanism's material and the gun.

Good luck!

sillyplatapus (author)2009-09-03

could you make a vid or something :))

Miltron_B (author)sillyplatapus2009-09-04

Sadly, the gun turret died in acction before any vid could be made. It was just too much fun playing with it to bother filming it!

sillyplatapus (author)2009-09-03

this confuses me ? :o

donalexander (author)2009-08-26

Hey mate nice invention, I think you will be keen to see this paint ball one, let me know what you think and what software they are using?

Miltron_B (author)donalexander2009-08-31

Thanks Mate. There are several painball turrets out there. All of them are awesoem. I think the software for their robots is costum made. Probably motion tracking using openCV.

tkezic (author)2009-08-08

hi mate, can i get the software in vb 6? and the one that has the auto fire? cheers

Miltron_B (author)tkezic2009-08-10

Hi! Well, it depends on a whole bunch of things. Are you also using phidgets? If so, just get hte phidgets VB6 API to control the servos and relays. Now, sadly, the API I used for visual recnition is based in C++ (Intel OpenCV). Try googling for VB6 Computer Vision API, see if you get anything. Best of luck!

tkezic (author)Miltron_B2009-08-11

hi thanks for the quick reply. yes i am using phidgets, a polulu servo controller which i can program. would i be able to harrass you for a copy of the code anyway? cheers

Miltron_B (author)tkezic2009-08-11

Hey! Regretably, the code is long long lost in the realm on formatted hardrives and lost HDD partitions. But, it was very simple. Just grab these examples and mash them up nicely. From the Phidgets API: Servo Example and the InterfaceKit Example. From the OpenCV API: Face recognition Example. From DirectX 9.0 SDK (asumming you want to use the xbox controller): Xinput Example. With those, and the comments in them, you should be able the get it to work. The hardest part, is to align your robot with the cameras. You do this with a regression taking various data points. Oh! You need the Windows SDK for the DirectX SDK to work properlly. Also, thanks to teh DreamSpark programme, you can get VisualStudio 9 for free is you are a student. Best regards, and don't hasitate on contacting me again if you need anything else.

tkezic (author)Miltron_B2009-08-12

cheers. I have looked and looked and all i could find was the c# and i get lost within minutes of trying to figure out how to use it. i am very good with vb6, and found motion detecting software, but it gives me lots of boxes, say pic height = 50 boxes which is good for sensitivity, but the servo tries to go back and forth to all the boxes, i cant seem to get an average or centre of the x and y value. here is my code. could you help with any suggestions? thankyou so much.

Sub GetMotion()

Static Counter As Single 'counter
BoxesX = 50 'from 1 to 50 50 default on x and y
BoxesY = 50 'from 1 to 50
AveragePixelLoop = 30 'from 1 to 250 30 default

For Px = 0 To (MotionPic.Width) Step Int(MotionPic.Width / BoxesX)
For Py = 0 To (MotionPic.Height) Step Int(MotionPic.Height / BoxesY)

pixx = Fix(Px / (MotionPic.Width / BoxesX))
pixy = Fix(Py / (MotionPic.Height / BoxesY))
For Repeat = 0 To 5 ' default is 5
ColorSumStr = Right$("000000" + Hex(GetPixel(MotionPic.hdc, Px + Repeat, Py + Repeat)), 6)
ColorRedStr = Mid$(ColorSumStr, 5, 2)
ColorGreenStr = Mid$(ColorSumStr, 3, 2)
ColorBlueStr = Mid$(ColorSumStr, 1, 2)
ColorRedDec = Val("&H" + ColorRedStr)
ColorGreenDec = Val("&H" + ColorGreenStr)
ColorBlueDec = Val("&H" + ColorBlueStr)
AveragePixel(Repeat) = ColorRedDec + ColorGreenDec + ColorBlueDec

Counter = Counter + 1
If Counter = AveragePixelLoop Then Counter = 1

mdSample(pixx, pixy, 0) = 0
mdSample(pixx, pixy, Counter) = 0
For Repeat = 0 To 5
mdSample(pixx, pixy, 0) = mdSample(pixx, pixy, 0) + AveragePixel(Repeat)
mdSample(pixx, pixy, Counter) = mdSample(pixx, pixy, 0) + AveragePixel(Repeat)

AverageSum = 0
For Repeat = 1 To AveragePixelLoop
AverageSum = AverageSum + mdSample(pixx, pixy, Repeat)
AverageSum = AverageSum / AveragePixelLoop

'preveri proženje motion-a
If Abs(mdSample(pixx, pixy, 0) - AverageSum) > mdTriger Then
MotionPic.Line (Px - 4, Py - 4)-Step((MotionPic.Width / BoxesX) - 4, (MotionPic.Height / BoxesY) - 4), , B

If pixx = 0 Then Label2.Caption = 84 Else Label2.Caption = (pixx * 5)
If pixy = 0 Then Label3.Caption = 84 Else Label3.Caption = (pixy * 3) '(MotionPic.Height / 2)
Label9.Caption = MotionPic.Height

MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(8)
MSComm1.Output = Chr$(Label2.Caption)
MSComm1.Output = Chr$(85) 'Terminate and Update

MSComm1.Output = Chr$(255)
MSComm1.Output = Chr$(9)
MSComm1.Output = Chr$(Label3.Caption)
MSComm1.Output = Chr$(85) 'Terminate and Update

Miltron_B (author)tkezic2009-08-13

The thing is, your servo does not know what those values are.

Here is what you are going to:

Find the x,y value for a single pixel you want in your image. (this will be what ever you are aiming for)

Manually move your servos so that the gun is aiming to that point in the real world (if you shoot, it's going to hit where your point is)

Wirte down the value for the servo moving your X and write down the value for the servo moving Y.

Do this for all XY points for the entire cross section of the image.

Once you have the data to what servo values correspond to what x/y value, make a mathematic regresion (you can use excell or a TI calculator to do this)

Your program should be something like:

servoX = regression in fuction of X pixel data;
servoY = regression in fuction of Y pixel data;

tkezic (author)Miltron_B2009-08-14

thankyou very much, i will try it out and let you know. your help is much appreciated. thankyou

Miltron_B (author)tkezic2009-08-14

Here is a good link on how to make Regressions with Office.

If you run into trouble let me know.

It would be awesome if you post some pics of your work in progress.

Good Luck.

geekazoid (author)2009-08-12

lol i don't speak spanish or live in mexico, but i still firgured out wat it meant.. lol dictionary (i guess i go a bit overboard)

Miltron_B (author)geekazoid2009-08-13


qwertyman10 (author)2009-07-27

2 things that would make this machine even more awesome: 1. support with bluetooth or peer to peer wifi so it could be used with smartphones or mini laptops in the heat of battle up to 100 feet away, and 2. a set of wheels and some motors to make it portable. Awesome invention!

Miltron_B (author)qwertyman102009-08-04

Hey mate! Glad you liked it. This is actually controlled by a PC already, so you just need another laptop and VNC in both machines. This way you can controll it half around the world! Making it a mobile BB tank would be awesome indeed though.

qwertyman10 (author)2009-07-27

that looks like a multi-thousand dollar investment.. awesome! i could take down both my brothers and both their friends with that! that thing looks so cool.

marcos101 (author)2009-05-18

lol I want to see some one do this with a paintball gun. _

Ddog196 (author)2009-05-07

It would be bad if you can have like three of these and plant them somewhere around in the woods (if you're playing airsoft) and being able to control each one seperately and use them to take out random targets.

Miltron_B (author)Ddog1962009-05-08

I want to make something voice controlled, and get a feed of what each turret is seeing un a small, head mounted LCD.

I just found the perfect plataform:

coin11291995 (author)2009-04-07

how did you come up with this? that seems a little complicated for playing around with useless junk.

kerneykid1 (author)2009-02-04

thats cool. really.

Lylec (author)2008-08-26

Miltron, I am sure I am missing it, but you mention an auto mode in the intro. but i cant find a description of the aiming process etc. Any stats on its accuracy? In my part of the world, just being able to paint a guy up with a Laser dot will get him running

Miltron_B (author)Lylec2008-08-26

Hola Lylec!

The automated aiming mode is very simple. The OpenCV Library has an example on face recognition. In that Example, you will see that the program draws a circle around the face it is detecting.

If you look at the code as how the program draws that circle, you will see it uses a point of the image (pixel) as a center to trace the circle. This point is almost always smack in the middle of the face.

About the accuracy, it will depend on how well you calibrate your robot.

Use the FIXED WebCam to use this pixel (in x, y, coordinate system of the image) as your reference point. In order to get the position of your servos as a function of the center point of the circle, you will need to gather at least 20 points of data across the mid-section of your screen and use a spreadsheet to do a cuadratic o cubic regresion.

That means that you will have to experimentally (trial and error) find at least 20 points where the servos are in such position, that the gun is pointing to where the center of the drawn circle is. And you have to find this 20 points across the mid section of the image.

I hope that answered your question, if not, ask again what ever you are stuck in.

Good luck in that part of the world of yours! Just don't be mean to your neighbors.


Miltron_B (author)Miltron_B2008-08-26

Here is a nice link that I'm sure will help you. In your case, the "Shelf Space" is the center of the circle and the "Books sold" are the position of one of your servo motors. If you want to take it further, the face recognition software also gives you a circle radius, this will be a nice indication of how far your target will be.

Lylec (author)Miltron_B2008-08-27

Thanks Miltron. And just a useful/less factoid. I live in South Africa, and Hola is also a very common/hip greeting amongst the youth (tho mainly the black youth). The theory is that during the cold war, Cuba send instructors to Angola to train soldiers (our erstwhile enemies) They obviously spoke spanish, so the greeting was passed on to their students and slowly it made its way into our local slang..... So there you go, you can greet practically any SA youth (under 35 probably) in your native tongue......

NZbomber (author)Lylec2008-12-30

what sport?

Miltron_B (author)NZbomber2008-12-30

FIFA World Cup. It's huge everywhere, except in the U.S.

Lylec (author)Miltron_B2009-01-04

I have tickets already :) only for round of 16 tho.

Miltron_B (author)Lylec2008-08-28

That story is friggin' awesome! I want to go to SA for the WorldCup 2010.

Miltron_B (author)Miltron_B2008-08-26

for got the link.

sdaw (author)2008-12-23

would you mind putting some diminsions in? i managed to get this as a school project, and i don't have much time to think about it. thanks.

About This Instructable




Bio: I'm currently doing my studies in the institute of tecnology for superior education from monterrey (a.k.a ITESM), in M??xico. I just ... More »
More by Miltron_B:DIY Workbench playable NESDas Uber Airsoft Gun TurretFish Tank LED Bonanza!
Add instructable to: