[OoB] Shooting paintball maker with relay, Arduino and .NET WinForms

[OoB] Shooting paintball maker with relay, Arduino and .NET WinForms

My first Arduino based project was Sonar with C#, JS and HTML5. Now I continue the “Out of Boredom” series with a setup that allows firing a paintball marker (gun) with a command sent from a computer πŸ™‚ This time software stack is simpler – just a small Arduino sketch and uncomplicated WinForms (.NE

My first Arduino based project wasΒ Sonar with C#, JS and HTML5. Now I continue the “Out of Boredom” series with a setup that allowsΒ firing a paintball markerΒ (gun) with a command sent from a computerΒ Smile | :)Β This time software stack is simpler – just a small Arduino sketch and uncomplicated WinForms (.NET/C#) application, but hardware requires a bit of electronics knowledge. Don’t worry though, nothing too complicated – I’m definitelyΒ notΒ an expert in this field…

[OoB] Shooting paintball maker with relay, Arduino and .NET WinForms

The project is based around anΒ electromechanical relay. Such relay is basically an electronically controlled switch that allows you to turn powerful devices on and off by sending a signal from Arduino’s output pins. You can control very large motors or light bulbs for example. The beauty of this components is the fact that you can govern external circuits – there is no physical link between your control circuit and the thing you want to turn on/off. You can use a relay for devices that require huge current but you can also control more subtle equipment, and that’s what I decided to do. I play paintball/speedball and I happen to own high-end electro-pneumatic marker called DM13. Such marker has electronically operated trigger and uses solenoid valve to shoot… I thought: “Wouldn’t it be cool to press enter on my laptop and make this gun fire nearly 20 balls per second?”…Β See this video to see how it workedΒ Smile | :)

This is a list ofΒ hardware parts used:

Element Role
Arduino Uno R3 Controlling trigger via relay and communicating with PC
JZC-11F 005-IZ SPDT relay Simulating trigger pull by closing trigger circuit
P2N2222AG NPN transistor Supplying current to operate relay
1.2k Ohm resistor Limiting transistor base current
Green LED Signalling ready state
Red LED Signalling firing
2x 330 Ohm resistor Limiting current going through diodes
Piezo buzzer Signalling read/fire with different tones
SPST switch Turning buzzer on/off
Breadboard and jumper wires or universal board Connecting components

LED connected toΒ Pin 13Β is used to signal that device is ready, LED attached toΒ Pin 12Β indicates firing (closed trigger circuit). LEDs are of course not connected to Arduino directly, there are resistors protecting them from overcurrent. Buzzer is there to make one tone when device is ready and another (higher) tone when device is firing. The purpose of a switch is to make your life easier while testing. Buzzer sound can get annoying quickly so you can turn it off…

These are the boring bits, theΒ more interesting stuffΒ is on the left side of the diagram.Β Pin 2Β is connected (via resistor) to aΒ baseΒ of NPN transistor andΒ collectorΒ is attached toΒ relay coil. The transistor is needed because the coil, which controls the switching function, needs more power then Arduino output pins can supply. In this circuit transistor is used not as amplifier but as a switch. WhenΒ Pin 2Β is set toΒ HIGH (base-emitter voltage = 5V) the transistor reaches its fully-on state and current flows through collector energizing the coil. PuttingΒ HIGHΒ state onΒ Pin 2Β results in a connection between relay’sΒ COMΒ (Common) andΒ NOΒ (Normally Open) pins. I’ve checked my marker with a multimeter (in resistance mode) and I was able to see that pulling the trigger resulted in a closed circuit between middle and lower pins of the trigger switch. Attaching one cable betweenΒ middle pinΒ of the switch andΒ COMΒ pin, and another cable betweenΒ lower switch pinΒ andΒ Normally OpenΒ pin gives the ability toΒ simulate trigger pull. In other words:Β HIGHΒ state on Arduino’sΒ Pin 2Β equals trigger pull as far as maker is concerned*. It’s quite simple but as you’ve seen on theΒ videoΒ it works really well! One more thing: look on the diagram on the right-hand side of JZC-11F relay – there’s a signal diode and it’s purpose is to protect the transistor from voltage spikes that appear whenΒ Pin 2Β to is put toΒ LOWΒ state (when supply voltage is removed from relay’s coil). Such diode usage is called “flyback” or “freewheeling”… I first created this circuit on a breadboard and then soldered it on a universal board… Keep in mind that there are multiple Arduino relay shields available so you don’t really have to create such transistor based circuit yourself. I did it because I think that it’s a nice way to refresh some very basic electronics knowledge. Ok, we are done with hardware!

Now time for softwareΒ (thisΒ GitHub repositoryΒ contains all the code)!

Here’s completeΒ Arduino sketch:

const byte fireRelayPin = 2;const byte fireBuzzerPin = 11;const byte fireLedPin = 12;const byte readyLedPin = 13;const byte readyToFireMessage = 6; <em>//</em><em> ASCII ACK</em>const byte fireCommand = 70; <em>//</em><em> ASCII F</em>const byte triggerPullDelayInMs = 30;const byte fireBuzzerHz = 1000;const byte readyBuzzerHz = 400;void setup() { pinMode(fireRelayPin, OUTPUT);Β Β Β  pinMode(fireBuzzerPin, OUTPUT);Β Β Β  pinMode(fireLedPin, OUTPUT); pinMode(readyLedPin, OUTPUT);Β  Serial.begin(9600);Β Β Β  tone(fireBuzzerPin, readyBuzzerHz);Β  digitalWrite(readyLedPin, HIGH);Serial.write(readyToFireMessage);}void loop() {Β Β  if (Serial.available()) {
Β Β Β Β Β Β Β Β byte data = Serial.read();Β Β Β Β Β Β Β  if (data == fireCommand) {pullTrigger(); delay(triggerPullDelayInMs); releaseTrigger();Β  }Β Β Β  }}
void pullTrigger() {Β Β Β  digitalWrite(fireLedPin, HIGH);Β Β  digitalWrite(fireRelayPin, HIGH);Β 
Β Β Β Β tone(fireBuzzerPin, fireBuzzerHz);}void releaseTrigger() {igitalWrite(fireLedPin, LOW);Β Β Β  digitalWrite(fireRelayPin, LOW);Β 
Β Β Β Β tone(fireBuzzerPin, readyBuzzerHz);Β Β Β  Serial.write(readyToFireMessage);}

[OoB] Shooting paintball maker with relay, Arduino and .NET WinFormsNothing complicatedΒ Smile | :)Β First, the usual (good) practice of creating constants for pin numbers and other useful values. Then there is aΒ setupΒ method that configures pin modes, initializes serial connection (used to communicate with PC), and turns on the “ready” LED. There is also a call toΒ tuneΒ function.Β tuneΒ is used to generate sound by making piezoelectric element in buzzer vibrate at a designated frequency. InΒ loopΒ function program waits for data sent by PC via serial port and checks if this data means a fire command (ASCII letter ‘F‘). If so, a trigger pull is simulated followed by a slight delay and trigger release. TheΒ digitalWrite(fireRelayPin, HIGH);Β line is what makes paintball gun fire. If you’ve looked carefully ,you’ve noticedΒ Serial.write(readyToFireMessage);Β calls inΒ setupΒ andΒ releaseTriggerΒ functions. These exist to let computer know that Arduino is ready to receive first fire command or is ready to process a new one.

This is theΒ .NET 4.5 WinForms applicationΒ build to control paintball marker:

 

For more detail: [OoB] Shooting paintball maker with relay, Arduino and .NET WinForms

About The Author

Scroll to Top