Solenoids are electromagnetic coils wrapped around a tube with a metal plunger inside. When the electricity is turned on, the magnetized coil attracts the plunger and pulls it in. If you attach a permanent magnet to the plunger, then the electromagnet can also repel the plunger when it is turned on and push it out.
Solenoids are used in many mechanisms such as car door locks. In robots, they can be used instead of a motor to push or pull an effector in a straight line. They can also be used to hit objects, like the keys in a robotic xylophone. This model shows how a solenoid uses electricity to move a plunger back and forth.
This project is adapted from my book Robotics: Discover the Science and Technology of the Future, published by Nomad Press.