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 !
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:
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:
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.
Next, let's install the emitter / detector pair. If you want more information on how these work, refer back to my earlier Instructables.
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.
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.
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
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.
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.
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.
Finish connecting the LED ring by attaching the gate and strobe wires to appropriate pins:
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:
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.
Time to test the IR emitter / detector pair.
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.
If you are not getting expected changes, here are some things to check:
Time to test the strobe. We are just going to use the basic "Blink" example and change the pin number:
If you do not get the expected flashing, check your wiring and pin numbers.
All that is left to test is the push button:
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.
Time to put our tested system into an integration. Start by preparing the PVC barrel:
Getting the final alignment is a bit tricky. You want to anchor your barrel in the correct position.
Time for some weapons grade firmware.
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.
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.