arduino multiple if statements

I'm try to program a robot for an event at my school. I'm using a arduino mega 2560 to control the robot. The problem that i'm having is with an if statement that is used to to track IR. right now the other parts of the program is blank and I will fill that out later. The part that I want to test is when the IR is in front of the robot then the IR sensor will turn on the fan. Any help is appreciated.

#include <AFMotor.h>

AF_DCMotor motorB(4);
AF_DCMotor motorC(3);

const int trigger = 52;
const int echo = 53;
const int Center_IR = 35 ;
const int Left1_IR = 33;
const int Left2_IR = 31;
const int Right1_IR = 37;
const int Right2_IR = 39;
const int Fan = 22;

void setup()
{
  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(Center_IR, INPUT);
  pinMode(Left1_IR, INPUT);
  pinMode(Left2_IR, INPUT);
  pinMode(Right1_IR, INPUT);
  pinMode(Right2_IR, INPUT);
  pinMode(Fan, OUTPUT);
}

void loop() 
{
  long duration, distance;
  delayMicroseconds(2);
  digitalWrite(trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigger, LOW);
  
  duration = pulseIn(echo, HIGH);
  distance = (duration/2) / 29.1;
  
  if ((Center_IR > 0)||(Left1_IR > 0)||(Left2_IR > 0)||(Right1_IR > 0)||(Right2_IR > 0))
  {
    if(Center_IR > 0)
    { 
     digitalWrite(22,HIGH);
     delay(100);
     digitalWrite(22,LOW);
     delay(1000);

    }
    else if (Left1_IR > 0)
    {
      
    }
    else if(Left2_IR > 0)
    {
      
    }
    else if(Right1_IR > 0)
    {
      
    }
     else if(Right2_IR > 0)
     {
      
    }
    else
    {
      
    }
  }
  else
  {
    
  }
    
}
  if ((Center_IR > 0)||(Left1_IR > 0)||(Left2_IR > 0)||(Right1_IR > 0)||(Right2_IR > 0))
  {
    if(Center_IR > 0)

Your pin numbers are always greater than 0.

thanks

blade1112345:
thanks

Presumably you saw what John was getting at.....

I change the program however the program dose not turn on port 22 even after I trip the sensor. Here is the changed code.

#include <AFMotor.h>

AF_DCMotor motorB(4);
AF_DCMotor motorC(3);

const int trigger = 52;
const int echo = 53;
const int Center_IR = 35 ;
const int Left1_IR = 33;
const int Left2_IR = 31;
const int Right1_IR = 37;
const int Right2_IR = 39;
const int Fan = 22;

void setup()
{
  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(Center_IR, INPUT);
  pinMode(Left1_IR, INPUT);
  pinMode(Left2_IR, INPUT);
  pinMode(Right1_IR, INPUT);
  pinMode(Right2_IR, INPUT);
  pinMode(Fan, OUTPUT);
}

void loop() 
{
  long duration, distance;
  delayMicroseconds(2);
  digitalWrite(trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigger, LOW);
  
  duration = pulseIn(echo, HIGH);
  distance = (duration/2) / 29.1;
  
  if ((Center_IR == 1)||(Left1_IR == 1)||(Left2_IR == 1)||(Right1_IR == 1)||(Right2_IR == 1))
  {
    if(Center_IR == 1)
    { 
     digitalWrite(22,HIGH);
     delay(100);
     digitalWrite(22,LOW);
     delay(1000);

    }
    else if (Left1_IR == 1)
    {
      
    }
    else if(Left2_IR == 1)
    {
      
    }
    else if(Right1_IR == 1)
    {
      
    }
     else if(Right2_IR == 1)
     {
      
    }
    else
    {
      
    }
  }
  else
  {
    
  }
    
}

Missed point error.

const int Center_IR = 35 ;
  if ((Center_IR == 1)

When will Center_IR ever equal 1 ?

Shouldn't you you be reading the value on the Center_IR pin somewhere ?

What John was hinting at is that here for example:

const int Center_IR = 35 ;

.... you make Center_IR be 35. So it then in your first code is always > 0, and in your second code never ==1.

Those are pin numbers, not the values of the pins: you need to read them....

if that is true then how would I write the code so it reads what come into the port and not the port number?

Clue: you're already doing digitalWrite() to send stuff to a pin....

.... so how about digitalRead()

Thank you everyone for helping me out. The code now works. here is the final code that I did if any one has the same problem.

#include <AFMotor.h>

AF_DCMotor motorB(4);
AF_DCMotor motorC(3);

const int trigger = 52;
const int echo = 53;
const int Center_IR = 35 ;
const int Left1_IR = 33;
const int Left2_IR = 31;
const int Right1_IR = 37;
const int Right2_IR = 39;
const int Fan = 22;

void setup()
{
  pinMode(trigger, OUTPUT);
  pinMode(echo, INPUT);
  pinMode(Center_IR, INPUT);
  pinMode(Left1_IR, INPUT);
  pinMode(Left2_IR, INPUT);
  pinMode(Right1_IR, INPUT);
  pinMode(Right2_IR, INPUT);
  pinMode(Fan, OUTPUT);
}

void loop() 
{
  long duration, distance;
  delayMicroseconds(2);
  digitalWrite(trigger, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigger, LOW);
  
  duration = pulseIn(echo, HIGH);
  distance = (duration/2) / 29.1;
  
  if ((digitalRead(Center_IR) == 1)||(digitalRead(Left1_IR) == 1)||(digitalRead(Left2_IR) == 1)||(digitalRead(Right1_IR) == 1)||(digitalRead(Right2_IR) == 1))
  {
    if(digitalRead(Center_IR) == 1)
    { 
     digitalWrite(22,HIGH);
     delay(100);
     digitalWrite(22,LOW);
     delay(1000);

    }
    else if (digitalRead(Left1_IR) == 1)
    {
      
    }
    else if(digitalRead(Left2_IR) == 1)
    {
      
    }
    else if(digitalRead(Right1_IR) == 1)
    {
      
    }
     else if(digitalRead(Right2_IR) == 1)
     {
      
    }
    else
    {
      
    }
  }
  else
  {
    
  }
    
}

Why do you need to test 5 pins then test each of them again ?