How to check if a button is unpressed

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]

We can give assistance with your code.

Can you help me with this code?

Before you have the hardware connected? Not a chance. At a minimum, you need to post a schematic showing how you have wired the switch to the Arduino.

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.

Steve

slipstick:
It doesn't get much simpler than that.

Agreed.

Which makes me think that the OP's problem is more complex and he has not expressed it clearly.

...R