Automatic Garage Door Closer

Sounds like a good project, I've done some thinking about something similar myself.

Regarding the circuit, the sensor switch is in the wrong place. When it closes, it will short the 5V supply to ground, not what we want. Plus the green LED will never illuminate, as it's connected to an input pin. As for the relay, without knowing the specs for the unit you have in mind, the circuit as shown will only put 5mA through the relay coil. Most relays require considerably more, in fact, most require more than the 20mA that an Arduino pin can safely supply. A small NPN junction transistor is usually a great way to drive a relay.

Regarding the code, it's fairly minimal, it looks like it will operate pretty much as you expect. Obviously, this is a project I'd test on the bench to ensure it works as expected before installing it on the garage door. I might add a couple things, one being an alarm. When the code decides it needs to close the door, I'd sound an audible alarm for maybe 30-60 sec first before activating the relay. I might also have an override switch to stop the controller from closing the door for those times when I wanted the door to stay open more than five minutes. Finally, when the controller decides to close the door, it's an open-loop situation, meaning that it activates the relay but then just assumes the door closes properly. Most garage doors have safety mechanisms that could make that a bad assumption. Mine has a light beam across the bottom that if interrupted, will prevent the door from closing. If too much force is required to close the door, i.e. something blocking it, or a spring breaks, etc., it will reverse, open the door, and stop. The upshot of all this is that the controller may not really be aware of the state of the door. I can make suggestions to address this if you're interested.