able to read and respond to two inputs individually but cant together

I have a window sensor that is NO and a PIR motion sensor that is NC. If i get a 1 from the window sensor i have the alarm buzzer turn on. If i get a 0 from the PIR the buzzer turns on. If i comment one or the other out, they each work individually but if i uncomment them and put them together, neither work. copy and pasted relevant code. Using arduino Mega. Any ideas what i'm doing wrong?

 int MSensorOut = 24;     // the number of the output pin
 int MSensorIn =  25;   // the number of the LED pin
int WSensorOut = 29;     // the number of the output pin
int WSensorIn =  42; 
 int alarmState = 43;
int readingW;    // the current reading from the input pin window
int readingM;     // Motion sensor

void setup(){
      pinMode(alarmState, OUTPUT);
    pinMode(WSensorIn, INPUT); 
  pinMode(WSensorOut, OUTPUT); 
  digitalWrite(WSensorOut, HIGH);       //sends one to WSensorIn
        digitalWrite(alarmState, LOW);   
     pinMode(MSensorOut, OUTPUT); 
  digitalWrite(MSensorOut, HIGH);      // sends one to MSensorIn
  pinMode(MSensorIn, INPUT);   
}
void loop()




{  
;

    
 readingW = digitalRead(WSensorIn);

    
 if (readingW == HIGH) {
   digitalWrite(alarmState, HIGH);}
  else {
     digitalWrite(alarmState, LOW);
     
   }

 readingM = digitalRead(MSensorIn);

    
 if (readingM == LOW ) {
   digitalWrite(alarmState, HIGH);
   delay (1500);}
  else {
     digitalWrite(alarmState, LOW);
     
   }

we'll start by making it look like code

 int MSensorOut = 24;     // the number of the output pin
 int MSensorIn =  25;   // the number of the LED pin
int WSensorOut = 29;     // the number of the output pin
int WSensorIn =  42;
 int alarmState = 43;
int readingW;    // the current reading from the input pin window
int readingM;     // Motion sensor

void setup(){
      pinMode(alarmState, OUTPUT);
    pinMode(WSensorIn, INPUT);
  pinMode(WSensorOut, OUTPUT);
  digitalWrite(WSensorOut, HIGH);       //sends one to WSensorIn
        digitalWrite(alarmState, LOW);   
     pinMode(MSensorOut, OUTPUT);
  digitalWrite(MSensorOut, HIGH);      // sends one to MSensorIn
  pinMode(MSensorIn, INPUT);   

void loop()




{ 

 
 readingW = digitalRead(WSensorIn);

   
 if (readingW == HIGH) {          // If window is open
   digitalWrite(alarmState, HIGH);
 delay(1000);}
  if (readingM == LOW){
   digitalWrite(alarmState, HIGH);
 delay(1000);}
  else {
     digitalWrite(alarmState, LOW);
     
   }

 readingM = digitalRead(MSensorIn);

   
 if (readingM == LOW) {            // if motion is detected
   digitalWrite(alarmState, HIGH);
   delay (1500);}
  else {
     digitalWrite(alarmState, LOW);
     
   }

i tried to tidy it so I could read it
it complains "too many left curly braces"
have you compiled it?

ok added a sprinkling of "}"
tidied it
now it compiles

int MSensorOut = 24;     // the number of the output pin
int MSensorIn =  25;   // the number of the LED pin
int WSensorOut = 29;     // the number of the output pin
int WSensorIn =  42;
int alarmState = 43;
int readingW;    // the current reading from the input pin window
int readingM;     // Motion sensor

void setup(){
  pinMode(alarmState, OUTPUT);
  pinMode(WSensorIn, INPUT);
  pinMode(WSensorOut, OUTPUT);
  digitalWrite(WSensorOut, HIGH);       //sends one to WSensorIn
  digitalWrite(alarmState, LOW);   
  pinMode(MSensorOut, OUTPUT);
  digitalWrite(MSensorOut, HIGH);      // sends one to MSensorIn
  pinMode(MSensorIn, INPUT);   
}
void loop()
{ 
  readingW = digitalRead(WSensorIn);

  if (readingW == HIGH) 
  {          // If window is open
    digitalWrite(alarmState, HIGH);
    delay(1000);
  }
  if (readingM == LOW)
  {
    digitalWrite(alarmState, HIGH);
    delay(1000);
  }
  else 
  {
    digitalWrite(alarmState, LOW);
  }

  readingM = digitalRead(MSensorIn);


  if (readingM == LOW) 
  {            // if motion is detected
    digitalWrite(alarmState, HIGH);
    delay (1500);
  }
  else 
  {
    digitalWrite(alarmState, LOW);
  }
}

you have very misleading names for your pins

there is no "else" clause when you test readingW

you are testing readingM before you set it
and then again after you set it

you have delays after setting the alarmState HIGH but not after setting it low

I updated the code to the actual one that was working individually

so wrap it in
[ code]
your code
[ / code]

without the spaces!

mmcp42:
so wrap it in
[ code]
your code
[ / code]

without the spaces!

thank you, still new to this, I was trying to find out how to that

you seem to be declaring loop inside setup?!?!?
take a look at what I posted for you

mmcp42:
you seem to be declaring loop inside setup?!?!?
take a look at what I posted for you

sorry my code is all over the place, in trying to get this work i added and removed a great deal of code and just decided to comment the code i wasnt using. in copy and pasting code fragments i forgot to put the closing brackets in the posted code. but it is there. thanks for your patience

well it's gonna b hard to debug something that doesn't compile or represent the problem!

mmcp42:
well it's gonna b hard to debug something that doesn't compile or represent the problem!

I completely understand, just wanted to give it a shot and see if anyone had some suggestions on why the program can read only one at a time.

take a look at my post #4
I left some clues :slight_smile: