Problem
I'm stuck on triggering different switch. I'll explain what each of my switch should do. Output of this setup : No output from relayPin
mainPin
- Main power of the switch to control
relayPin— keeps on/off - Override
reedPinstate - Let
SecondState
reedPin
- Secondary power switch to control
relayPin— depends onmainPinon/off state - Overridden by
mainPin - Let
FirstState
*another explanation in comment
Is it caused by coding or hardware? Pardon my ignorance, it is my beginner code. I would appreciate any help, thank you.
Code
const int reedPin = 8; // Reed Switch
const int mainPin = 9; // Main Switch
const int relayPin = 6; // Relay
int FirstState = 0;
int SecondState = 0;
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(reedPin, INPUT);
pinMode(mainPin, INPUT);
}
void loop() {
FirstState = digitalRead(reedPin);
SecondState = digitalRead(mainPin);
if (FirstState == HIGH) {
digitalWrite(relayPin, LOW);
}
else if (SecondState == HIGH) {
digitalWrite(relayPin, HIGH);
}
else {
digitalWrite(relayPin, HIGH);
}
}
Only else if (SecondState == HIGH) { works in output.

SW1is main switch - referred asfirstStatein code. when this is off,U1(referred assecondStatein code) has no function WhatU1does is simple on/off (reed switch). WhatSW1does enablesU1function Sorry for confusion.