what is the problem in this motor control arduino code

Or you could put all your movement code inside the Serial. available condition with an extra pair of {} braces.