Heading estimation using inertial sensors built-in smartphones has been considered as a central problem for indoor pedestrian navigation. For practical daily lives, it is necessary for heading estimation to allow an unconstrained use of smartphones, which means the varying device carrying positions and orientations. As a result, three special human body motion states, namely, random hand movements, carrying position transitions, and user turns, are introduced. However, most existing heading estimation approaches neglect the three motion states, which may render large estimation errors. We propose a robust heading estimation system adapting to the unconstrained use of smartphones. A novel detection and classification method is developed to detect the three motion states timely and discriminate them accurately. For normal working, the user heading is estimated by a PCA-based approach. If a user turn occurs, it is estimated by adding horizontal heading change to previous user heading directly. If one of the other two motion states occurs, it is obtained by averaging estimation results of the adjacent normal walking steps. Finally, an outlier filtering algorithm is developed to smooth the estimation results. Experimental results show that our approach is capable of handling the unconstrained situation of smartphones and outperforms previous approaches in terms of accuracy and applicability.