Halteres

Halteres are small knobbed structures modified from the hind wings in flies. They vibrate during flight, and help the insect fly better.
The halteres evolved from wings. Ancestral flying insects had two pairs of wings, like dragonflies, hymenoptera and lepidoptera still do. Flies have only the front pair of wings.
Function.
Halteres help balancing and improve flight. They help flies to perform their fast aerobatics. In addition to providing rapid feedback to the muscles steering the wings, they also help stabilise the head during flight.
They are flapped rapidly and work as gyroscopes, telling the insect about its body position during flight.
Every vibrating object tends to maintain its plane of vibration, a result of the Coriolis effect. If the body of the insect changes direction in flight or rotates about its axis, the vibrating halteres exert a force on the body. The insect detects this force with sensory organs at the base of the halteres.
The two halteres vibrate in different planes, each forming an angle of about 45 degrees with the long axis of the insect. This increases the information got from the halteres.
Development.
In Diptera, the formation of the haltere during metamorphosis is dependent on the homeotic gene "Ultrabithorax" (Ubx). If this gene is experimentally deactivated, the haltere will develop into a fully developed wing. This is an excellent illustration of an important mechanism of evolutionary development; a simple homeotic gene change can result in a radically different phenotype.
Convergent evolution.
The Strepsiptera, small insects parasitic on bees, wasps and cockroaches, also have halteres. We know the evolution was independent because in the Strepsiptera the "forewings" evolved into halteres while, in the Diptera, the "hindwings" changed into halteres. This is a classic case of convergent evolution.
Grimaldi and Engel say halteres have evolved at least seven times in insects, and "in most cases it is known to be associated with improved manoeuvering in flight".