Im new to the coding aspect here.
I think this should be simple but I'm doing something wrong !
I have a board connected to a small led with cables to 5v , grnd and s8 (digital pin 8)
To turn on my led I have code; so effectively the light is on once I plug in power.
Id like to detect a mag lock opening ie no power and then turn this light on.
Im not sure how to put the eif statement in and what to wire. I have a relay that I connected to the mag lock but not sure how to detect the low of power from the relay or what wires to connect to relay.
Im hoping that all make sense in some way and someone can help?
not sure why you want to use a microcontroller for this but assuming your mag-lock is wired in a similar fashion as below, IMHO, a simple transistor circuit would do!
The circuit shown by haffyj is possibly AC so using leds can be a bit tricky. If the NO contact is available use it with a diode, led, and resistor in series be sure the cathode of one connects to the anode of the other. This is to protect the LED from to high of a reverse voltage. If that contact is not available then connect the LED, diode and resistor across the Mag Lock (NC) and ground It should not draw enough to keep the lock on. If it is DC the diode is not needed. Either case you will have to determine the resistance since you did not state the voltage.
Then you can use the unused set of contacts if there is one or match the voltage with what the relay is switching and connect the LED to the other contact. You can use a multimeter to check this.