Help with getting two magnetic reed switches to trigger one LED

I'm a novice with Arduino and I'm trying to build a couple door sensors for my double doors with a 8266 nodeMCU. My end goal is to have either one of the switches trigger "whatever." For my testing purposes I'm using an LED. For some reason only one switch(switchPin0/switchValue0) triggers the LED. My code is -

int switchPin0= 0;
int switchPin1 = 5;
int LedPin = 16;
int switchValue0;
int switchValue1;

void setup() { 
  pinMode(LedPin, OUTPUT);
  pinMode(switchPin0, INPUT);
  pinMode(switchPin1, INPUT);
}

void loop() {
  // Read the switch value
  switchValue0 = digitalRead(switchPin0);
  switchValue1 = digitalRead(switchPin1);

if (switchValue0 == HIGH || switchValue1 == HIGH)

{

digitalWrite(LedPin, HIGH);
}

else

{

digitalWrite(LedPin, LOW);

}

}

You are not using the if statement correctly. Try this line of code and it will work fine:

if ((switchValue0 == HIGH) || (switchValue1 == HIGH))

Thank You for the quick reply!

Unfortunately, I'm getting the same result. switchValue0 works, switchValue1 does not.

Latest version

int switchPin0= 0;
int switchPin1 = 5;
int LedPin = 16;
int switchValue0;
int switchValue1;

void setup() {
  pinMode(LedPin, OUTPUT);
  pinMode(switchPin0, INPUT);
  pinMode(switchPin1, INPUT);
}

void loop() {
  // Read the switch value
  switchValue0 = digitalRead(switchPin0);
  switchValue1 = digitalRead(switchPin1);

if ((switchValue0 == HIGH) || (switchValue1 == HIGH))

{

digitalWrite(LedPin, HIGH);
}

else

{

digitalWrite(LedPin, LOW);

}

}

jacklesplat:
Unfortunately, I'm getting the same result. switchValue0 works, switchValue1 does not.

Post the latest version of your program so we can see exactly what you tried.

...R

I've tried switching inputs and different pins, but only switchValue0 is working.

My latest version

int switchPin0 = 0;
int switchPin1 = 14;
int LedPin = 16;
int switchValue0;
int switchValue1;

void setup() { 
  pinMode(LedPin, OUTPUT);
  pinMode(switchPin0, INPUT);
  pinMode(switchPin1, INPUT);
}

void loop() {
  // Read the switch value
  switchValue0 = digitalRead(switchPin0);
  switchValue1 = digitalRead(switchPin1);


if ((switchValue0 == HIGH) || (switchValue1 == HIGH))

{

digitalWrite(LedPin, HIGH);
}

else

{

digitalWrite(LedPin, LOW);

}

}

Have you verified that the second switch actually works?

If you try the IF statement using only (switchValue1 == HIGH) what results do you get.

I commented out the ((switchValue0 == HIGH)) out of my IF statement and when I make contact on the switch attached to pin0 (switchValue0) it still works, and the switch attached to pin 4(switchValue1) still doesn't work.

int switchPin0 = 4;
int switchPin1 = 0;
int LedPin = 16;
int switchValue0;
int switchValue1;

void setup() { 
  pinMode(LedPin, OUTPUT);
  pinMode(switchPin0, INPUT);
  pinMode(switchPin1, INPUT);
}

void loop() {
  // Read the switch value
  switchValue0 = digitalRead(switchPin0);
  switchValue1 = digitalRead(switchPin1);

if /*((switchValue0 == HIGH) ||*/ ((switchValue1 == HIGH))

{

digitalWrite(LedPin, HIGH);
}

else

{

digitalWrite(LedPin, LOW);

}

}

Can you post a picture or wiring diagram of your switches?

Attached a diagram

Not familiar with the nodeMCU, but on an arduino you would need either pull-up resistors on the input pins for the switches, or use the internal pullups by setting pinMode as INPUT_PULLUP instead of INPUT.

The way you have it wired, when the switch is closed the input will be LOW, when the switch is open it will be HIGH.

Also makes me a bit nervous seeing an LED without a current-limiting resistor, unless that is built-in on that particular board.

That did it! Thank you! Also, I do have a 220 resistor soldered inline on that LED that I had leftover from another project. I updated the code with the INPUT_PULLUP and changed my IF statement to watch for the LOW value.

Updated Code

int switchPin0= 14;
int switchPin1 = 13;
int LedPin = 16;
int switchValue0;
int switchValue1;

void setup() {
  pinMode(LedPin, OUTPUT);
  pinMode(switchPin0, INPUT_PULLUP);
  pinMode(switchPin1, INPUT_PULLUP);
}

void loop() {
  // Read the switch value
  switchValue0 = digitalRead(switchPin0);
  switchValue1 = digitalRead(switchPin1);

if ((switchValue0 == LOW || switchValue1 == LOW))

{

digitalWrite(LedPin, HIGH);
}

else

{

digitalWrite(LedPin, LOW);

}

}