Arduino Nerf Target Practice
by Jonathan Robson in Outside > Launchers
4693 Views, 25 Favorites, 0 Comments
Arduino Nerf Target Practice
Arduino + 2 servos + laser
Switch it on and the servos move to a random position and turn on the laser target. You have 2 seconds to hit it before it switches off and moves to a new random position. Servo positions are limited to 0 to 180 degrees on the x-axis and 90 to 180 degrees on the y-axis so that as long as you stand behind it targets will all appear in front of you and there's no danger of getting zapped by a laser in your eye!
Switch it on and the servos move to a random position and turn on the laser target. You have 2 seconds to hit it before it switches off and moves to a new random position. Servo positions are limited to 0 to 180 degrees on the x-axis and 90 to 180 degrees on the y-axis so that as long as you stand behind it targets will all appear in front of you and there's no danger of getting zapped by a laser in your eye!
http://youtu.be/e2r4px3w7dE
Build It
1: Servos
I've used a pan-tilt mechanism but it will work just as well by sticking one servo to the rotor arm of the other. Attach the x-axis servo control wire to Digital 8 pin and the y-axis servo to digital 9. For both servos the positive wire goes to 5v pin and ground to GND, both viaa breadboard.
2: Laser
Positive wire goes to digital 4 pin and ground to GND via the breadboard. I added a target shaped lens to the laser which came with a cheap laser pointer.
3: Power
Add a 9v battery. Ground wire goes to GND via the breadboard and positive goes to VIN pin via any kind of on/off switch.
4: Packageing
Put it all in a plastic food storage box or similar, cutting holes for the switch, servo and wires.
I've used a pan-tilt mechanism but it will work just as well by sticking one servo to the rotor arm of the other. Attach the x-axis servo control wire to Digital 8 pin and the y-axis servo to digital 9. For both servos the positive wire goes to 5v pin and ground to GND, both viaa breadboard.
2: Laser
Positive wire goes to digital 4 pin and ground to GND via the breadboard. I added a target shaped lens to the laser which came with a cheap laser pointer.
3: Power
Add a 9v battery. Ground wire goes to GND via the breadboard and positive goes to VIN pin via any kind of on/off switch.
4: Packageing
Put it all in a plastic food storage box or similar, cutting holes for the switch, servo and wires.
Code
// Nerf Target Practice
// J Robson
// www.jrobson.me
#include <Servo.h>
Servo myservo1; // x- axis servo
Servo myservo2; // y- axis servo
int pos = 0; // variable to store the servo position
long randNumber; // Initialise a variable for a random servo position
void setup()
{
myservo1.attach(8); // attaches the x axis servo on digital pin 8
myservo2.attach(9); // attaches the y axis servo on digital pin 9
pinMode(4, OUTPUT); // attaches the laser to digital pin 4
}
void loop()
{
myservo1.write(randNumber = random(0, 180)); // servo to random position on the x axis between 0 and 180 degrees
delay(500); // waits half a second for the servo to reach the position
myservo2.write(randNumber = random(90, 180)); // servo to random position on the y axis between 90 and 180 degrees
delay(500); // waits half a second for the servo to reach the position
digitalWrite(4, HIGH); // turn on the target laser
delay(2000); // target laser stays on for 2 seconds
digitalWrite(4, LOW); // turn off the target laser
}
// J Robson
// www.jrobson.me
#include <Servo.h>
Servo myservo1; // x- axis servo
Servo myservo2; // y- axis servo
int pos = 0; // variable to store the servo position
long randNumber; // Initialise a variable for a random servo position
void setup()
{
myservo1.attach(8); // attaches the x axis servo on digital pin 8
myservo2.attach(9); // attaches the y axis servo on digital pin 9
pinMode(4, OUTPUT); // attaches the laser to digital pin 4
}
void loop()
{
myservo1.write(randNumber = random(0, 180)); // servo to random position on the x axis between 0 and 180 degrees
delay(500); // waits half a second for the servo to reach the position
myservo2.write(randNumber = random(90, 180)); // servo to random position on the y axis between 90 and 180 degrees
delay(500); // waits half a second for the servo to reach the position
digitalWrite(4, HIGH); // turn on the target laser
delay(2000); // target laser stays on for 2 seconds
digitalWrite(4, LOW); // turn off the target laser
}
Shoot!
Load up a Nerf gun, stand BEHIND the device with the laser pointing AWAY from you and switch it on. It'll keep on giving you targets to shoot at until you switch it off or the battery runs out.