Adjusting the strength of an electromagnet