How does autorotation work on the iPhone (in terms of hardware, not software)
Solution 1:
In the older iOS devices it's the accelerometer - it is detecting the constant acceleration due to gravity.
Normal motion produces only short bursts of acceleration, not long enough to trigger rotation.
If you put your iOS device in a fast car and accelerated it for several seconds you could probably get it to autorotate the wrong way.
Solution 2:
It´s called a gyroscope. Have a look at this article on iFixit, it explains it (within an iPhone 4) quite well.