# Accelerometer to pitch and roll

This tutorial describes how an accelerometer can be used to determine an aircraft’s attitude (pitch and roll). An accelerometer measures, as its name hints, acceleration along a predefined axis. As you probably remember from you physics class, the earth’s gravity is also an acceleration (a falling stone keeps going faster and faster). So: with an accelerometer, we can measure the earth’s gravity! This image shows how we do it:

The red arrow represents the earth’s gravity. The blue arrow shows how the accelerometer senses gravity. Note that the axis of this accelerometer is perpendicular to the aircraft (we placed it like that in our aircraft!). The angle theta between the actual gravity vector and the measured gravity is related to the pitch of the aircraft (pitch = theta + 90°). If we know theta, we know our pitch! Since we know the magnitude of the earth’s gravity, simple calculus gives us our pitch angle: accelerometer = cos (theta) * gravity theta = acos (accelerometer / gravity) And since pitch = theta + 90° pitch = asin (accelerometer / gravity)