Programming Problem, how to get the secound Sequence to work

When I hit any of my two sensors they both trigger the first
(myIra<500){ sequence) but cant get the other sensor to operate the
second part of the code which is , “else if(myIrb<500){ second
sequence)”.
Don’t think its a hardware issue as my sensors are both in working
order and each in the correct analog pins 1 and 2.

Can you see something in the program that would cause this???

Thanks Again
Lourens Botha

int mota = 2; // motor / buzzer
int leda1 = 3; // hit target
int leda2 = 4; // when hit
int leda3 = 5; // reload
int motb = 6; // motor / buzzer
int ledb1 = 7; // hit target
int ledb2 = 8; // when hit
int ledb3 = 9; // reload

int triggera = 0;
int IRsensorPina = 1; // Infrared Receiver connected to digital pin 9
int triggerb = 3;
int IRsensorPinb = 2; // Infrared Receiver connected to digital pin 9

boolean loadeda = false;
boolean hita = false;
boolean shota = false;
boolean loadedb = false;
boolean hitb = false;
boolean shotb = false;

// The setup() method runs once, when the sketch starts

void setup(){
pinMode(mota, OUTPUT);
pinMode(leda1, OUTPUT);
pinMode(leda2, OUTPUT);
pinMode(leda3, OUTPUT);
pinMode(motb, OUTPUT);
pinMode(ledb1, OUTPUT);
pinMode(ledb2, OUTPUT);
pinMode(ledb3, OUTPUT);
Serial.begin(9600);
}

void loop()
{
loadeda = false;
loadedb = false;
int myIra = analogRead(IRsensorPina);
int myIrb = analogRead(IRsensorPinb);

if(loadeda){
digitalWrite(leda3,0);
}else{
digitalWrite(leda3,1);
}
if(loadedb){
digitalWrite(ledb3,0);
}else{
digitalWrite(ledb3,1);
}

if(myIra<500){
digitalWrite(mota,0);
digitalWrite(leda2,1);
digitalWrite(leda1,1);
digitalWrite(leda3,1);
digitalWrite(ledb2,1);
digitalWrite(motb,0);
delay(2000);
for(int x=0; x<5; x++){
digitalWrite(leda2,0);
digitalWrite(leda1,1);
digitalWrite(mota,1);
digitalWrite(leda3,1);
digitalWrite(ledb2,0);
digitalWrite(motb,1);
delay(400);
digitalWrite(mota,0);
digitalWrite(leda2,0);
digitalWrite(leda1,1);
digitalWrite(ledb2,1);
digitalWrite(motb,0);
delay(600);
digitalWrite(mota,1);
digitalWrite(leda2,0);
digitalWrite(leda1,1);
digitalWrite(leda3,1);
digitalWrite(ledb2,0);
digitalWrite(motb,1);
delay(800);
digitalWrite(leda2,0);
digitalWrite(leda1,1);
digitalWrite(mota,0);
digitalWrite(leda3,1);
digitalWrite(ledb2,1);
digitalWrite(motb,0);
delay(200);
}
}else if(myIrb<500){
digitalWrite(mota,0);
digitalWrite(ledb2,1);
digitalWrite(ledb1,1);
digitalWrite(ledb3,1);
digitalWrite(leda2,1);
digitalWrite(mota,0);
delay(2000);
for(int x=0; x<5; x++){
digitalWrite(ledb2,0);
digitalWrite(ledb1,1);
digitalWrite(motb,1);
digitalWrite(ledb3,1);
digitalWrite(leda2,0);
digitalWrite(mota,1);
delay(400);
digitalWrite(motb,0);
digitalWrite(ledb2,0);
digitalWrite(ledb1,1);
digitalWrite(leda2,1);
digitalWrite(mota,0);
delay(600);
digitalWrite(motb,1);
digitalWrite(ledb2,0);
digitalWrite(ledb1,1);
digitalWrite(ledb3,1);
digitalWrite(leda2,0);
digitalWrite(mota,1);
delay(800);
digitalWrite(ledb2,0);
digitalWrite(ledb1,1);
digitalWrite(motb,0);
digitalWrite(ledb3,1);
digitalWrite(leda2,1);
digitalWrite(mota,0);
delay(200);
}
}

Serial.print(myIra);
Serial.print(":");
Serial.println(myIrb);
delay(100);
}

Use code tags, please.

Are you sure you the result of analogRead are what you expect ? I'd write a test sketch that calls analogRead and displays the two values on the serial line, just to be sure.

  int myIra = analogRead(IRsensorPina);
  int myIrb = analogRead(IRsensorPinb);

Typically, people allow a small interval between analogRead() calls.

    for(int x=0; x<5; x++){
      digitalWrite(ledb2,0);
      delay(400);
      digitalWrite(ledb2,0);
      delay(600);
      digitalWrite(ledb2,0);
      delay(800);
      digitalWrite(ledb2,0);
      delay(200);
    }

I don’t get it. Don’t you trust the pin to stay off. Telling it to turn off 20 times seems redundant.

Your two pins are not treated equally by your code - if the first test succeeds then the other pin is ignored - is that what you want?

How are they wired up? Could they be electrically coupled in some manner?

What is the impedance of the sensor driving these analog pins?

The code would be clearer if you'd put each sequence inside its own function.

PaulS:   int myIra = analogRead(IRsensorPina);   int myIrb = analogRead(IRsensorPinb);

Typically, people allow a small interval between analogRead() calls.

There is no problem with calling analogRead repeatedly if the voltage source has a low enough impedance (10k or less). If the source is higher impedance and you are reading from more than one pin, then accuracy might be enhanced by reading each pin twice (to allow a longer time for the high impedance source to charge the sample and hold capacitor on the ADC converter).