Hello,
I’ve been working on an Arduino-based pneumatic Nerf gun that functions much like a revolver and features full and semi automatic fire. The (15) rotating barrels are mounted on a hub and connected to a motor with a gearbox. Using a limit switch, the barrels can be indexed 24 degrees (360/15=24) to align each new barrel with the air outlet after every shot. The air outlet is controlled by a solenoid. The Arduino operates the motor and solenoid through the [NKC Motor Shield.
In most of my tests, the setup worked just fine. However, when I used the full-auto loop and reduced the delays that affect the rate of fire, the motor will start acting strange. It will suddenly start to rotate very slowly in brief, fast pulses of rotation. These pulses are not characteristic of anything my program might cause. They can be set off by subjecting the gun to a prolonged period of high rate of fire. Once it happens, the motor is stuck doing this regardless of any input from the gun’s switches. (Although I should note the pulses are slowed down by some, though never stopped). To break the cycle, the motor must be disconnected from the shield and reconnected, then it will work fine again instantly until the next bunch of pulses are set off. Throughout this process, the SN754410NE motor driver becomes extremely hot, enough to burn my skin.
Does anyone have an idea of what might be going on here? I’ve tried dozens of variations in my program to stop this problem but it persists. Could it be that the motor shield is not meant to handle such rapid switching?
Thanks!
Here it is working properly at low RoF. (I have to hold the limit switch myself, it’s not fully assembled yet)
http://s237.photobucket.com/albums/ff15 … nt=fai.mp4
Here it is after getting stuck at high RoF.
http://s237.photobucket.com/albums/ff15 … D00022.mp4
Here is the sketch:
//Naming input pins
#define trigger 2
#define indexing 8
#define selector 7
//Naming output pins
#define motor 10
#define dir_motor 13
#define valve 9
#define dir_valve 12
//Declaring variable with start value of 0
int indexingstate = 0;
int triggerstate = 0;
int oldtriggerstate = 0;
int selectorstate = 0;
void setup(){
//Set input pins as inputs
pinMode(trigger, INPUT);
pinMode(indexing, INPUT);
pinMode(selector, INPUT);
//Set output pins as outputs
pinMode(motor, OUTPUT);
pinMode(dir_motor, OUTPUT);
pinMode(valve, OUTPUT);
pinMode(dir_valve, OUTPUT);
//Setting motor and valve direction (irrelevant)
digitalWrite(dir_motor, LOW);
digitalWrite(dir_valve, LOW);
}
void loop(){
//Read and store value of selector switch
selectorstate = digitalRead(selector);
//Begin semi-auto loop
if(selectorstate == HIGH){
//Read and store value of trigger switch
triggerstate = digitalRead(trigger);
//debounce delay
delay(20);
//If there is a transition from not pressed to pressed, Fire!
if((triggerstate == HIGH) && (oldtriggerstate == LOW)){
//Run motor until indexing switch is hit
do{
analogWrite(motor, 255);
//possible delay
delay(10);
indexingstate = digitalRead(indexing);
}while(indexingstate == LOW);
//Stop motor
analogWrite(motor, 0);
//Open valve for 1 second
delay(50);
analogWrite(valve, 255);
delay(50);
//Close valve
analogWrite(valve, 0);
//RoF delay
delay(10);
}
//If trigger is not pulled, do nothing.
else{
analogWrite(motor, 0);
analogWrite(valve, 0);
}
//store current value of trigger switch as old value
oldtriggerstate = triggerstate;
}
//Begin full-auto loop
else{
//Read and store value of trigger switch
triggerstate = digitalRead(trigger);
//Debounce delay
delay(20);
//If trigger is pulled, Fire!
if(triggerstate == HIGH){
//Run motor until indexing switch is hit
do{
analogWrite(motor, 255);
delay(50);
indexingstate = digitalRead(indexing);
}while(indexingstate == LOW);
//Stop motor
analogWrite(motor, 0);
//Open valve for 1 second
delay(30);
analogWrite(valve, 255);
delay(30);
//Close valve
analogWrite(valve, 0);
//RoF delay
delay(50);
}
//If trigger is not pulled, do nothing.
else{
analogWrite(motor, 0);
analogWrite(valve, 0);
}
}
}
Here is a concept picture of the limit switch:
http://i237.photobucket.com/albums/ff15 … witch2.png](Assembling the Freeduino (Arduino) Motor Shield « MCUKITS)