By far the easiest way to do this is to connect a switch to the door that opens/closes as the door opens/closes. This assumes that when you say "the door moves" you really meant "is opened or closed".
Whether the switch is normally open or normally closed doesn't matter. Wire the switch to a serial port; connect one side to DTR, the other to CD. Now you can write a program that runs a loop that (1) opens the blocking tty device, then (2) reads the descriptor, which will block until CD drops returning an error from read(2), at which point you close the descriptor and repeat the loop. (1) will complete when the switch closes. (2) will complete when the switch opens. After each event, you can perform whatever actions you want.