How does a Solenoid Work?

A solenoid is a coil of wire usually wrapped around a piston made of iron and uses an electonmagnetic current to convert electrical energy to mechanical energy by allowing the piston to either move backward or forward as the current is turned on or off. The electromagnets have a big advantage over regular magnets because they can be turned on or off creating an automated switch.