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);
}
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);
}
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);
}
}
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