Introduction: Arduino-Controlled Self-Targeting Sentry Mount
In this project we build a really easy, low-cost, low-complexity, high-functionality automatic targeting mount for any purpose you require. When someone or something comes near the device, it magically (not really) swivels around to face the intruder, ready to bombard them with whatever you have hooked up to the mount, be it water, nerf darts, plastic balls, or something more nefarious.
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Assemble the Minions! (Supplies)
For this project you will need:
HC-SR04 Ultrasonic Sensors: http://www.amazon.com/gp/product/B0089VB326/ref=oh...
These babies are extremely cheap, fairly small, and work very reliably. For this project we only need three, but they are a great addition to your kit.
Adafruit Pro Trinket 5v: http://www.amazon.com/Adafruit-Pro-Trinket-5V-16MH...
This is a very popular Arduino Uno-like board that is nice and small, but still has essentially the same functionality as a full Uno. You can also buy it from Adafruit's online shop. Note: this will require some setting up on your computer (not hard at all) before you can upload code to it using the Arduino IDE
Micro USB Cable: http://www.amazon.com/AmazonBasics-USB-Cable-Micro...
This is the cable you need to interface with the Pro Trinket. It doesn't need to be very long to upload code, but we will be using a six-foot one because we will power the pro trinket using this as well, and we will want a nice long leash in case there are no power outlets in close proximity.
USB Wall Adapter: http://www.amazon.com/I-Qs-Black-Power-Adapter-Cha...
For use in powering the trinket.
This is what the mount will be attached to.
Male to Female Jumper Wires: http://www.amazon.com/FOXNOVO-2-54mm-Female-Arduin...
We will be using a lot of these. We won't need all 40, but I couldn't find a smaller pack. Besides, they're not that much anyways.
Male to Male Jumper Wires: http://www.amazon.com/FOXNOVO-2-54mm-Female-Arduin...
We will only use a couple of these, but again, I couldn't find a smaller pack and they're not expensive at all.
Miniature Breadboard (Isn't it cute?): http://www.amazon.com/heartsea-technologyRed-Solde...
This is pretty self-explanatory. We will be attaching all the components using this.
Hot Glue Gun and Glue Sticks
If you're planning on putting something on the mount right away, you will probably need a few more things. In this project I set up the mount as an auto water-shooter, so I bought a small pump from Amazon and a small motor driver to power it (you cannot power motors directly from the pins on your Arduino!). You can see some of the equipment in the above picture. Technically I will not be covering how to do this, but the functionality is included in the code for you.
Step 2: Attach the Wires
Break off three groups of four wires each of the male to female jumper wires. Technically you do not need to have all four wires still together, but it makes everything more organized. Plug the male headers on the HC-SR04s into the female ends of each of the wires. If the sensors' headers are pointing straight back (parallel to the barrels), you will need to bend them 90 degrees so they are all pointing down, which is parallel to the circuit board. Also stick the pro trinket into the breadboard. You may also need to plug some of the male to male jumper wires into the female headers of the servo.
Once this is done, use a sharpie to label (in small numbers) the barrels of each ultrasonic sensor one, two, and three. This will be used to identify them later.
Step 3: Hook It All Up!
Using the above diagram, hook up all the parts. For reference, below is a list of where the pins go. In small letters on the ultrasonic sensor you will see various labels. Use that to identify what pins are Voltage In (vcc) Trigger (trig) Echo (echo) and Ground (gnd).
Attach the gnds on the sensors to the ground on the trinket. Also attach the ground on the servo (most likely the darkest wire) to the trinket's ground.
Attach all the vccs to the pin labeled "5v" on the trinket. On the servo, this is probably the wire next to the ground.
Here is how all the control pins go: (identify which sensors are 1, 2, and 3 based on the labels you added to the sensors in the previous step)
trig1 = 5
echo1 = 4;
trig2 = 13;
echo2 = 12
trig3 = 6
echo3 = 8
servo = 11
(the motor driver shown in the real photo is optional)
Step 4: We're All About (building) That Base.
It's time to get started building the mount for your mount.
!!!!!!!(All measurements are in inches)!!!!!!!
-Do all the drawing in light pencil-
-Cut out a 5x5 piece of cardboard. (Image 1)
-On one of the sides, make small marks at 2 and 3 inches. (Image 2)
-If that side is the top, then on the two adjacent sides make a mark at 2 inches. (Image 3)
-Connect the mark at three inches on the top with the mark on that side of the cardboard, and repeat for the other side. Connect with a light line. (Image 4)
-Cut along both lines, so you have a hexagon. Using the pencil, trace the outline onto another piece of cardboard, and cut that out. One of these will end up being the top, and the other the bottom. (Image 5)
-Using a piece of cardboard at least 2.5 x 8, starting from one edge measure along the length of the first cut mark you made, and make a small mark where the end is. (Image 6)
-Starting from the mark you just made, measure the length of the smaller top of the shape and make another mark. (Image 7)
-Using that mark as a start point, measure the length of the remaining cut, and make another mark. (Image 8)
-On the adjacent sides of where you made the mark, measure 2.5 inches down each side, and connect it with a line. (Images 9 + 10)
-Cut straight down to this line on all the marks you just made, then cut along this line to free the pieces. (Images 11 + 12)
-Make notches wide enough in the tops of each piece to allow the wires of the ultrasonic sensors to pass through. (Image 13)
-Next, hot glue these pieces you just cut, with the notches on top, to the larger piece that you decided was the base. (Image 14)
-Hot glue the sensor two shown in the middle, and glue the wires to the inside of the device as shown. (Images 15+16)
-Repeat for the other two sensors (facing the device, sensor one should be on the left). (Image 17)
-Then, glue the breadboard down as shown. (Image 18)
-Trim off the remaining cardboard on the back. (Image 19)
-Make a small square, in the top of the device that you haven't glued down yet, big enough to fit the wires for the servo. The servo should be placed as shown, with the square off to the side. Cut this out. (Images 20 + 21)
-Glue the top on. (22)
-Disconnect the servo wires, pass them through the hole, then reconnect them. (23 + 24)
-Before you glue the servo in place, make sure that you are facing the correct side outwards by moving the plastic piece that came with the servo that attaches to the top along the range of the servo's motion. When you glue down the platform to this plastic piece, it should be pointing outwards and should be able to move about 180 degrees, swinging from sensor one all the way to sensor three. Once you are positive it works, glue down the servo and glue any size cardboard platform to the top of the servo's plastic thingy. (25)
-Make the back, like shown in image 26. The bigger hole closer to the middle is for my usb cable, and the smaller hole on the side is for the optional motor driver that I connected. DO NOT GLUE THIS ON YET! To upload code to the pro trinket, you will need to be able to access the reset button which would be covered by the back.
Step 5: Upload the Code!
Upload the attached code to your pro trinket by following the instructions provided by Adafruit. This may require some work. If you get the error that the device cannot be found, then make sure to press the reset button just before uploading code. If you are experiencing any other problems uploading code, please contact Adafruit, not me.
Lets take a look at all the sections, shall we?
-The most important part of this code is probably the threshold and positions. int threshold specifies the distance at which the sensors kick into action. The HC-SR04 can reliably measure distance up to 200 cm, so set this value accordingly. In my program, the distances are in cm.
-The positions are all measured in degrees. The servo has a range of motion of about 0 degrees to 180 degrees, so set these accordingly.
-For the pins, if you followed my instructions in the hooking up the connections part these should all be fine. int pump is used to define the motor control pin for whatever you mount on top of the sentry mount. The function spray() is what I used to set up a water cannon, but you can customize this to do whatever you want! Read the comments for more info on everything.
-First, make sure everything works like it is supposed to. As you sweep your hand across the ultrasonic sensors, the platform should follow, and as you approach one sensor individually it the platform should swing to face you.
-If this is all good, then go ahead and glue on the cardboard back.
Step 6: We've Done It!
And there you have it! A fully-functional automatic targeting mount for whatever your heart desires. Don't know what to put on it? Here are some suggestions:
-A water sentry
-A nerf gun
-A ball shooter
-A paintball gun
-An airsoft gun
-A camera for home security
-Anything else needed to defend your home from marauding and malicious intruders! (flamethrowers not endorsed)
-Set up multiple sentries to really show the bad guy(s) who's boss!
Please show your support here on Instructables by liking, sharing, and commenting! If you have any questions, feel free to post them in the comments.
Participated in the
Small Spaces Contest
Participated in the
On a Budget Contest
Participated in the