An accelerometer works on the principle of piezo electric effect. Here, imagine a
cuboidal box, having a small ball inside it, like in the picture above. The walls of this
box are made with piezo electric crystals. Whenever you tilt the box, the ball is
forced to move in the direction of the inclination, due to gravity. The wall with which
the ball collides, creates tiny piezo electric currents. There are totally, three pairs of
opposite walls in a cuboid. Each pair corresponds to an axis in 3D space: X, Y and Z
axes. Depending on the current produced from the piezo electric walls, we can
determine the direction of inclination and its magnitude. For more information
check this.