For MEMS (Micro-Electro-Mechanical System) inertial sensor low precision, high noise and the characteristics of the gyroscope error accumulating, this paper designed a kind of yaw angle measuring system based on EKF (Extended Kalman Filter) by STM32 microcontroller and MEMS sensor. The EKF applys the attitude angle quaternion as the filter state variable, the angular rate as the filter time update. And application of the carrier location's gravitational field and geomagnetic data, complete filter measurement update, suppress divergent attitude error, obtain high accuracy and reliability of the attitude angle (pitch angle, roll angle, yaw angle) data. Experimental results show that the practical application of error control heading within ± 1º, with high practical value.