weapon Control system

pls help me...

i have designed weapon movement sequence based on joistick comprised with variable resisters...

void loop() { // read the value of the potentiometer: int analogValue1 = analogRead(analogPin1); int analogValue2 = analogRead(analogPin2); int analogValue3 = analogRead(analogPin3); int analogValue4 = analogRead(analogPin4);

// if the analog value is higher than threshold values, turn on the Relays: if (val==HIGH && analogValue1 > threshold1) { digitalWrite(Relay1, HIGH); digitalWrite(Break, HIGH); } else { digitalWrite(Break, LOW); digitalWrite(Relay1, LOW); } if (val==HIGH && analogValue2 > threshold2) { digitalWrite(Relay2, HIGH); digitalWrite(Break, HIGH); } else { digitalWrite(Break, LOW); digitalWrite(Relay2, LOW); }

if (val==HIGH && analogValue3 > threshold3) { digitalWrite(Relay3, HIGH); digitalWrite(Break, HIGH); } else { digitalWrite(Break, LOW); digitalWrite(Relay3, LOW); } if (val==HIGH && analogValue4 > threshold4) { digitalWrite(Relay4, HIGH); digitalWrite(Break, HIGH); } else { digitalWrite(Break, LOW); digitalWrite(Relay4, LOW); }

pls tell me anyone how this if statement works... is it one by one...

Yes, one by one in the same order you have them in your code. Code runs very fast so it is just microseconds between them.

I guess break always seem to be low, and that is the reason for your question. I would move break to a separate if statement like

if (val == HIGH && analogValue1 > threshold1) {
  digitalWrite(Relay1, HIGH);
} else {
  digitalWrite(Relay1, LOW);
}

....

if (digitalRead(Relay1) || digitalRead(Relay2) || digitalRead(Relay3) || digitalRead(Relay4)) {
  digitalWrite(Break, HIGH)
} else {
  digitalWrite(Break, LOW)
}

Break will always be low because not all if Statements can ever be true at the same time.

The Joystick has five positions(top, bottom, left, right, None of the above). At any one time, you are trying to respond to the Position. Assuming that for instance: val==HIGH && analogValue1 > threshold1 you set break high.

Less than a microsecond later, you test val==HIGH && analogValue2 > threshold2. It is probably not true and the program goes to the corresponding else Statement which will set break low again.

If you are going to use all those ifs in sequence, you Need to use elses everywhere.

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :)

  // if the analog value is higher than threshold values, turn on the Relay:
  if (val==HIGH) {
bool r1 = analogValue1 > threshold1;
bool r2 = analogValue2 > threshold2;
bool r3 = analogValue3 > threshold3;
bool r4 = analogValue4 > threshold4;

// If any relay is on, turn on Break
bool br = r1 || r2 || r3 || r4;

    digitalWrite(Relay1, r1);
    digitalWrite(Relay2, r2);
    digitalWrite(Relay3, r3);
    digitalWrite(Relay4, r4);
    digitalWrite(Break, br);
  }

Hi, Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

How have you got your relays wired and in your code you have a variable "val", where does that come from?

We need your COMPLETE code.

Thanks... Tom... :)

And a little more consolidated:

void loop() {
  if (val == HIGH) {
    // if the analog value is higher than threshold values, turn on the Relay:
    bool r1 = analogRead(analogPin1) > threshold1;
    bool r2 = analogRead(analogPin2) > threshold2;
    bool r3 = analogRead(analogPin3) > threshold3;
    bool r4 = analogRead(analogPin4) > threshold4;

    digitalWrite(Relay1, r1);
    digitalWrite(Relay2, r2);
    digitalWrite(Relay3, r3);
    digitalWrite(Relay4, r4);
    digitalWrite(Break, r1 || r2 || r3 || r4);
  }
}

hatmadushantha: pls help me...

i have designed weapon movement sequence ...

Whose side are you on?

This is the Fully code... this is working thanks guys.....I applied this to 30GCM old gun.....

int switchPin = 2; // digital pin to attach the break switch const int analogPin1 = A0; // pin that the sensor is attached to const int analogPin2 = A1; // pin that the sensor is attached to const int analogPin3 = A2; // pin that the sensor is attached to const int analogPin4 = A3; // pin that the sensor is attached to int Break = 7; // pin that the Break relay attched to up int Relay1 = 3; // pin that the relay attched to up int Relay2 = 4; // pin that the relay attched to down int Relay3 = 5; // pin that the relay attched to CW int Relay4 = 6; // pin that the relay attched to CCW const int threshold1 = 700; // Threshold value for operating up motor const int threshold2 = 700; // Threshold value for operating down motor const int threshold3 = 700; // Threshold value for operating CW motor const int threshold4 = 700; // Threshold value for operating CCW motor int val = 0;

void setup() { // initialize the Digital pins as relay output: pinMode(switchPin, INPUT); pinMode(Break, OUTPUT); pinMode(Relay1, OUTPUT); pinMode(Relay2, OUTPUT); pinMode(Relay3, OUTPUT); pinMode(Relay4, OUTPUT); // initialize serial communications: Serial.begin(9600); }

void loop() { // read the value of the potentiometer: int analogValue1 = analogRead(analogPin1); int analogValue2 = analogRead(analogPin2); int analogValue3 = analogRead(analogPin3); int analogValue4 = analogRead(analogPin4); val = digitalRead(switchPin);

if (val== HIGH && analogValue1 > threshold1) { digitalWrite(Relay1, HIGH);// Control signal goes to traversing part as well as Stator winding via common Sngle pole 4out main relay digitalWrite(Break, HIGH); } else if (val== HIGH && analogValue2 > threshold2) { digitalWrite(Relay2, HIGH);// Control signal goes to traversing part as well as Stator winding via common Sngle pole 4out main relay digitalWrite(Break, HIGH); }

else if (val== HIGH && analogValue3 > threshold3) { digitalWrite(Relay3, HIGH);// Control signal goes to traversing part as well as Stator winding via common Sngle pole 4out main relay digitalWrite(Break, HIGH); }

else if (val== HIGH && analogValue4 > threshold4) { digitalWrite(Relay4, HIGH);// Control signal goes to traversing part as well as Stator winding via common Sngle pole 4out main relay digitalWrite(Break, HIGH); } else { digitalWrite (Break, LOW); digitalWrite(Relay1, LOW); // motor power OFF digitalWrite(Relay2, LOW); // motor power OFF digitalWrite(Relay3, LOW); // motor power OFF digitalWrite(Relay4, LOW); // motor power OFF }

// print the analog value: Serial.println(analogValue1); delay(1); // delay in between reads for stability }

TomGeorge: Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :)

Didn't read that did you? If you are too stupid to read that then you are too stupid to play with guns. If you are too lazy to read it then you don't deserve any help.

If you did not understand what it said then you won't understand any answer you get given.

Note you should not cross post. Your other newer thread will get you nowhere.

Hi,
Can you please post a copy of your sketch, using code tags?
They are made with the </> icon in the reply Menu.
See section 7 http://forum.arduino.cc/index.php/topic,148850.0.html

Please… Tom… :slight_smile:

ChrisTenone: Whose side are you on?

one would suspect the OTHER SIDE

of this.

not much use for an automated weapon except to shoot down planes or assassinate the president.

hey, we all have to pick a first project though, right ?

not much use for an automated weapon except to shoot down planes or assassinate the president.

Why must you always see the bad side of everything? Where's your humanity? It could be a malaria mosquito eradication project.

(FWIW, I think your president is safe (whoever she turns out to be) - the IP puts this one in Sri Lanka)

AWOL: (FWIW, I think your president is safe (whoever she turns out to be) - the IP puts this one in Sri Lanka)

whew..... that is good. glad you did not say the IP was on a golf course !

first i would say that this gun was non operatinal at our naval meuseum for last 10 to 12 years. actually i'm plannng make it operational for displaying pupose not to kill anyone....