A relay is basically a switch,… an electromagnetic switch. A small current flowing through a coil in the relay create a strong magnetic field that pulls one switch contact against or away from another. What really cool about relay is, you can use a low voltage, or a low current to control a higher voltage or current. While semiconductor switching devices, or transistors, are faster and more reliable, relays retain some advantages. They provide complete electrical isolation between circuits. Some relays can handle double-throw or multiple pole switching. And you can really control high voltage, or high current at a really cheap price.
There are two basic types of relay. Latching and nonlatching. Nonlatching relays are the most common. They resemble a momentary switch, in that its contacts spring back to their default-position when power to the relay is interrupted.Latching relays, on the other hand, have no default position. They almost always have double throw contacts which remain in either position without drawing any power. Only short pulse of power required to change the relay’s contact status.These two type of relay can look really similar. Make sure you get the correct type for your application.
Relay pin outs are lack of standardization. Be sure to check the datasheet for your particular relay.
Normally, you would apply a small signal from microcontroller, to the base of a transistor, which then control the relay. Note that a rectifier diode wired in parallel with the relay coil for protecting the coil from possible voltage spikes.