In this paper, an MEMS gyro aided on line calibration algorithm for electronic compass is presented. This electronic compass module consists of a three-axis AMR sensor, a two-axis MEMS tilt sensor and a one-axis MEMS gyro. The automatic calibration method requires to rotate the electronic compass two full 360-degree revolution. In this rotation procedure, magnetic field data, attitude data and angular rate data are recorded. Based on recorded magnetic field data and attitude data, raw heading data is calculated. This raw heading data is verified by angular rate output of MEMS gyro. Results of experiment show that the accuracy of calibrated compass is better than 0.5 deg and MEMS gyro aided on line calibration algorithm is effective for electronic compass.