Microelectromechanical systems, which can be moved or rotated with nanometre precision, already find applications in such fields as radio-frequency electronics, micro-attenuators, sensors and many others. Especially interesting are those which allow fine control over the motion on the atomic scale because of self-alignment mechanisms and forces acting on the atomic level. Such machines can produce well-controlled movements as a reaction to small changes of the external parameters. Here we demonstrate that, for the system of graphene on hexagonal boron nitride, the interplay between the van der Waals and elastic energies results in graphene mechanically self-rotating towards the hexagonal boron nitride crystallographic directions. Such rotation is macroscopic (for graphene flakes of tens of micrometres the tangential movement can be on hundreds of nanometres) and can be used for reproducible manufacturing of aligned van der Waals heterostructures.