New to arduino - Paintball project

Hello, everyone.

New to the forum and totally new to arduino, looking for some advice on how to approach my first arduino project.

The microcontroller I got to use with this project is a Teensy 3.0, mostly because it was one of the smallest microcontrollers I can find and space is a big factor for this project. I would like to use 4 momentary switches to control an N-Channel MOSFET which will replace a microswitch on another board in an electronic paintball gun, basically allowing the teensy to open and close the circuit on the board that fires the paintball gun.

The reasoning behind this is I would like to use the 4 separate switches to fire the paintball gun. This way, rather than with the single trigger, where you have to pull the trigger and release it before you can fire it again, you can just engage the first of the 4 switches and then the next one and then the next one and so on, using 4 different fingers to fire it, not having to release one switch to engage the next one.

So basically, what I would like is when you pull one switch, it closes the circuit of the N-channel mosfet for about 10-30ms and then opens it, regardless of wether the switch that was engaged is still pressed or not, so you can still hold down the one switch and use your next finger to press the next one and fire again.

I’m not very knowledgable about the coding or electronics aspects, so I’m looking for a little bit of guidance to make sure I get this whole thing set up correctly. Any help is greatly appreciated.

ninja3454:
The microcontroller I got to use with this project is a Teensy 3.0, mostly because it was one of the smallest microcontrollers I can find and space is a big factor for this project.

For something like this, even smaller and less expensive would be a bare ATTiny85 -- or a Digispark if you want the convenience of plugging into a USB port to program it.

ninja3454:
The reasoning behind this is I would like to use the 4 separate switches to fire the paintball gun. This way, rather than with the single trigger, where you have to pull the trigger and release it before you can fire it again, you can just engage the first of the 4 switches and then the next one and then the next one and so on, using 4 different fingers to fire it, not having to release one switch to engage the next one.

Seems like an odd interface to me. There's no reason you should need to tap the buttons; you can simply hold the button down and have the microcontroller repeat the pulses. Use two buttons (etc.) so that when both are held down the fire rate is faster. You might consider also using a force-sensitive resistor so that the gun fires more quickly with increased pressure on the trigger.

Chagrin:
Seems like an odd interface to me. There's no reason you should need to tap the buttons; you can simply hold the button down and have the microcontroller repeat the pulses. Use two buttons (etc.) so that when both are held down the fire rate is faster. You might consider also using a force-sensitive resistor so that the gun fires more quickly with increased pressure on the trigger.

The reasoning for this is paintball field rules usually have a "semi-auto only" rule which means the gun can only fire once per trigger pull. Most paintball guns already have full auto firing modes, but I want to use multiple single triggers in order to be able to achieve a greater rate of fire while still only firing once per trigger pull.

ninja3454:
Hello, everyone.

New to the forum and totally new to arduino, looking for some advice on how to approach my first arduino project.

The microcontroller I got to use with this project is a Teensy 3.0, mostly because it was one of the smallest microcontrollers I can find and space is a big factor for this project. I would like to use 4 momentary switches to control an N-Channel MOSFET which will replace a microswitch on another board in an electronic paintball gun, basically allowing the teensy to open and close the circuit on the board that fires the paintball gun.

The reasoning behind this is I would like to use the 4 separate switches to fire the paintball gun. This way, rather than with the single trigger, where you have to pull the trigger and release it before you can fire it again, you can just engage the first of the 4 switches and then the next one and then the next one and so on, using 4 different fingers to fire it, not having to release one switch to engage the next one.

So basically, what I would like is when you pull one switch, it closes the circuit of the N-channel mosfet for about 10-30ms and then opens it, regardless of wether the switch that was engaged is still pressed or not, so you can still hold down the one switch and use your next finger to press the next one and fire again.

I'm not very knowledgable about the coding or electronics aspects, so I'm looking for a little bit of guidance to make sure I get this whole thing set up correctly. Any help is greatly appreciated.

You may want to check the rest of the circuit before assuming an N-Channel MOSFET will work. N-Channel generally assumes that one end of the 'switch' is connected to ground. A P-Channel will assume one end is connected to VCC. I believe a Solid State Relay doesn't care, but are usually large and expensive. That being said, using a MOSFET is a great idea for this, and this could work well for you, but you'll want to check that before you get too far.

mirith:
You may want to check the rest of the circuit before assuming an N-Channel MOSFET will work. N-Channel generally assumes that one end of the ‘switch’ is connected to ground. A P-Channel will assume one end is connected to VCC. I believe a Solid State Relay doesn’t care, but are usually large and expensive. That being said, using a MOSFET is a great idea for this, and this could work well for you, but you’ll want to check that before you get too far.

Yes, I agree. I’m not really sure how I can tell wether the microswitch is attatched to a ground or not.

I don’t know much about electronic components, I just did a little bit of research and I figured a mosfet or transistor would work best for what I’m trying to do.

Found this schematic of the board in which I am replacing the microswitch, and from this it seems like the microswitch is connected to a ground. http://www.scenariodreams.com/images/universal/clap_type_a.jpg

One more thing to check. Assuming you are supplying your voltage off the same device and not another battery, grab your multimeter and measure the resistance between “Trigger GND” and “GND” If it is <0.5Ohms, you are good. Otherwise you may need to do some more digging.

If GND and Trigger GND are actually the same thing, then yes, an N-CHan MOSFET is looking good, you would connect the Drain to the Trigger signal, the Source to trigger GND, and then your signal pin to gate through a 100 ohm resistor. It won’t matter for hardware if it is an NO or NC circuit, but software you’ll want to be a bit more careful if it is an NC circuit, so it doesn’t accidentally fire when you turn it on…

judging from the multimeter it's looking like trigger ground and ground are the same, so we should be good.

Ok finally got all my stuff in and started on the project. Decided to use the digispark board instead because its smaller and I don’t need that many pins. I got it all set up like I thought it should be with some help from arduino tutorials, but alas, it’s not working. A pic of how the breadboard is set up is attached, and the code that I attempted us below.

On each button, one side of the button is attached to the 5v supply, and the other side is attached to pins 1-4 and also attached to the ground through a 10k resistor. I figured this is the right way to do it after reading this tutorial http://arduino.cc/en/tutorial/button

Then on the MOSFET, the gate is hooked up to pin 5, the drain is hooked up to gun trigger +, and source is hooked up to gun trigger ground.

Any ideas on how to make this work? I hope I didn’t make too much of a fool out of myself haha. :stuck_out_tongue:

const int button1 = 1; // pin number of button number one.
const int button2 = 2; // pin number of button number two.
const int button3 = 3; // pin number of button number three.
const int button4 = 4; // pin number of button number four.
const int fet1 = 5; // pin number if the N-Channel MOSFET

// variables will change:
int BS1 = 0; // variables for reading the pushbutton status
int BS2 = 0;
int BS3 = 0;
int BS4 = 0;

void setup() {
// initialize the FET pin as an output:
pinMode(fet1, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(button1, INPUT);
pinMode(button2, INPUT);
pinMode(button3, INPUT);
pinMode(button4, INPUT);
}

void loop(){
// read the state of the pushbutton value:
BS1 = digitalRead(button1);

// push button sequence
//if button 1 pressed…
if (BS1 == HIGH) {
// turn MOSFET on:
digitalWrite; (fet1, HIGH);
//wait 10 ms
delay(10);
//turn MOSFET off
digitalWrite (fet1, LOW);
}
else {
// otherwise, keep MOSFET off
digitalWrite; (fet1, LOW);
}

BS2 = digitalRead(button2);

// push button sequence
//if button 2 pressed…
if (BS2 == HIGH) {
// turn MOSFET on:
digitalWrite; (fet1, HIGH);
//wait 10 ms
delay(10);
//turn MOSFET off
digitalWrite (fet1, LOW);
}
else {
// otherwise, keep MOSFET off
digitalWrite; (fet1, LOW);
}

BS3 = digitalRead(button3);

// push button sequence
//if button 3 pressed…
if (BS3 == HIGH) {
// turn MOSFET on:
digitalWrite; (fet1, HIGH);
//wait 10 ms
delay(10);
//turn MOSFET off
digitalWrite (fet1, LOW);
}
else {
// otherwise, keep MOSFET off
digitalWrite; (fet1, LOW);
}

BS4 = digitalRead(button4);

// push button sequence
//if button 4 pressed…
if (BS4 == HIGH) {
// turn MOSFET on:
digitalWrite; (fet1, HIGH);
//wait 10 ms
delay(10);
//turn MOSFET off
digitalWrite (fet1, LOW);
}
else {
// otherwise, keep MOSFET off
digitalWrite; (fet1, LOW);
}
}

This is how I have it set up now. Still isn't working. In fact, the 2nd little light on the digispark only comes on when I press button number 2, but not the others, which makes me question if the other buttons are even working even though they're hooked up exactly the same.

The code is still the same.

The way you have your buttons connected (either time) is incorrect. Connect the input pin to one side of the button and the other side of the button to GND (plain wire; no resistor). Then use this code:

// variables will change:
int BS1 = HIGH;               // variables for reading the pushbutton status
int BS2 = HIGH;               // initial state set as HIGH
int BS3 = HIGH;
int BS4 = HIGH;

void setup() {
  // initialize the FET pin as an output:
  pinMode(fet1, OUTPUT);     
  // initialize the pushbutton pin as an input:
  pinMode(button1, INPUT);
  digitalWrite(button1, HIGH);     
  pinMode(button2, INPUT);
  digitalWrite(button2, HIGH);  
  pinMode(button3, INPUT);
  digitalWrite(button3, HIGH);  
  pinMode(button4, INPUT);
  digitalWrite(button4, HIGH);  
}

When a pin is set as input and you digitalWrite the pin high this activates the "internal pullup"; it's the equivalent of adding a 20K resistor between the pin and 5V. When the button is not pressed -- when the pin is connected to "nothing" -- it will read as high. When the button is pressed the small amount of current supplied by the internal pullup will be sunk to GND and the pin with read as low.

Next you need to change this code:

  // push button sequence
  //if button 1 pressed and it was HIGH before...
  if (digitalRead(button1) == LOW && BS1 == HIGH) {     
    // turn MOSFET on:   
    digitalWrite(fet1, HIGH);
    //wait 10 ms
    delay(10);
    //turn MOSFET off
    digitalWrite(fet1, LOW); 
  }
  // set BS1 to the current state
  BS1 = digitalRead(button1);

As an aside, your first method of connecting the buttons was close to correct, except when any single button was pushed they would all read as high. The top side of each button should have had a separate 10K resistor connecting to GND. When the button was unpressed it would read low (it would be connected to GND via 10K) and when pressed it would read high (it would be connected to 5V and the resistor would prevent enough current from leaking to GND for it to read low).

Chagrin, thanks for the help. I tried your suggestions and I'm still not having any luck. I'm not sure if it's a problem with the buttons or if it's the MOSFET? I'm going to try hooking up an LED instead of the mosfet just to see if the buttons work.

OK, here's a pic of how I have the breadboard set up now and the code I'm using. I still can't get it to work, any suggestions?

For a little reference:

Top right corner of the breadboard is 9V power
Top left corner goes to paintball gun power
Bottom right corner is the trigger connection.

// constants won't change. They're used here to
// set pin numbers:
const int button1 = 1; // pin number of button number one.
const int button2 = 2; // pin number of button number two.
const int button3 = 3; // pin number of button number three.
const int button4 = 4; // pin number of button number four.
const int fet1 = 5; // pin number if the N-Channel MOSFET

// variables will change:
int BS1 = HIGH; // variables for reading the pushbutton status
int BS2 = HIGH; // initial state set as HIGH
int BS3 = HIGH;
int BS4 = HIGH;

void setup() {
// initialize the FET pin as an output:
pinMode(fet1, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(button1, INPUT);
digitalWrite(button1, HIGH);
pinMode(button2, INPUT);
digitalWrite(button2, HIGH);
pinMode(button3, INPUT);
digitalWrite(button3, HIGH);
pinMode(button4, INPUT);
digitalWrite(button4, HIGH);
}

void loop(){
// read the state of the pushbutton value:

// push button sequence
//if button 1 pressed and it was HIGH before...
if (digitalRead(button1) == LOW && BS1 == HIGH) {
// turn MOSFET on:
digitalWrite(fet1, HIGH);
//wait 10 ms
delay(10);
//turn MOSFET off
digitalWrite(fet1, LOW);
}
// set BS1 to the current state
BS1 = digitalRead(button1);

// push button sequence
//if button 1 pressed and it was HIGH before...
if (digitalRead(button2) == LOW && BS2 == HIGH) {
// turn MOSFET on:
digitalWrite(fet1, HIGH);
//wait 10 ms
delay(10);
//turn MOSFET off
digitalWrite(fet1, LOW);
}
// set BS1 to the current state
BS2 = digitalRead(button2);

// push button sequence
//if button 1 pressed and it was HIGH before...
if (digitalRead(button3) == LOW && BS3 == HIGH) {
// turn MOSFET on:
digitalWrite(fet1, HIGH);
//wait 10 ms
delay(10);
//turn MOSFET off
digitalWrite(fet1, LOW);
}
// set BS1 to the current state
BS3 = digitalRead(button3);

// push button sequence
//if button 1 pressed and it was HIGH before...
if (digitalRead(button4) == LOW && BS4 == HIGH) {
// turn MOSFET on:
digitalWrite(fet1, HIGH);
//wait 10 ms
delay(10);
//turn MOSFET off
digitalWrite(fet1, LOW);
}
// set BS1 to the current state
BS4 = digitalRead(button4);
}

Well, your buttons are OK but your power wiring is goofed. Where you have your 9V and gun power connected on the same rail it looks like a loop. There's no power at all even touching the mosfet drain or source or the trigger switch.

Refresher course: http://bildr.org/2012/03/rfp30n06le-arduino/

I'm not really clear on how the switch works on your paintball gun. Is it basically gun power positive -> trigger (first pole) -> trigger (second pole, when depressed) -> gun power negative? In other words when you pull the trigger it energizes some kind of solenoid that stays energized until you release it? Or, similarly, the trigger clicks somewhere in the middle of the pull to temporarily energize the solenoid?