Introduction: The Aperture Science Sentry Turret With an Arduino

This instructable was created in fulfillment of the project requirement of the Makecourse at the University of South Florida (www.makecourse.com)

Ever since I first played Portal when it released on the Orange Box, I've always been obsessed with the game. The turrets in particular have remained my favorite characters in any game to date and I've always imagined how cool it would be to have one of my own. So when I signed up for the Makecourse at the University of South Florida, and they told me I could make my project whatever I wanted as long as it used an arduino and had a 3D printed part, the choice was very clear to me.

My project had 3 main requirements:

  • The arms pop out
  • The turret speaks
  • The turret uses a proximity sensor to govern its functioning


This was no easy feat for me, as it was my first time working with pretty nearly all of the technology I'd be using, and I definitely made it harder on myself than it needed to be, but all things considered, I think it turned out pretty well. I wanted this project to be a learning experience, so I tried to use an extremely diverse tool set and approach to making things, just to familiarize myself with all of the different ways you can create things.

If you have the resources, I recommend you save yourself the hassle and 3D print as many of the parts that you can. Keep in mind this project was made over the course of 16 weeks, so I wouldn't say this is really a weekend project.

That being said, lets jump right into the build.

Step 1: Tools & Supplies

Tools & Supplies:

  • Clamps (recommended)
  • 3 axis CNC Mill (optional)
  • Jigsaw (optional)
  • Laser Cutter (optional)
  • 3D printer (highly recommended)
  • Rotary tool
  • Sandpaper; 200 & 400 grit
  • Dowel rods
  • Wood filler
  • Krylon fusion spray paint-primer semigloss white (for the plastic. Don't waste your money using this on wood)
  • Cheap white and black semigloss spray paint
  • Scrap wood
  • Superglue
  • Epoxy
  • Hot Glue/ E600
  • Soldering Iron (as needed)
  • Zip ties (optional)
  • 6 x AA batteries (power the breadboard)
  • Portable phone charger (power the Arduino)


Parts to get online:

2 x KY-008 Laser Dioide: https://www.amazon.com/HiLetgo-KY-008-Transmitter...

1 x HC-SR04 Ultrasonic Sensor: https://www.amazon.com/SainSmart-HC-SR04-Ranging-...

1 x Arduino Uno R3: https://www.amazon.com/Arduino-Uno-R3-Microcontro...

4 x MG996R Digital Metal Gear Servo: https://www.amazon.com/Arduino-Uno-R3-Microcontro... 1 x Df Player: https://www.amazon.com/Arduino-Uno-R3-Microcontro...

1 x Spare speaker: I pulled mine from a bluetooth shower speaker like this one https://www.amazon.com/Arduino-Uno-R3-Microcontro...


Reminder:

I highly recommend you 3D print all of the parts you can, even if it means slicing the part into sections and using adhesive to bind it together.

Step 2: The Mechanical Design

The designing of this was all done in Solidworks, since I am a university student, we get a free student edition of the program.

I wanted the turret to have as much movement as possible, so when designing this turret I had to keep that in mind. First and foremost, the arms had to pop out, so I made a box that is mounted in the center by a pin and holds the a servo, that attaches to a gear, which moves a rack along a slot and pushes the arms out.

Next, I wanted to make sure the arms could move left and right, so I designed the inside of the panels in such a way that you could mount a servo in it, and connect it to the rack and pinion system, so when the gear turns and sends the arms out, it pushes out the servo as well, which is connected to the arm panels.

Finally, I wanted it to be able to pitch up and down, so on the bottom of the carrier box that holds the rack and pinion system, I made a hanging slot. Then I made a linkage mechanism that connects to the bottom servo, and moves a pin along the inside of that slot. So as the servo tilts forward and backward, the arms tilt up and down.

Because these specifications were made with 9g microservos in mind, some modifications will need to be made to the arms, and the central housing of the turret to make sure everything fits. If you are planning on using the same servos I used, I would highly recommend scaling everything up by at least 30%, and modifying where the servos are mounted on the arms. I decided last minute that I wanted larger servos, and as such did not have enough space for the bottom servo to fit in the housing.

Attached are the STLS which can be printed on any size 3D printer that will print it.

Step 3: Printing the Parts:

After I finished the design. I began 3D printing all of my parts. I sanded them each with 200 grit sand paper as each part came out.

Since the outside panels were to large to print full size on the Z18 we have at my school, I had to cut the parts up in Solidworks, and print the panels in halves. Then I would later join them with epoxy.

Originally, I planned on printing the center of the body on the Z18 as well, but when I returned to load my print in, I discovered the printer had been broken, and as such, I would need to find another way to make the body of the turret.

Step 4: Machining the Body

Luckily for me, I know how to use a CNC mill and have open access to one at all times. So when it came to making the body, I decided, I would simply machine it out of wood.

I found some low quality scrap plywood at that was about 1/2 inch this work and cut it into five pieces of wood ( the picture shows four, but I went back and cut another piece). Each piece was about 8.5in x 13.5in x.5 inches in size.

After that I spread wood glue on each piece and clamped them together to make a block of wood that I would then mill the body out of.

Once the block was all glued, and I had finished with the CAM software, I squared off the edges of the block, put it in the vice, and ran it through the machine to be milled.

Once I milled the left side, I cut off the excess material with a saw and used a belt sander to finish up the shape.

I then repeated this process for the other side of the body.

Step 5: Painting and Partial Assembly

Before painting all of my parts, I sanded them all with 200 grit sandpaper, and then filled in any noticeable gaps with wood filler. Once the wood filler dries, lightly sand it once more, and it will be good to paint.

I recommend using Krylon Fusion paint-primer if you're going to be painting any sort of plastic, but would switch to something cheaper when painting the wood parts.

Once the parts seemed appropriately smooth, I laid them down on scrap paper and cardboard, and begin to coat them with spray paint. I would paint two layers, then sand away any abnormalities with 400 grit sand paper, and hit it once more with another two layers of paint.

Additionally, I would flip the center pieces over, and paint the legs, and inside of the body with black spray paint.

Once these were painted, I took the two center pieces, wood glued them together and put them in a vice to set.

Once that was done, mounted the legs in the holes with superglue, waited for it them to dry. I then added E6000 to anchor them in. Once the legs were in place I left the turret hanging on some metal bars in order to let the E6000 set for 48 hours without the weight of the body on it.

Step 6: Circuit and Wiring

The concept:

The whole idea behind this turret is that I really wanted to give it as much functionality as possible, and I wanted it to perform some sort of tracking operation like a real turret would, with as many degrees of freedom as possible. Originally the plan was to run a webcam through the arduino and use motion tracking software (Open CV) to control the servos and tell them where the lasers on the arms should be pointed. I later found out that this isn't a task best handled by an arduino, and would be better suited for something along the lines of a raspberry pi. I hope to revisit this in a later revision of the turret or possibly a complete rebuild.

With the possibility of webcam tracking nullified, I realized the best way for me to get some sort of accurate position based tracking was to have all of the servos move in response to distance readings that were being measured by an HC-SR04 proximity sensor. The main problem with the ultrasonic proximity sensor is that it only has about 30 degrees of vision, and can only tell distance as a flat number. A single proximity sensor alone will not be enough to tell the turret if the person is on the left, the right, or directly in front of the turret. So as it stands now, the servos only move and track as a person approaches it directly from the front. If you want left and right tracking as well, I would suggest mounting PIR sensors in some sort of array and using them to determine which side an object was on.

The circuit:
I set up the circuit in such a way that it allows for 4 separate servos. One servo opens the arms out, a servo in each arm controls where the lasers are pointing, and one servo in the bottom of the turret that controls the pitch up and down. (The bottom servo was removed do to size constraints, but the algorithm for the bottom servo's tracking still exists in the code, so if you upscale the design of the turret enough for the bottom servo to fit, it will tilt up and down relative to the distance read out by the proximity sensor).

I could not find a module to in fritzing for the df player but I ran my wiring setup the exact same way as the example picture shows. You can set your servo pins to whatever digital pins are available, they don't necessarily need to be the ones I have marked. I would recommend keeping the same triggerPin, echoPin, tx, and rx pins, as in my code though, since the libraries seem to be configured to those pins.

With all of these servo's, there is a lot of current being drawn, so it's important to note that I have not only a 6AA batteries powering the breadboard directly, but also an external battery powering the arduino separately. I highly recommend using external power sources with on/off switches.

IMPORTANT NOTE:
Run your df player on a separate breadboard than the servos. The amplifier on the df player seems to melt the breadboard when other components are added to it. I learned this the hard way.

Step 7: Full Assembly

Once the wiring had been complete and the body had been mostly assembled, it was time to put the turret together with all of its electrical components.

I used super glue to mount the servos to the arms, and then used superglue again to mount the servos to the pinion. All other pieces would then go in their respective places. Additionally, a hole would be cut in the back in order to route the path of the wires.

The turret is now fully assembled at this point

Step 8: The Code

If you've made it this far in the build, then you're ready to upload your code. Essentially what this code does is it will track your movement between a distance of 150cm and 300cm. If you go beyond 300cm it will scan the room 5 times, and then shut down if no object closer than 300cm is detected. If you are closer than 150cm, the arms will begin to move back and forth frantically in a spraying motion. There is a unique voice line for each of these scenarios that play and these voice lines can be replaced with anything you want them to be.

Step 9: The Final Product

Here you'll see the turret turn on, open up, and then switch between the tracking code and the spay pattern code based on the distance determined by the proximity sensor.

Design Now: In Motion Contest

Runner Up in the
Design Now: In Motion Contest

Robotics Contest 2017

Second Prize in the
Robotics Contest 2017