#define SWITCH_PIN 2 // Pin connected to the switch
#define RELAY_PIN 3 // Pin connected to the relay module
void setup() {
pinMode(SWITCH_PIN, INPUT_PULLUP); // Set switch pin as input with internal pull-up resistor
pinMode(RELAY_PIN, OUTPUT); // Set relay pin as output
}
void loop() {
int switchState = digitalRead(SWITCH_PIN);
if (switchState == HIGH) {
// Switch is ON, turn on LED 1 (connected to NO terminal of the relay)
digitalWrite(RELAY_PIN, HIGH);
} else {
// Switch is OFF, turn on LED 2 (connected to NC terminal of the relay)
digitalWrite(RELAY_PIN, LOW);
}
}