Smartphones use gyro sensor to detect the orientation of the device(smartphone). It's a gyroscope in the form of a small sensor. It is calibrated to give a reading of zero when the device is kept on a plane horizontal surface. Any change in orientation of the device is measured by the gyro sensor.