An electric car horn
The electric car horn was invented for safety; to warn others of vehicles approaching, their presence, or to gain attention to a potential hazard. Most vehicles, as well as bicycles, trains, and ships, are required by law to have horns.
The horn system includes a steel diaphragm, a contractor, and electromagnet. In simple terms, when you press down on the horn from your vehicle, it triggers the electromagnet, which causes the diaphragm to move. Once the diaphragm reaches its maximum point, the contractor momentarily cuts off the current (putting the diaphragm back in its original position). This process is repeated and the back and forth movement is what causes the sound to come out.
Other Types of Horns
Bulb horn that works by squeezing the rubber bulb.
Air horns that are operated by the compressed air from the train's air brake system.