// Contact D2 to GND; D3 to OUT-4 IN1 constexpr int CONTACT_PIN = 2; constexpr int FAN_PIN = 3; void setup() { pinMode(CONTACT_PIN, INPUT_PULLUP); digitalWrite(FAN_PIN, LOW); pinMode(FAN_PIN, OUTPUT); } void loop() { const bool closed = digitalRead(CONTACT_PIN) == LOW; digitalWrite(FAN_PIN, closed ? HIGH : LOW); delay(10); }