Portal 2 Turret Gun




Introduction: Portal 2 Turret Gun

--- CARA MIA! - Master Turret Control is here!! ---

Check out the Master Turret Control. A way to control you Turret gun! Control multiple turrets with a single controller.


This Christmas, I decided to design and build a working Portal turret gun from the game

Portal 2. For me, this was an exercise of properly modelling the entire assembly in Fusion 360 first, before building anything. This design uses an Arduino Nano, an MP3 player chip, distance sensor, servos, LEDs and 3D printed parts.

The goal here was to make it move in 3 "axes", with spoken sound from the game and LED's to simulate firing.

- Open the "wings" if it senses someone in front. Use a crank mechanism with sliders, just because.

- If the person is still there after opening, fire until they drop. LED's and machine gun sound.

- If the person is no longer there, run a little scanning search routine.

- Close up and go to sleep until someone else comes along.

- Use Portal turret sounds and voices from the game.

I took some liberties in the design, trying to make it appreciably the same as the one seen in the game, but functional and printable. With some basic sketches found online, I started modelling and planning...

The sounds are stored on a microSD card, which is accessible from the back side so that sounds may be updated or changed later. It is inline with the black infill strip, making it essentially invisible once installed. 18 individual expressions and sounds used in this go-round.

The lidar sensor (time-of-flight) is on a chip with a rectangular profile. This sensor is nearly invisible from the front once assembled.

Step 1: Fusion 360 Modelling

The design started from sketches found online. Using these images as canvases, I started sketching the outlines of the 3 views. Then it was a matter of extruding them into 3D, then shelling the general shape and making cuts. All electronics were built in Fusion as components that were inserted and placed where I thought it would make sense. Driving parameters were:

  • Arduino Nano had to have connector accessible for updating once fully assembled
  • MicroSD card had to be accessible in the same manner, and ideally invisible once installed
  • Time-of-flight sensor should be invisible as well
  • A 2.1mm electrical connector for power at the back
  • Printed parts to be as large as possible (not a lot of little pieces)
  • Print with no supports

After components (Nano, other chips, servos) were added to the basic shape, they were moved around and positioned as required, and the supporting structures were built to support them inside the shell.

The wing opening mechanism was a crank and slide mechanism. Why? Because I wanted to use a crank mechanism, that's why! This added some complications, but it also had a benefit; once the geometry was determined, operational repeatability would be ensured and the min and max limits were pretty much guaranteed.

Once the entire model was built and I was confident that it would work, and could be built (printed) and assembled, I went ahead and printed out the parts and built a prototype. Once that worked out, I went back to the model and made some tweaks to improve appearance and assemblability (is that a word?). This model is what came of those changes.

This was pretty taxing, as there really aren't many boxy shapes in this thing, and it closes up pretty tightly, with no real access for tweaking once put together. I learned quite a bit on this project, such as using embedded components within other components. This made manipulating and keeping sub-assemblies linked for quick access. In the end, it was worth the effort!

As for videos guides on Fusion 360, I'd recommend Lars Christensen's YouTube channel.


I found Lars' channel along with other videos to be very helpful in coming up with new ideas and using features effectively in Fusion.

Step 2: 3D Printed Parts

Portal turret v4.zip is updated and should contain all printed parts needed to build the latest turret.

--- new "Rear test Leg". Not true to original, but it's at the back, and allows one to use a straight mini-USB connector straight up. ---

V4 parts (body and wings shown in RED) have been revised to reduce the bridge size in the body when printing and have virtually eliminated the "bump" on the front face, over the eye. This required modifying the wings to fit in the revised shell, and also required a revised pitch frame. I've also updated the infill strips to be consistently thin, and reduced the width by a hair. This makes putting it together much easier. I've also included a revised rear leg which is stretched a bit, allowing more room for the plug connector at the back.

These were printed on a Prusa Mk2, using PLA for all parts. The print orientation should be pretty evident. The body was printed in the vertical position, with no supports. There is the large gap in the sides that has to be bridged, but I really had no big issues with pretty standard settings, other than the bump. The bump on the front and rear can be virtually eliminated with good filament and some good print settings. I found that 0.2mm worked well in the slicer and produced a decent result. Any larger and openings started appearing in the body near the infill strip.

The design of channels and protrusions were done with 45 degree chamfers, so "hanging in space" elements will be minimal.

I had little cleanup to do to put the assembly together. The infill strips that slide into the channels are now pretty straightforward, with reduced width and consistent thickness. I think that one could use a thin, black material cut into strips instead of using these printed pieces (printed on edge).

The one area that does require finesse is the slider pins in the pitch frame. Straight pins (nails) in the bore holes that are chased with a 1/8" drill bit and some lube will go a long way.

Step 3: Components

V4 (Red turret) has smaller bridging, requiring v4 wings and Pitch frame.

Once the model was complete, and I was happy with my prototype, I printed rev 2 with the plastic components as shown. Everything here is PLA, with Black and design colour (Blue in this case), and a tiny bit of translucent PLA for the central "Lens" or laser eye.

This photo pretty well captures the components, with the exception of the wiring.

Step 4: Electronics

The build uses the following components:

  • Arduino Nano (1)
  • DFPlayer Mini MP3 player (or MP3-TF-16P) (1)
  • VL53L0X Time-of-Flight Ranging Sensor (1)
  • Generic SG90 micro servos (3)
  • 5mm red LEDs (5)
  • 220 Ohm resistors for LEDs (5)
  • 1kOhm resistor (1)
  • 4cm speaker, 4Ohm, 3 Watt (1)
  • 2.1mm power connector (1)
  • 3" long framing nails (4)
  • M2 x 6 screws (8)
  • M2.5 x 8 screws (2)
  • M3 x 8 screws (4)
  • M3 x 12 screws (4)
  • M3 x 16 screws (2)
  • shrink wrap
  • small tie wraps

All components are readily available from Amazon or Banggood and other sources.

The screws were sourced from an assortment kit. It's a pain in the butt to get them otherwise...

Step 5: Mechanical Assembly

Most of the mechanically assembly is reasonable. The printed parts are printed with the holes tapped where necessary, so a quick chase with a screw before final assembly will be helpful and made assembly of the screwed components pretty easy.

The Arduino and the MP3 chip snap into the cradle without hardware. The VL53LOX will slip into the front shell without fasteners. Trial fit first, then remove and install once wired up.

The slider assembly uses 4 framing nails as slider rails. They are about 1/8" in diameter, with the heads clipped. These were taken from a strip of DeWalt framing nails used with their electric framing nailer. Needless to say, smooth nails are a must.

The servos mount as shown. Orientation is important. The pitch and the pivot servos are "centred" when installing into their pieces. The crank is installed such that, when in the open position, it will close by rotating counter-clockwise direction, when viewing from the front. Open position is rods and crank straight in line, with another 10 degrees rotation till lock.

The leg assembly is the easiest part. 2-2.5mm screws, with the leg caps snapping over the elbows of each leg. Use fasteners than don't protrude above the top of the leg plate. That way, the pivoting body won't bind if you tweak the rotation range.

All servo connections to printed parts are made using the short white crank that comes with the servos. These cranks just press into the printed parts. I tried printing the splined bore in the parts that connected to each servo, but had limited, repeatable success. Much easier using the cranks that come with the servos.

The crank assembly uses the longer 2.5mm screws. The crank rods should not be squeezed between the crank halves. In fact, you could try using shorter screws without the Crank2 part. That should work as well (hopefully no appreciable torque here if the wings slide freely).

The speaker is captured by a servo mount (2 pieces) which capture the speaker. Speaker between these "legs", and held in position by securing them to the pitch servo. This servo then connected to the pitch (slider) assembly, followed by the crank assembly with rods. All of this is assembled before being installed in the LHS body with 4 small screws.

Once the main guts are installed, with the Arduino and MP3 player temporarily located, then the fun begins - wiring!

Step 6: Wiring

V5 - Radio option (Red turret photos). This includes an nRF24L01 radio chip. Completely changes the Arduino pin wiring to accommodate all the connections. Details to come...

The final packaging is tight, so spending some time here figuring out wire lengths is well worth it. Most interconnecting wires I ended up with were between 3" - 4".

The LEDs are wired with the 220 Ohm resistors directly, followed by some shrink wrap, and some wiring twisting, then put aside, after they have been tested. I used light gauge wiring here as I had some lying around (CAT5 type communication wiring) and didn't want the visible wiring to be obtrusive.

The mechanical bits are mock fit in the shell, then wire routing is figured out, then cutting and prepping the wires is next.

I built the servo connectors so that I could plug in and replace servos if I ever messed something up and stripped the gears. This was definitely helpful after messing up during my first prototype.

Once happy with the bulk of the wiring, the LEDs were soldered up at the end. Then it's time to carefully stuff the wired assembly into one half of the shell. The last step is to solder the power connector to the power wires once it is all inside.

-- Important note: Make sure the wiring stuffed behind the Nano are not pressing on the reset button!! This will obviously cause problems and prevent the unit from operating properly. --

At this point, all wiring is done, but before final assembly, it is important to upload the code to the Nano and power it up to make sure the LEDs, servos and MP3 player all worked as designed. After that, it's time to put the rest of the mechanical bits together.

Step 7: Arduino Code

Code for Radio turret now shown. Will still work without MTC, but has all the goodies baked in!

The attached file is what I came up with to drive the unit as shown in the videos. I will keep tweaking to change the Turret's character and the way it behaves. Lots of options here.

I structured the code using subroutines that I call as needed. It keeps the main body clean and was pretty helpful when I was playing around with different characteristics. It helped me manipulate the code for different behaviours.

I also used lots of variables up front which helped me tweak and adjust parking positions and min and max ranges, for example.

I used the DFMiniMP3 library in my code. I tried other libraries, like the DFRobot one, but had issues, so went back to this one. It meant that I had to keep the 'static void' pieces to keep it functional. These aren't necessary for the operation, but hey, I'm no master coder. I would love to hear of another library that is similarly as simple and neat as the VL53LOX library. Let me know if you find a better way to do this!

As for sounds, the implementation is done in a simple way, by having a folder named "mp3" on the SD card, with the files names 0001.mp3, 0002.mp3, etc. The first four digits must be in this format, but you can add any suffix after that to help identify the particular sounds. See https://www.dfrobot.com/blog-277.html for an example. I've included a pic of my file names as used on the folder. The numbers correspond to the call-outs in the code.

The sound files I pulled from the Wikipedia page on Portal Turret sounds. The code pics a random sound file (1 of 2, or 3 sounds) to keep things from getting stale.

Would love to hear or see cool implementations of other code. One idea I think I might try is to interconnect 2 or 3 of them wirelessly, such that triggering one turret will make them all wake up! Maybe adding a simple RF chip to the assembly? There's still some room in there... :)

Step 8: Final Body Assembly

This part is a bit tricky because of the black infill strips. The scale of the final assembly is small enough such that the strips and receiving grooves are tiny. This necessitated chasing the channel with a pointer or other small scraping implement to make sure the strips would fit with little resistance before trying to put the other side on.

Tying the wires together neatly and tie-wrapping as required will make this far easier.

I have put a couple of these together now and find it easier to put the two halves together first, then insert the infill strips. Insert one side into the half with the "shelf" that prevents the infill strip from falling in, then lightly pry open and gently press in. Not too bad now.

This was one of the trickier parts. Maybe one day, I'll rethink this assembly, but I do like the way it looks when done, and it is pretty robust.

Step 9: Wing Assemblies

Now that the body is together, with the wing LEDs sticking out, it is time to prep the wings and assemble.

It is imperative that the slider holes are chased with a 1/8" drill bit, then cleaned out. Clip the heads off the nails using bolt cutters, vise-grips, hacksaw or favorite nail-cutting tool. The slider pins (clipped nails) are installed into the wings by press fitting them into each wing piece. Straight, de-burred and smoothed nails are the key to making this work. The wing sliders and holes should be lubricated and tested before connecting the crank rods and running. Dry graphite, or other PLA suitable lubricant is recommended. I find that a small tube of personal lubricant works really well, and is cheap. It's really slick. It also requires for some 'splainin' when your partner or parent comes in and asks what exactly you need that for at the workbench!!

Start by figuring out which wing part goes where, and trial sliding that part first. Then fit the top and bottom halves together once the pins are installed, apply some lubricant (a q-tip works well for this) and make sure the wings slide well. This can be tricky, but without making sure the wings slide effortlessly, without binding, you'll be in for a frustrating time. Trust me...

Once the wings are good to go, it's just a matter of sliding them into place, locating the connecting rod over the hole in the wing and assembling with a single screw. Then, the LEDs are inserted into the gun holes, wires are tucked against the wing and you're ready to go! You can also use some hot glue to lock them into place once everything is tested.

Step 10: Scare and Shock Your Friends!!

The last little caveat on this design is that an angled plug is a great idea, since it doesn't interfere with the back leg when pivoting. The revised rear leg (v3) has been stretched to give a little more room.

Once built and plugged in (5V or suitable for Nano), it will sit quietly until someone is detected within the programmed distance, then spring to life and slay anyone who enters its domain!!

Let me know if you build one (or more) and if you come up with new features or concepts!

Step 11:

Toys Contest

Grand Prize in the
Toys Contest

Be the First to Share


    • Chocolate Challenge

      Chocolate Challenge
    • Go Big Challenge

      Go Big Challenge
    • Electronics Contest

      Electronics Contest



    Question 7 months ago

    To all,
    I'm really excited about this project and am close to getting all the electronics working! I'm not having any luck figuring out the power supply though so I bought the following adjustable power adapter from amazon:
    Belker 36W Universal 3V 4.5V 5V 6V 7.5V 9V 12V AC DC Adapter Power Supply 1A 1.5A 2A 2.5A 3A 3000mA Amp Max
    Connected to the Vin and tried from lowest to highest voltage settings. Nothing from the speaker from 3v to 7.5v. At 9v the speaker started to work until the three servos started firing so I tried 12v and it appears I might have fried something because nothing works now including the leds and tof sensor. While I try to figure out what got fried I would like to know if anyone else has gotten this to work and if so, what the exact specifications, volts, amps, watts, etc. or link is to the power supply that works with all of the components.
    Also, I was wondering if the stranded wires I'm using might be the problem? For the breadboard test, as shown in the picture, I am using the following from amazon that people say are 22 gauge:
    ELEGOO 120pcs Multicolored Dupont Wire 40pin Male to Female, 40pin Male to Male, 40pin Female to Female Breadboard Jumper Wires Ribbon Cables Kit Compatible with Arduino Projects
    Any suggestions from anyone would be greatly appreciated. Thanks!


    Question 7 months ago

    Why Does Sound Stop When Servos Activate?
    I have all the electronics from Step 4: Electronics on a breadboard for testing. I am using the diagram labeled "Portal Turret Gun - Radio option" but without the Radio and commented out the Radio code in Portal_Turret_Radio-RED_v1.ino. I am powering the board using the mini usb. As you can see in the attached video everything starts working fine until the servos start to kick in. Once the servos start to operate the sound stops working but everything else continues to work. If I disconnect all three servos then everything else works including the sound. I suspect that either the servos or the speaker is drawing too much power but I don't know how to analyze the circuit to verify this. Any ideas, recommendations, or suggestions on how to fix this? Thanks!


    Reply 7 months ago

    You will likely encounter problems when powering solely from the USB port on the Nano, with sound and servos asked to work at the same time. Servos and amp can draw a lot of current (particularly when servos loaded and volume high) and the nano can't always supply it when powered from USB port, so voltage will drop and you'll get clipping audio or other weird effects. It's why I use the Vin pin on the board with a good power supply (at least 2A) to feed the Nano, amp and servos.


    Reply 7 months ago

    I bought a 5v 2A power supply and connected it to vin but the sound still cuts out when the servos start going. A couple of questions: 1) How many volts and amps is the power supply for your turrets? 2) If you are using 5v/2A power supply, should I try a power supply with more volts, more amps, or both and what is the max for both so I don't fry anything?


    Reply 7 months ago

    Thanks for the quick reply! I'll find a 2A+ power supply to Vin. Once I get everything put together I'll post my results. I'm having lots of fun working on this and you provided great information on how to print and put together. Thanks!


    Question 8 months ago

    Arduino Nano? We just finished printing this project and are in the process of ordering the electronics. For the Arduino Nano can you tell me what versions work for this project? The only board I could find that looked like the one in the pictures posted above is this one I found on amazon: "ELEGOO Nano Board CH340/ATmega+328P Without USB Cable, Compatible with Arduino Nano V3.0 (Nano x 3 Without Cable)". Here is a link so you can see the specs: https://www.amazon.com/dp/B0713XK923/?coliid=IUDTJ...
    I included a picture of the one on amazon. Let me know if this would work or if anyone can provide a link to one that would work. Thanks!

    Follow up: The nano I found on Amazon fits perfectly in the body without any filing or other modifications! Also, other than the fact that I need a 2A+ power supply to Vin, it works great as you can see in my other post.


    11 months ago

    I am almost finished with this project but while testing everything on my breadboard, the 5V pin from USB is no longer enough to power servo, LEDs, and speaker... so while installing the power connector I purchased (https://www.amazon.com/NTE-Electronics-69-A9-Waterproof-Connector/dp/B008UTSRCG) I realized I have no idea how much voltage to put through, or where to get it from. Can anyone recommend me either a power source to solder this plug to or which brand plug you ended up using?



    Question 1 year ago on Step 6

    in V5 you added a Radio option.
    where are the wiring plans for V4? So i can build it without the Radio.



    Reply 1 year ago

    Hi Christian,
    I no longer have the code that goes with my old version, without the radio, so it wouldn't help you. You can build a version without radio by deleting the radio chip, and either commenting out or deleting the radio code.


    Question 2 years ago

    Awesome job, i'm planning to make it this week. There's à lot of stl, wich one do we need to priint and in what quantity please ? Is'the v4 zip enough with one of each ? Thanks for your work and for sharing it 😊


    Answer 2 years ago

    Hi clem,
    It's been a while, but yes, I believe I put the most recent files in one zip because it was an evolving project with evolving parts. I've also added a step file of the full model so people can hack the heck out of it too!
    Good luck and have fun!


    Reply 1 year ago

    Greetings Chris! If I don't have the radio does the schematic change at all? I did it all minus the radio. I'm working on building all the guts outside the body to be sure I know what I am doing and running into a few snags. Do I need to have an external power source vs usb? I read that you do or the speaker won't work properly, but I figured for testing I should be able to rig all this up and get it act accordingly. Awesome stuff!!! Thank you!!!


    Reply 1 year ago

    Hello there!
    It's been a while since I've looked at these turrets, so I hope the code has enough documentation to deal with the radio bits. If you built it according to the Feb 2019 wiring schematic, then I'd comment out all of the radio lines of code, until you can compile without error, otherwise I don't think it will run without the radio wired in. I had a version earlier on without the radio, but I believe the code for that was overwritten with the newer code so I don't have that any more. Progress!

    It's a good idea to test the guts outside the body, but you could also install them in one side of the shell to support it all while verifying that the servo's, lights, speaker and sensor all work. I recall doing that while testing initially.

    I run mine through the usb connector, but you will need a good power supply, one that can push out a couple of amps, otherwise the Nano supply voltage will drop and you will encounter problems, such as restarting whenever the speaker is turned on. The older versions of the knock-off Nano's I use have the mini USB connector and that works well for me. I'm not sure about the Nano variants that use the micro USB and how they would work in this current heavy environment. Mine still sit behind me, powered up and working since I built them, almost a couple years ago! Part of the fun with these projects, I guess.

    Good luck!


    Reply 1 year ago

    Brilliant!! THanks for the reply, its been grand fun working on them. I am new to this type of tinkering. I was having a few problems but finally soldered the ToF sensor and now it seems to be working / giving me proper readouts. I was attempting to bread board the ToF sensor and it wasn't booting it up. Solid so far, I didn't think to comment out the radio. I will do that and see how it goes!

    Itll probably be awhile, I was having some weird issues with the servos not acting properly just tested by itself and they are all working properly, re-do it with the new commented code out.

    Its been good fun though!


    1 year ago

    Hi ChrisN2019,
    I had some few problems with my turret.
    First, the pitch part is too heavy for the wings. The parts are not center so the wings lean on the side.
    Second, after few utilisation, the pitch broquen.
    Can you try to make something or is it possible to get the Fusion360 file to modify it by myself ? I would really like to be able to design a portal 2 turret from your work ^_^
    Thanks in advance and have a nice day


    2 years ago

    First of all, very nice project! As a portal fan I found this really awesome. :-)
    While the project is well documented, it was still hard to replicate.

    Most of all, I found the tolerances of the 3D prints too tight. My printer is tuned quite well, but still a lot of sanding and tweaking was needed to make everything fit. Especially the black infill strips did not fit at all.
    Because of this, the TOF sensor doesn't fit properly and is triggered by reflections on the turret body itself. I ended up solving this by changing the trigger distance.
    A zip file with the mp3 files and the correct arduino libraries would also be welcome :-)


    Question 2 years ago

    Hi! Great job! I'm doing the project (version without radio) using all the instructions, the diagrams and the Portal_Turrtet_Trials.ino but not all the components are working. I think is because i do not have all the libraries that u use. "Arduino.h" for example. Can u help me, pls? Thanks


    3 years ago

    hi your job is amazing, i'm almost finishing it but i'm getting this error over and over:
    Arduino: 1.8.9 (Windows 10), Placa:"Arduino Nano, ATmega328P"
    In file included from D:\UEM\Impressora 3d\Portal+Turret+v4\Portal_Turret_Radio-RED_v1\Portal_Turret_Radio-RED_v1.ino:23:0:
    D:\UEM\5 Quinto Ano\Arudino\libraries\DFPlayer_Mini_Mp3_by_Makuna\src/DFMiniMp3.h: In instantiation of 'uint16_t DFMiniMp3<T_SERIAL_METHOD, T_NOTIFICATION_METHOD>::listenForReply(uint8_t) [with T_SERIAL_METHOD = SoftwareSerial; T_NOTIFICATION_METHOD = Mp3Notify; uint16_t = unsigned int; uint8_t = unsigned char]':
    D:\UEM\5 Quinto Ano\Arudino\libraries\DFPlayer_Mini_Mp3_by_Makuna\src/DFMiniMp3.h:97:27: required from 'void DFMiniMp3<T_SERIAL_METHOD, T_NOTIFICATION_METHOD>::loop() [with T_SERIAL_METHOD = SoftwareSerial; T_NOTIFICATION_METHOD = Mp3Notify]'
    D:\UEM\5 Quinto Ano\Arudino\libraries\DFPlayer_Mini_Mp3_by_Makuna\src/DFMiniMp3.h:329:17: required from 'void DFMiniMp3<T_SERIAL_METHOD, T_NOTIFICATION_METHOD>::sendPacket(uint8_t, uint16_t, uint16_t) [with T_SERIAL_METHOD = SoftwareSerial; T_NOTIFICATION_METHOD = Mp3Notify; uint8_t = unsigned char; uint16_t = unsigned int]'
    D:\UEM\5 Quinto Ano\Arudino\libraries\DFPlayer_Mini_Mp3_by_Makuna\src/DFMiniMp3.h:152:19: required from 'void DFMiniMp3<T_SERIAL_METHOD, T_NOTIFICATION_METHOD>::setVolume(uint8_t) [with T_SERIAL_METHOD = SoftwareSerial; T_NOTIFICATION_METHOD = Mp3Notify; uint8_t = unsigned char]'
    D:\UEM\Impressora 3d\Portal+Turret+v4\Portal_Turret_Radio-RED_v1\Portal_Turret_Radio-RED_v1.ino:191:20: required from here
    D:\UEM\5 Quinto Ano\Arudino\libraries\DFPlayer_Mini_Mp3_by_Makuna\src/DFMiniMp3.h:421:63: error: 'OnUsbOnline' is not a member of 'Mp3Notify'
    D:\UEM\5 Quinto Ano\Arudino\libraries\DFPlayer_Mini_Mp3_by_Makuna\src/DFMiniMp3.h:432:65: error: 'OnUsbInserted' is not a member of 'Mp3Notify'
    D:\UEM\5 Quinto Ano\Arudino\libraries\DFPlayer_Mini_Mp3_by_Makuna\src/DFMiniMp3.h:443:64: error: 'OnUsbRemoved' is not a member of 'Mp3Notify'
    exit status 1


    Reply 2 years ago

    In the Arduino IDE, open up the example PlayMP3 under "Dfplayer Mini MP3 by Makuna". Copy the class Mp3Notify and use it to replace the one in the original code by Chris. It has several OnUsb_ lines that were missing. Worked for me. Maybe we are using a different/newer version that Chris.