I have magnetic switches on all my windows and doors. so when the window is open the switch is on. I want to use that to turn on a relay for 1 second even though the switch will stay on for an extended period. I can do that in the sketch no problem but also have a panel on the wall of the floor plan of the house and there is an led where there is a window or a door. I need these leds to stay on while the window is open. Easy way would be to use two output pins one to drive the relay another to drive the led. Is there a way to connect 5 volts in a circuit with the led and the magnetic switch then to the pin to turn on the relay.
Thanks
Rick
Is there a way to connect 5 volts in a circuit with the led and the magnetic switch then to the pin to turn on the relay.
Thanks
Sure! Wire the LED in series with a resistor (as usual). Connect one end of the LED/resistor to +5V and the other end to the switch. Ground the other switch contact. Now when close the switch is closed (turned on), the LED will come on.
Also connect the non-grounded end of the switch to an Arduino input. Enable the Arduino's internal pull-up resistor so make sure the input reads high when the switch is open. When the switch is on (closed) , the Arduino input will be pulled low. Your sketch can read the input state and take appropriate action.