I had a problem on L293D

I don't see anything wrong with the code that isn't turning the motor on and off, at least nothing that is different between it and the other code that would cause it to "hang." Have you tried putting in a few debugging statements in your code? (IE flash the LED or send data to the serial interface).

You might want to check your hardware, you may be getting interference between your motors and your IR receiver. You seem to be able to receive IR signals when the motors are off, but not when on.