Nerf Meter - Dart Velocity Attachment With Arduino-based Display.
by mbouy in Circuits > Arduino
1652 Views, 17 Favorites, 0 Comments
Nerf Meter - Dart Velocity Attachment With Arduino-based Display.
I took a Nerf Dual Rail Barrel (supplied with Modulus ECS-10) and added an Arduino-based meter with 4 digit display which reports velocity of each dart in metres per second. Pushing the button shows an average of all reads, holding the button for 2 seconds resets the average to zero.
This project could not have happened without the work by BrittLiv documented here: https://www.instructables.com/Measure-the-speed-of-Nerf-darts/.
The principles are the same - two IR LED emitter/receiver pairs measure the time taken for a dart to travel a known distance. Where that project uses a discreet Atmega 328p and display driver, I found the Sparkfun serial 7 segment display includes all that hardware in one convenient package. This allows the whole thing to fit in a much smaller footprint, and simplifies the build substantially. Feedback on that project also referred to low profile side-looking LEDs, which I used here.
Supplies
I used Core Electronics Australia for most parts, and the local Jaycar for sundries.
COM-11442 7-Segment Serial Display - Blue (other colours available include red, white, green)
SEN-18772 Infrared Emitter (2)
SEN-19018 Infrared Detector (2)
SP0622 SPST PCB Mount Tactile Switch with Blue LED
SK0975 SPST Ultra Mini Rocker Switch
150ohm resistors (3)
10kohm resistors (2)
1S LiPo Battery to fit the available space.
Also require an FTDI programmer, or a spare Arduino to use as a programmer.
Modify/Fabricate a Barrel
There are no hard and fast rules here - so many ways to achieve the same result. Find a Nerf gun or accessory which you're happy to cut, and which can be made to accomodate the parts. Note the display module ships with no header attached, and programming will require header pins to be soldered to the rear. Depending on how these are mounted might affect your ability to mount the display. I bent some pins to 45° so they could remain in-situ and I could still get the whole unit closed. I was aiming for a 'that might be official' look, with neat cutouts and no visible external parts, but an entirely different look could be achieved by glomming it all on the outside and making it obviously a mod.
Once I had most of the parts and had chosen the barrel to modify, I played with various mounting options and had to remove some internal ribs and do quite a bit of shaping. I used a power drill, dremel, chisel & files to cut the main mounting holes. For the button I cut away too much and had to rebuild a bit of the case with builder's bog (2-part polyester) and paint the section to hide it.
The IR LED (emitter) and Photo-transistor (receiver) are very similar looking, but the emitter has a coloured dot at the junction. These need to be mounted as pairs which forms a beam to be broken by the dart. I drilled a 3mm hole through the barrel and straight through the other side. They weren't perfectly centred, but close enough. Measure the spacing between hole pairs as accurately as you can, as this forms the basis of the calculation. Use whatever unit works for you, if you want feet per second, then measure in decimal feet.
Wiring
I had a spare 1S LiPo which fit in the case and had a connector which mated to the programming header and could power the unit. I cut the positive lead and soldered the ends on the power switch. This will make recharging the battery a bit fiddly in future, but my testing on the bench showed this battery could run the display continously for at least 12 hours. I think it'll be a very long time before recharging is an issue. If I was working with a larger barrel I would've used an 18650 battery in a holder so it's easy to swap out. The display works on 3.3 to 5.5V.
The photo transistors (IR receivers) need pulldown resistors, so to make things tidy I soldered them directly to the board - one 10kohm each at A6 to ground and A7 to ground. I also soldered some fine wires to A6 and A7 to later connect to the receivers.
I used a button with LED but any momentary button would do. I haven't used the button LED for any kind of signal, it's on when power is on. Each end of the display PCB has solder pads for + and - and I used these for the LED with a 150ohm resistor. Also at each end are solder pads for SDA and SCL. Since we're not using I2C comms at all, I used SDA (A4) for the button. It was a convenient point to solder to.
Wiring the Barrel
While not necessary, having a connector between the barrel and the body made it easier to work on the pieces separately. It also became a point of failure, and made it harder to get the body reassembled. I had the parts on hand so used them, I wouldn't have made an effort to get them.
Apologies for my poor sketch, I don't have software to draw a schematic. Following the principles of the instructable I copied, there are 150ohm current limiting resistors on the emitters, and the receivers are across analog pins which have pulldown resistors on them.
Code
The Serial 7-Segment Display is shipped as a display module with code to display data received via I2C, SPI or UART. Being based on an Atmega 328p means we can reconfigure it, but Arduino IDE needs a few libraries and a board installed.
Paste https://raw.githubusercontent.com/sparkfun/Arduino_Boards/master/IDE_Board_Manager/package_sparkfun_index.json into the Additional Boards Manager URL in preferences.
Then use Tools > Board > Boards Manager to find 'SparkFun AVR Boards' and click Install.
Once installed the board can be selected under SparkFun AVR Boards as SparkFun Serial 7-Segment Display.
Using Library Manager install sevseg.h (I used v3.7) and bounce2.h for switch debouncing.
Most of the sensor code is copied from https://www.instructables.com/Measure-the-speed-of-Nerf-darts/ with only minor amendments.
NB: The instructions at https://github.com/sparkfun/Serial7SegmentDisplay/wiki/Customizing-the-Display initially led me to an old version of sevseg.h and the original firmware. I've pared it down to only what is required. Revisit the source if you want to use the colon or apostrophe, which I didn't.
The new sevseg library uses setNumber(number to display, decimal position counting from right). As far as I can tell, the decimal can be disabled, but not enabled and unused.
sevseg.setNumber(8008,0); // displays 8008.
Some maths can be done within the function, and my code does that:
sevseg.setNumber(meanVal*100/meanCount,2); // Shifted two places and two decimal places displayed.
For text use setChars with any text in quotes. There's a good example regarding strings, I've uploaded a copy which is configured to work on this display and would be a good test before embarking on wiring.
sevseg.setChars("NERF"); // No decimals.
sevseg.setChars("N.E.R.F."); // All decimals on
Closing Comments
The code occupies about 25% of the available space, so there's plenty of room for additional functions. Some options I'm thinking of:
- double-click to switch units from m/s to FPS and back
- display rounds that contributed to the average
- round countdown - would need a way to preset rounds, perhaps step through obvious choices 6, 10, 12.