DC Motors Not Spinning

I have a problem where, once the code is uploaded successfully into Arduino, the motor controller works fine and the motor spin.

However, after first, second, third cycle of rotating, the motor gradually spins slower and slower and finally stops.
But, I can hear the sound of gears in the motor rotating since the code is still running. And I am using the 9V alkaline battery.

My question is what makes it that way, is it because of the battery I am using?

Well you have told us nothing about "the code", "the Arduino", "the motor controller" or "the motor" but if you just want a random guess what you describe just sounds like the battery running out of juice.

And if it is a little rectangular 9V battery that's exactly what you should expect. Maybe try 6 x AA batteries instead.

Steve

Just to underscore what Steve said, 9V PP3 or 'smoke detector' batteries are useless for any application that pulls large current.
Transistor radio that pulls almost no current? Great application for a 9V.
Your application with a motor? No.