A self-calibration method was proposed to compensate the drawback generated by classic ellipsoid fitting algorithm. In this paper magnetometers and accelerometers were chosen to obtain geomagnetic field and gravitational field for TRIAD algorithm. The first step is using the classic ellipsoid fitting to calibrate the magnetic vector, which is taken as an internal reference in the second step. Due to the direction the geomagnetic vector and gravity vector are relatively invariant; therefore the projection of geomagnetic vector on gravitational vector is a constant value. The second step is using projection method to calibrate accelerometer. At last, both simulation and experiment were taken to prove the accuracy of the calibration method.