Arduino for E-trigger

ok i have been doing some googling on this for a few days, i asked over on a pb forum and now i think i should ask here. i just ask that you go easy on me.

ok i am looking to make a electronic trigger for a paintball guns based on open source.

there are a few things i want this E-trigger to do and not do.

it should be noted im a machinist and dont know anything about programing

i'm only wanting 900 RPM or 15 BPS.

i want to have a 3way switch so i can change from semi-, burst and full(no ramping, no safety)

i want to have a safety in the hand grip (like in a 1911) so if your hand is not on it, the gun can not fire.

the solenoid will be controlled via NPN and a led to show when its triping.

well thats all im wanting out of this. now its just a matter of getting down to whats the best way to do this.

  1. i was thinking on the grip safety, having that as the power switch. but i dont know how long of a bootup time the arduino has. if it is less then .5sec. then i could get away with doing it that way. is it is longer then that it would be in series with the solenoid.

  2. the selector switch i was thinking of using a rotary switch. on the other side i was thinking using different resisters going to an input pin. so 1kohm+input.pin=semi and 3.3kohm+input.pin=burst

so if input.pin=3.3kohm then for [u]one[/u] trigger pull, the solenoid will trip, wait 0.7sec. then trip again, and wait .07sec. then again trip, and last wait .07sec. once more. [u]however[/u] if the trigger is pulled a 2nd time before the end of the firing cycle, it is ignored.

so how am i thinking the right way on how to set it up?

how would i go about programing this?

Look at the most basic tutorial blink. Then add before the delay() function call for the off-phase the part that reads the pressed button and selects the proper delay to achieve the frequencies you want. That isn't a perfect solution, but it should get you started.

Korman

i can see what you are trying to do, and i kinda like it, i like to play PB when i can but have not been able to much lately.

i think for durability you would be far better off with 1 switch and a tricolor led for feedback, i cant see a pot standing up to PB for long.

but the other fellow is right this would just be a modified blink so nothing too hard there, other than i don’t know what the solenoid would need to activate, i think you will need a mosfet or darlington transistor for it.

i am still pretty new at programming, so i might not be of much help there.

ok i think im on to something here. have a look at this code and tell me if im on the right track

/*
 
 
 The circuit:
 * NPN attached to pin 13
 * pushbutton attached to pin 1 from +5V
 * pushbutton attached to pin 2 from +5V
 * pushbutton attached to pin 3 from +5V
 * pushbutton attached to pin 4 from +5V
 * pushbutton attached to pin 5 from +5V
 * 10K resistor attached to pin 1 from ground
 * 10K resistor attached to pin 2 from ground
 * 10K resistor attached to pin 3 from ground
 * 10K resistor attached to pin 4 from ground
 * 10K resistor attached to pin 5 from ground
 
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 
 
 created 2005
 by DojoDave <http://www.0j0.org>
 modified 07 Feb 2011
 by eliofall
 
 This example code is in the public domain.
 */

// constants won't change. They're used here to
// set pin numbers:
const int trigger      = 1;
const int safety       = 2;
const int semi         = 3;
const int burst	        = 4;
const int full	        = 5;     
const int ledPin     = 13;      // goes to an 2n2222 to turn on the led & selonoid

// variables will change:
int triggerState	= 0; 
int safetyState	= 0; 
int semiState		= 0; 
int burstState		= 0; 
int fullState		= 0; 

void setup() {
  pinMode(ledPin	, OUTPUT);      
  pinMode(frigger	, INPUT);
  pinMode(safety	, INPUT);
  pinMode(semi		, INPUT);
  pinMode(burst		, INPUT);
  pinMode(full		, INPUT);   
}

void loop(){
  // read the state of the pushbutton value:
  triggerState = digitalRead(trigger);
  safetyState = digitalRead(safety);
  semiState = digitalRead(semi);
  burstState = digitalRead(burst);
  fullState = digitalRead(full);

  // check if you hand is on the grip, where the selecter is and if youve pulled the trigger.
  if (triggerState 	== HIGH)
  and (safetyState 	== HIGH)
  and (semiState 	== LOW)
  and (burstState 	== LOW)
  and (fullState	== HIGH) { 
 void loop() {    
    digitalWrite(ledPin, HIGH);
    delay(10);
    digitalWrite(ledpin, LOW);    
    delay(70);  
  }
}
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

 // check if you hand is on the grip, where the selecter is and if youve pulled the trigger.
  if (triggerState 	== HIGH)
  and (safetyState 	== HIGH)
  and (semiState 	== LOW)
  and (burstState 	== HIGH)
  and (fullState	== LOW) { 
 digitalWrite() {    
    digitalWrite(ledPin, HIGH);
    delay(10);
    digitalWrite(ledpin, LOW);    
    delay(70);  
    digitalWrite(ledPin, HIGH);
    delay(10);
    digitalWrite(ledpin, LOW);    
    delay(70);  
    digitalWrite(ledPin, HIGH);
    delay(10);
    digitalWrite(ledpin, LOW);    
    delay(70);  
  
}
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW);
  }
}

 // check if you hand is on the grip, where the selecter is and if youve pulled the trigger.
  if (triggerState 	== HIGH)
  and (safetyState 	== HIGH)
  and (semiState 	== LOW)
  and (burstState 	== HIGH)
  and (fullState	== LOW) { 
 digitalWrite() {    
    digitalWrite(ledPin, HIGH);
    delay(10);
    digitalWrite(ledpin, LOW);    
    delay(70);
  
}

It would have been nice, if you’d have posted some code that actually compiles and does something. Your code is a mess, you declare local functions where you don’t want to. You should take a step back and look again at the basic examples and work a little more on understanding how the programming language works.

The best way to learn programming is to start with something very small (eg blinking the led), compile it and test it on the board. Once that works, add another small thing (eg the trigger switch), compile it again and test again if your program now does what you think it should do. Then progress in this way, always taking very small steps and checking after each step if your program does what you really want it to do. Adding a whole building of untested code will only lead frustration, strange behaviour and crappy products.

Also, using digital pins 0 and 1 isn’t such a bright idea, this is used by the USB-port and creates a lot of not so funny side effects. I remapped pin 1 to pin 6.

Here’s an example, what your code might look like - although I couldn’t be bothered to actually try to compile it or check if it works. I got rid of the input pin for automatic mode, I just assume that the weapon is in this mode if it isn’t set on burst or full. That saves you some cabling.

/*
 The circuit:
 * NPN attached to pin 13
 * pushbutton attached to pin 6 from +5V   (Remapped from pin 1)
 * pushbutton attached to pin 2 from +5V
   (Pin 3 has been eliminated)
 * pushbutton attached to pin 4 from +5V
 * pushbutton attached to pin 5 from +5V
 * 10K resistor attached to pin 6 from ground
 * 10K resistor attached to pin 2 from ground
 * 10K resistor attached to pin 4 from ground
 * 10K resistor attached to pin 5 from ground
 
 * Note: on most Arduinos there is already an LED on the board
 attached to pin 13.
 
 
 created 2005
 by DojoDave <http://www.0j0.org>
 modified 07 Feb 2011
 by eliofall
 
 This example code is in the public domain.
 */

// constants won't change. They're used here to
// set pin numbers:
const int trigger      = 6;	// Don't use pin1. Remapped to 6
const int safety       = 2;
// automatic has been eliminated
const int burst	        = 4;
const int full	        = 5;     
const int ledPin     = 13;      // goes to an 2n2222 to turn on the led & selonoid

const int burstSize = 3;	// How many shots in a burst

void setup() {
  pinMode(ledPin	, OUTPUT);      
  pinMode(trigger	, INPUT);
  pinMode(safety	, INPUT);
  pinMode(burst	, INPUT);
  pinMode(full		, INPUT);   
}

void loop() {
  // These 2 variables are remembered between function calls
  static int burstCount = 0;	// How many shots already done
  static int oldTriggerState = HIGH;  // Used to check if trigger has been released

  // read the state of the pushbutton value:
  int triggerState = digitalRead(trigger);
  int safetyState = digitalRead(safety);

  // We convert the buttons for the shooting mode into one variable where
  // 1 = burst mode and 2 = automatic mode.
  // 0 is default for single shot
  int shotMode = 0;
  if (digitalRead(burst) == HIGH) {
    shotMode = 1;
  }
  else if (digitalRead(full) == HIGH) {
    shotMode = 2;
  }

  // Only do something if the safety is pressed
  if (safetyState == HIGH) {

    // Check if trigger is pressed
    if (triggerState == HIGH) {

      // Here we handle burst and full state
      if (shotMode == 2
        || (shotMode == 1 && burstCount < burstSize)) {

        // We reset oldTriggerState to avoid duplicating the
        // the code for the actual shooting.
        oldTriggerState = LOW;
		
        // Increment burstCount. It'll be checked later
        burstCount++;
      }

      // Shoot
      // We checked if the trigger is pressed above, so we
      // don't need to check it again. We only check, if the trigger
      // was released before being pressed. This can happen in two ways:
      // For single shot by releasing the trigger, for burst and full mode
      // by the code right above
      if (oldTriggerState == LOW) {
        // I assume that part works correctly
        digitalWrite(ledPin, HIGH);
        delay(10);
        digitalWrite(ledpin, LOW);    
        delay(70);  
      }

      // Check if an additional lockout time in single shot mode or
      // a full burst is necessary
      if (shotMode == 0
        || (shotMode == 1 && burstCount >= burstSize)) {
        // Just wait for 430ms. Adapt as desired
        delay (430);
      }
    }
    else {
      // Trigger has been released. Reset burst counter
      burstCount = 0;
    }

    // Remember current triggerState for next run of the function
    oldTriggerState = triggerState;
  }
}

Perhaps that helps. If you find bugs, you can keep them and fry them with a garlic sauce to make a crunchy snack.

Korman