Arduino for Nerf: Chronograph and Shot Counter

2,166

28

1

My previous Instructable covered the basics of detecting dart speed using an infrared emitter and detector. This project takes it a step further, using a printed circuit board, display, and batteries to make a portable ammo counter and chronograph. Additionally, we add some LEDs to simulate muzzle flash. Because, pew pew pew . . .

This may seem like a daunting project with lots of steps, but the use of a printed circuit board and commercial components for the display and microcontroller make it much easier to assemble a reliable project. I will also provide test code for each element of the project to help ensure your success. You can do it !

Step 1: Parts and Supplies

Printed Circuit Board, three copies will cost you only $12.40 with free shipping, so make this with a friend to share the cost:


Electronic Parts


3D Parts

The 3D parts were created primarily in TinkerCad, which means they are easy to modify to your own purpose:

I have also put copies of the STLs on Thingiverse: https://www.thingiverse.com/thing:3645612


Tools & Misc:

  • Soldering Iron
  • Wire strippers
  • Flush cut snippers
  • Hot glue gun
  • Wire
  • #2 thread forming screws
  • 3/4" PCV


Step 2:

We are going to start with the circuit board.

  • Separate the two smaller "breakout" boards from the middle and set aside for latter using flush-cuts or by twisting.
  • Trim the rough edges, file or sand to smooth them down.

Step 3:

I'm not going to try and teach you soldering. Here are a couple of my favorite videos that show it much better than I can:

In general:

  • Find the location on the PCB using the silk screen markings.
  • Bend the component leads to fit the foot print.
  • Solder the leads.
  • Trim the leads

Let's start with resistors since they are the most plentiful, lowest seating, and easiest to solder. They are more heat resistant and will give you a chance to brush up on your technique. They also have no polarity, so you can put them in either way.

  • 6 ea., 100-ohm resistors which limit current to the LEDs go in the spots marked "*R" and "100".
  • 2 ea., 10,000-ohm resistors go in the spots marked "10K".

Step 4:

Next, let's install the emitter / detector pair. If you want more information on how these work, refer back to my earlier Instructables.

  • The IR emitter is clear and goes in the spot marked "EMIT" with the rounded lens pointing toward the center .
  • The IR detector is black and goes in the spot marked "DETECT" with the rounded lens pointing toward the IR emitter.

Step 5:

Since the 5 LEDs will draw more current than can be directly supplied by the microcontroller, we will use a transistor switch to turn them on and off. This can be a small N-channel MOSFET or a regular NPN transistor since we are dealing with about 100 mA.

  • The N-MOSFET goes in the spot marked "Q1" with the flat face matching the markings.

Step 6:

LEDs have a polarity. The long lead is positive and marked with a "+" on the PCB. There is also a flat edge on on side that I can never see clearly.

  • Install all the LEDs on the side opposite the resistors and MOSFET.
  • Flip the board over and solder one lead, and only one lead of each LED in place.
  • Inspect the LEDs, verifying the long lead is in the hole marked "+", and that the LED is flush with the board.
    • Reheat the joint while gently pushing down on the LED to seat it (see photo 4).
  • Solder the remaining leads and trim.

Step 7:

Test fit the led ring in the 3D printed cap. It will only fits one way, with the MOSFET toward the "t-shaped" opening.

Step 8:

Time to start wiring!

  • Take four 6" wires and strip and tin each end.
  • Solder into the header on the PCB:
    • Red for "+".
    • Black for "-".
    • Color choice for "S" which is "strobe", or the signal to turn the LEDs on.
    • Color choice for "G" which is "gate", or the signal coming from the IR detector.

Step 9:

Let's get the display ready. I like Adafruit's "I2C backpacks" because they only take two signals wires to work (in addition to power and ground). You can also chain them together.

The official Adafruit instructions are at:https://learn.adafruit.com/adafruit-led-backpack/0-dot-56-seven-segment-backpack

  • Ensure you get the display orientation correct with the decimal points matching the PCB markings.
  • As in the prior step, tin and strip 4 ea., 6" wires:
    • Red for "+"
    • Black for "-".
    • Color choice for "SDA" and "SCL".

Step 10:

The button is for user input. I use it to reset the ammo counter, but it could be used to turn the LEDs on and off like a flashlight, or what ever your imagination comes up with. It is your project.

  • Insert the switch in the breakout board and solder the leads.
  • Trim, strip, and tin two 6" wires. One should be black for ground, the other a distinctive color.
  • Solder the wires to the breakout board. Orientation does not matter.

Step 11:

The slide switch is used to turn power on and off. The design is a bit confusing, but helps with assembly. The markings on the silk screen show how the switch is breaking the contact between the two positive leads.

  • Cut the leads on the batter case so that approximately 2" remain attached.
  • Solder the slide switch to the breakout board.
  • Strip and tin the remaining ~4" leads from the battery holder and solder to one side of the breakout board (red to "+", black to "-").
  • Solder the leads from the battery holder to the other side of the breakout board (red to "+", black to "-").

Step 12:

Time to start integrating the various components. We will save the button for latter for since we can only easily fit three wires through a single hole.

  • Take the three red leads, strip and twist together:
    • LED ring
    • 7-segment display
    • Slide switch
  • Insert them through the bottom of the "3V" pad of the ItsyBitsy and solder in place.
    • If you are using another type of board, use the "5V" pin.
  • Take the three black ground wires from the same components, strip, twist, and insert in the "G" pad across from the "3V" pad.

Step 13:

Finish connecting the LED ring by attaching the gate and strobe wires to appropriate pins:

  • Attach the "G" or gate wire to the ItsyBitsy pin A0. This will allow us to get analog readings for troubleshooting.
  • Attach the "S" or strobe wire to pin 9 which will allow us to PWM the light signal if we want to control brightness later.

Step 14:

Finish connecting the 7-segment display by attaching the I2C wires:

  • Attach the SCL ("clock") pin from the display to the SCL pin on the ItsyBitsy.
  • Attach the SDA ("data") pin from the display to the SDA pin on the ItsyBitsy.

Step 15:

Time to add the button:

  • Attach the black lead to the ItsyBitsy "G" pin on the bottom short edge of the board. This is the same ground signal as the other "G" pin.
  • Attach the color lead to ItsyBitsy pin "7". This will allow us to use a hardware interrupt signal to reset the counter.

Step 16:

At this point, it is time to test our various components.

If this is your first time using the Adafruit ItsyBitsy, you will have to configure your Arduino IDE to recognize the board.

If this is your first time using Adafruit's I2C displays, you will again have to configure your Arduino IDE to use Adafruit's libraries.

Time to test it out:

  • Attach your ItsyBitsy to your computer using a USB Micro.
  • [Tools] -> [Board] -> [Adafruit IstyBitsy 32U4 8MHz].
  • [Tools] -> [Port] -> what ever port connected, usually the highest number.
  • [File] -> [Examples] -> [Adafruit LED Backpack Library] -> [sevenseg]
  • [Sketch] -> [Upload]

If the upload is successful, the display should come to life and start showing incrementing numbers. Time to let out a "whoop!" of glory. If not, time to put on the troubleshooter hat.

If the upload failed, double check the ItsyBitsy setup instructions, IDE settings, and USB cable connection.

If the display fails to light up, double check the backpack instructions and your wiring connections.

Step 17:

Time to test the IR emitter / detector pair.

  • [File] -> [Examples] -> [Analog] -> [AnalogReadSerial]
  • Upload to your board.
  • Click the "Serial Monitor" icon in the right corner of the IDE.

With any luck, you are seeing a stream of values coming in. These are 10-bit analog values so will range from 0 to 1023.

  • When the photo transistor is exposed to light, it allows current to pass and the signal will drop towards 0.
  • When the photo transistor does not see IR, it stops the current flow allowing the signal to go high.

If you are not getting expected changes, here are some things to check:

  • Double check the wiring from the ring to the microcontroller.
  • Is the IR LED on?
    • It should be slightly warm to the touch.
    • A cheap cell phone camera will show IR light nicely.
    • If it is not on, it is likely wired backward.

Step 18:

Time to test the strobe. We are just going to use the basic "Blink" example and change the pin number:

  • [File] -> [Examples] -> [01.Basic]->[Blink]
  • Depending on your IDE version, change the pin number to match the one we selected in step 13 (pin 9).
  • Upload the sketch and prepare to be blinded.

If you do not get the expected flashing, check your wiring and pin numbers.

Step 19:

All that is left to test is the push button:

  • [File] -> [Examples] -> [01.Basic] -> [DigitalReadSerial]
  • Change pushButton = 2; to pushButton = 7;
  • Change pinMode(pushButton, INPUT); to pinMode(pushButton, INPUT_PULLUP);
  • Upload.

The INPUT_PULLUP attaches a weak pullup resistor to 3V which means a digitalRead() should return "HIGH" or "1". When the button is pressed, it should return "LOW" or "0".

If you are not getting expected values, go back and check the button wiring.

Step 20:

Time to put our tested system into an integration. Start by preparing the PVC barrel:

  • Cut a section of 3/4" PCV 85mm long.
  • Mark 6mm from the end and drill a 1/4" or larger hole through both sides, as centered as possible.
  • Spray the inside of the barrel flat black to absorb reflected IR light when the dart passes.
  • Use a file to mark the position of the holes on the end of the barrel.

Step 21:

  • Test fit the battery case and trim if needed.
  • Insert the case (the lead end toward the power switch opening).
  • Tack the case in place with hot glue (not too much in case we have to take it apart latter).

Step 22:

  • Insert the power switch and the button into the 3D case holes and tack in place with hot glue.

Step 23:

  • Slide the ItsyBitsy into it's slot and arrange the wiring so we have a path for the barrel.

Step 24:

  • Insert the LED ring in the cap and tack in place with hot glue.
  • Attach the cap so the ItsyBitsy USB port emerges in the correct position.

Step 25:

  • Insert you barrel so that the alignment marks on the barrel end match the cap marks.
  • Visually check the IR emitter and detector and visible through the holes in the barrel. Enlarge holes if needed.
  • Attach the USB to the ItsyBitsy and rerun the IR checks (AnalogReadSerial sketch).

Step 26:

Getting the final alignment is a bit tricky. You want to anchor your barrel in the correct position.

  • Attach the barrel adapter to a Nerf blaster.
  • Slide the barrel case on to the adapter, verifying that the three screw holes on the blaster end line up.
  • Verify the barrel alignment on the exit side.
  • Carefully detach the assembly using the barrel adapter.
  • Carefully slide the barrel case off the adapter while holding the PVC in place with your finger inside.
  • Tack the barrel in place with hot glue.
  • Reassemble, recheck aliment
  • Attach the cap and barrel adapter using screws. #2 thread forming, or spare Nerf screws will work.

Step 27:

Time for some weapons grade firmware.

  • Download and then Upload the attached sketch to the ItsyBitsy.
  • Verify the display is flashing dashes (until the first shot is fired).
  • Place your finger in the barrel end far enough to block the IR beam and then quickly remove it.
  • Verify you get a flash of light from the LEDs.
  • Verify you get a numerical reading which will alternate from "1" (shot count) and some small feet per second value like "1.5".
  • Press the button on the bottom of the barrel and verify it goes back to flashing dashes (reset shot count).

If any of these steps fail, so back and double-check the operation using the previous test sketches. Examine wiring to see if anything was jostled during assembly.

Step 28: What Next?

Now you know how fast your Nerf gun is shooting, you can measure the effects of any mods you make. Since the barrel is removable and portable, you can let your friends chrono their blasters.

Moving forward in this series, we will look at upgrading the battery and wiring for LiPo, using a MOSFET to control flywheels, and working toward a select fire system with completely customizable operation.

Arduino Contest 2019

Runner Up in the
Arduino Contest 2019

Share

    Recommendations

    • Beauty Tips Contest

      Beauty Tips Contest
    • Sensors Contest

      Sensors Contest
    • Classroom Science Contest

      Classroom Science Contest

    Discussions