Introduction: 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!

http://youtu.be/e2r4px3w7dE

Step 1: 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.

Step 2: 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
  }

Step 3: 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.

Comments

author
PeckLauros (author)2013-06-05

I would do a similar and you did first and best! Good luck!

author
Jacky P (author)2013-06-03

What are all the parts?

author
Jonathan Robson (author)Jacky P2013-06-04

The parts, and what to do with them, are listed in step1. There is even an annotated diagram of them all.

About This Instructable

3,064views

21favorites

License:

Bio: Science museum exhibit design and fabrication manager, stagehand, ballet shoe maker, theatre production manager, project manager and art director of the Beijing Aquarium rainforest exhibit ... More »
More by Jonathan Robson:Arduino Nerf Target PracticeArduino Personal Soundtrack HoodieArduino / Wii controlled Lego Star Wars rocket turret
Add instructable to: