Target practice with airsoft and nerf guns is entertaining, but static targets quickly lose their appeal. In this project, we construct a random target system that uses a servo and PIC microcontroller to randomly show a target. As an added bonus, this target also detects impact and will sound an alert when the target is successfully hit!
How It Works – Hardware
This project takes advantage of both analog and digital parts: the piezo transducer detecting hits while the microcontroller handles random number generation, servo control, and linking between random target systems.
The hit detection happens with the help of a piezo transducer that either converts voltage to a flex in the transducer itself or converts a flex in the transducer into a voltage. When the projectile hits the target (which has the transducer connected to it), it generates a voltage spike. This spike gets amplified by U3A (while negative voltages are removed by D6), and is then fed into a Schmitt trigger U3B. This results in the micro controller detecting the pulse, making it able to respond to project impacts. All other parts connected to the microcontroller are controlled using either drivers or are directly driven.
How It Works – Software
The real complexity of this project lies in the firmware which performs multiple functions:
- Setting the servo to a specific angle
- Showing or hiding the target
- Sounding a beep
- Detecting impacts
The main bulk of the code is written in the form of a finite state machine to make detection and setting of the servo easy as well as reliable. If the targetState and machineState variables fall outside of their expected values, then the main code sets them to target show, preventing the system from hanging. If the machine detects a hit when the target state is “target show”, the system sounds the beeper, flashes the LED, and then hides the target.
The circuit also has a tactile switch to generate a random number by the user. When the circuit turns on, the system waits for the user to press the button. Once the user presses the button, a loop is executed, finishing only when the user releases the button. During this loop, a random variable is incremented and used as the seed for random number generation. Random number generation prevents predictable sequences, making the game harder.
You can construct the main circuit in this project by using common circuit construction techniques including a stripboard, breadboard, matrix board, and a custom PCB. In this project, I used a custom PCB as I intend to make multiple systems that I can place outside in an airsoft range.
When creating the target itself you need to seriously consider what you plan to fire and its penetrating power. Nerf guns fire soft darts that cannot cause harm, so the transducer can easily be mounted behind some cardboard. Airsoft, however, has some penetrating power and can go through materials like thin plastic and cardboard. Since I’m building for airsoft target practice, I used pieces of copper clad as the target and mounted the piezo transducer on the backside.