I have a magnetic switch like this https://images.app.goo.gl/BcjamziGH2PFNXtXA
It is used on doors/windows. In security panels when the door is opened (switch off - circuit is cut) the alarm sounds on.
I want to use it in a project. So far in my projects i was checking if the switch/button is pressed.
My problem is to write a code to test if the button/switch is unpressed/opened. When it is opened i want a buzzer to sound or a led to light on. Can you help me with this code?
Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu. [code]Paste your sketch here[/code]
Switches only have 2 states. If you can already test that it is ON/pressed/closed (which will be HIGH or LOW depending how it is wired) then checking that it is OFF/unpressed/open is just testing for the other one (LOW or HIGH). It doesn't get much simpler than that.