How can I detect if a garage door is opened or closed?
In many home security systems they use magnet switches to detect the state of the door.

You could also use something like IR to see if a certain part of the door frame is blocking the light.

And one more option is to sense if the door is horizontal or vertical, basically you would mount it to the inside of the door, when it opens it would be horizontal and closed would be vertical. This is actually how most of the off-the-shelve generic sensors work.

If you have a particular method that you prefer I can give some specific sensor recommendations as well.

Edit: I missed that you said you wanted it 4 meters from the door. I am not sure if you just want this because you don't want to deal with wireless, but the IR method can also work in which you put something that reflects IR on the door and then have your sensor look to see if your IR beam has been reflected or not.



Some more additions:

If it were me, I would get something like this, there are lots of other brands and methods that are used. Buying sensors and wireless modules can be pretty expensive when bought in quantity 1 and probably wont be worth the cost over just buying the off the shelf method.

Now if it were me wanting to tackle a fun project, I would use an accelerometer attached to the inside of the door (could even be a board just Velcro'd to the inside of the door). The accelerometer doesn't need to be anything special, just something that when attached can detect acceleration in the down direction when the door is vertical and the down direction when the door is horizontal. It so happens that the force of gravity will show up on an accelerometer. I would then use an Xbee module to transmit the status to an xbee that is inside.

Realistically you don't need to transmit very much very often, you could put everything into sleep mode when ever you aren't reading and then once every minute or so wake up and transmit the current state. Because of how little the device is on it could easily run off of a battery for a decently long time.

There may be other, better, methods of detection, but when ever I do a "for fun" project I like using parts that I might use in other projects. It helps to grow the intellectual property that I have, which is useful for the future.