There is also a convention, that I strongly urge you to follow, of one statement per line. I also suggest that for readability purposes, open and closing braces so no belong on the same line as the statement that they go with. Use white space around operators and proper indenting, so one can read the code.
This:
if (MD=2){
if (OD=0){TM++;delay (20);
if(TM<32){Door.write(10);} //.2 sec/30deg of movement therefore Rotate 90deg = 300mS or 15 cycles
if(TM>40){Latch.write(45);} // delay, open main door 180deg=600ms 600ms/20 per cycle= 30 cycles
if(TM>52){OD=1;CD=0;TM=0;} //disable close, enable open reset TiMer
}
}
should be:
if (MD == 2)
{
if (OD == 0)
{
TM++;
delay (20);
if(TM < 32)
{
Door.write(10);
} //.2 sec/30deg of movement therefore Rotate 90deg = 300mS or 15 cycles
if(TM > 40)
{
Latch.write(45);
} // delay, open main door 180deg=600ms 600ms/20 per cycle= 30 cycles
if(TM > 52)
{
OD = 1;
CD = 0;
TM = 0;
} //disable close, enable open reset TiMer
}
}
One can much more easily read this code, even though it takes more lines, and one can see where the blocks stop and end.
Another thing to consider is that there is convention that all capital letter names are constants, and one does not assign values to constants. Variables should have obvious names. OD, CD, and TM don't mean squat. Door and Latch are, on the other hand, good names. It is quite clear what they are.