Lego Nerf Arduino Turret
The inspiration behind this project came from a desktop turret they sell at staples, and a couple servos I had lying around. Many a time I have been told that Lego's are no good for building something serious (like a robot), so hopefully they will be proven wrong.
Make a Plan
The turret will need at least to servos two pan and tilt, a servo for the trigger, a ton of legos, and an arduino. However the specifics can vary quite a bit. Especially when it comes down to the legos.
This turret calls for:
1.) two HS-322HD servos --- $9.99
2.) a small servo of any variety --- $8.95
3.) an Arduino Uno --- $25
4.) Nerf Gun --- $6 this is a Nerf reflex. This one works great because of small size and flat side for gluing)
but make sure to have:
1.) Plastic Epoxy --- $5.50
2.) a Computer
3.) a Box of Legos
4.) PS1 controller
5.) PCB board and Breadboard
6.) also there will be some soldering and desoldering
So all in all it should cost about $50 if you have Legos
This project is pretty tough and took about four whole afternoons to build so it will take a while. Be ready to commit to it (plus you will have to ruin some precious Legos :( ).
This turret calls for:
1.) two HS-322HD servos --- $9.99
2.) a small servo of any variety --- $8.95
3.) an Arduino Uno --- $25
4.) Nerf Gun --- $6 this is a Nerf reflex. This one works great because of small size and flat side for gluing)
thanks to nerfrocketeer for gun name and price
but make sure to have:
1.) Plastic Epoxy --- $5.50
2.) a Computer
3.) a Box of Legos
4.) PS1 controller
5.) PCB board and Breadboard
6.) also there will be some soldering and desoldering
So all in all it should cost about $50 if you have Legos
This project is pretty tough and took about four whole afternoons to build so it will take a while. Be ready to commit to it (plus you will have to ruin some precious Legos :( ).
Build the Frame
Now where you go after you get everything you need is really up to you. From here the project may split to building the turret, or maybe create the code so if you would rather play with the servos and Arduino first go for it!
However, here is how build the turret first. To allow the gun to tilt, the gun and a servo have to be floating and only connect to the rest of the structure by a servo, and a point opposite and parallel to the servo that can freely turn. The structure will still need support so build a frame!
Using 2 X 3 Lego bricks make a the outline of a square or rectangle two bricks high. The size is dependent on the nerf gun so use it as a guide ( make the frame a little bit bigger than the gun). servo is much easier to convert into a Lego than you would think. The 1 X ? bricks will glue perfectly into the
HS - 322 and allow it to connect to the frame.
On the opposite side of the servo, two bricks with a hole and an axle can be used to connect the frame and the nerf gun without restricting rotation.
However, here is how build the turret first. To allow the gun to tilt, the gun and a servo have to be floating and only connect to the rest of the structure by a servo, and a point opposite and parallel to the servo that can freely turn. The structure will still need support so build a frame!
Using 2 X 3 Lego bricks make a the outline of a square or rectangle two bricks high. The size is dependent on the nerf gun so use it as a guide ( make the frame a little bit bigger than the gun). servo is much easier to convert into a Lego than you would think. The 1 X ? bricks will glue perfectly into the
HS - 322 and allow it to connect to the frame.
On the opposite side of the servo, two bricks with a hole and an axle can be used to connect the frame and the nerf gun without restricting rotation.
Preparing and Gluing the Gun
To turn a nerf gun into a lego brick takes some work.
with the n - strike attack gun I used it was pretty straight forward. First remove the hand grip which is just three screws.
Clean off one side with rubbing alcohol, making sure that one side is not the one with the screws because you might want to get on the inside of the gun later (I cut down the spring so it wouldn't fire so violently).
Next, pick the bricks that will be sacrificed - the more, the better. Two columns of 2X2 bricks 5 long should be enough, so take a flat piece and connect all the bricks into it, cover them in epoxy (wear gloves and protect surface), and then place the gun on the glue. Once again, try not to make it impossible to get into the inner workings of the gun. Put some weight on top of the gun like a rock, and let it dry for a day, don't worry there is plenty more to do. (consider checking out step seven)
The Trigger Servo
A Smaller Servo is Needed Here:
It should wedge just great into the trigger guard, but also consider cutting or sanding away a little grove for it to make a snugger fit (in picture it is held down by epoxy and a screw).
An Extra Note:
For the servo to actually pull (in this case push) the trigger it may be necessary to add some thickness to whatever blade is on the servo. So put a screw or bolt through it.
It should wedge just great into the trigger guard, but also consider cutting or sanding away a little grove for it to make a snugger fit (in picture it is held down by epoxy and a screw).
An Extra Note:
For the servo to actually pull (in this case push) the trigger it may be necessary to add some thickness to whatever blade is on the servo. So put a screw or bolt through it.
Install the Gun
After the Glue Drys :
Create a platform out of plank pieces that will fit well in the space of the frame, the gun which is now a modified lego brick can be attached.
To attach the servo, simply place some lego pieces down, mark a few points, pre-drill, and screw the servos in.
The HS - 322 seem to work well if left a five point gap, as can be seen in the picture above.
Create a platform out of plank pieces that will fit well in the space of the frame, the gun which is now a modified lego brick can be attached.
To attach the servo, simply place some lego pieces down, mark a few points, pre-drill, and screw the servos in.
The HS - 322 seem to work well if left a five point gap, as can be seen in the picture above.
Pan Servo
Pan Servo Time:
Screw the pan servo into some 1X8 bricks... one per side and make sure the connections are pointing away from the white connector.
To help strengthen it up use a couple plank pieces to hook the 1X8's together, and then use whatever combination of bricks you'd like to connect this to the bottom of the frame.
The servo can connect to any large lego piece on bottom the same way the tilt servo worked, a plank piece with single width (I went with a 1X2 plank for this).
this bottom piece will be the base so make sure it is large, heavy, and stable.
A Note on Placement of the Servo:
It may not be best for it to be perfectly centered so consider your center of mass with the frame and gun platform, and place the servo directly under that.
Screw the pan servo into some 1X8 bricks... one per side and make sure the connections are pointing away from the white connector.
To help strengthen it up use a couple plank pieces to hook the 1X8's together, and then use whatever combination of bricks you'd like to connect this to the bottom of the frame.
The servo can connect to any large lego piece on bottom the same way the tilt servo worked, a plank piece with single width (I went with a 1X2 plank for this).
this bottom piece will be the base so make sure it is large, heavy, and stable.
A Note on Placement of the Servo:
It may not be best for it to be perfectly centered so consider your center of mass with the frame and gun platform, and place the servo directly under that.
PS1 Controller Desoldering
thanks to blaze3927 from benheck.com Forums because I took my controller apart a long time ago and this picture is perfect.
Decided to go crazy on the html here since the instructable is getting a little long :)
Once you rip apart your precious ps1 controller you will see the joysticks, they are on there own little boards. Each one is attached by six pins for use in the joystick, and a couple structural ones.
Ps1 Joystick ... All Wired Up
Joysticks, at least in this case, are two potentiometers (or variable resistors). If you want to learn more check out this link.
The middle pin is signal the outside being positive or negative for both the pot's on the joystick. To test it out just give one outside pin 5v's, the other outside ground, and the middle goes to an analog pin on the Arduino. Fire up an example and have fun.
Consider soldering the joystick to a piece of pcb like what it was found on to make it look a little nicer.
The middle pin is signal the outside being positive or negative for both the pot's on the joystick. To test it out just give one outside pin 5v's, the other outside ground, and the middle goes to an analog pin on the Arduino. Fire up an example and have fun.
Consider soldering the joystick to a piece of pcb like what it was found on to make it look a little nicer.
Also remember that when bread boarding to pot's you can use the same ground pin but you will want to use two pins to power them (they are resistors and change the voltage when moved, if in series one effects others signal).
Breadboard!!
If you are new to bread boarding don't worry, but also don't try this all at once. Build up to this with one servo, one pot, a pot and a servo so on so on. (knob and sweep examples in Arduino IDE should help)
Already described the potentiometers.
The servos can have different colors of wires but they all mean the same three things... Power, Ground, and Signal. Check this link out if you need any help.
Servos can share the same power and ground which helps out with the wiring.
Don't forget to use 22 gauge wire anything larger size, smaller gauge can ruin the holes in breadboard or Arduino.
Already described the potentiometers.
The servos can have different colors of wires but they all mean the same three things... Power, Ground, and Signal. Check this link out if you need any help.
Servos can share the same power and ground which helps out with the wiring.
Don't forget to use 22 gauge wire anything larger size, smaller gauge can ruin the holes in breadboard or Arduino.
Code... Almost Done!
Here are a couple bits of code. For even simpler stuff check out the servo examples and smoothing example in the Arduino IDE.
First is a chunk used for the trigger
#include <Servo.h>
#include <Servo.h>
First is a chunk used for the trigger
#include <Servo.h>
Servo myservo; // initiate an instance of Servo class
byte byteRead;
int pos = 0;
void setup() {
// Turn the Serial Protocol ON
myservo.attach(3);
myservo.write(0);
Serial.begin(9600);
}
void loop() {
/* check if data has been sent from the computer: */
if (Serial.available()) {
/* read the most recent byte */
byteRead = Serial.read();
/*ECHO the value that was read, back to the serial port. */
if (byteRead = 'F');
{Serial.println("fire");
for(pos = 0; pos < 120; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 120; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}
}
Next is the full on code for the turret, keep in mind to fire this you type F into the serial port that is what the above code tests.
There are also commented out Serial.println() lines of code. If yuncommented they can be used to debug and gather numbers from pot's.