Back to Tutorials Page


A relay is an electro-mechanical switch that opens and closes under the control of another electric circuit. When current flows through the coil of the relay, a magetic field is created that causes an armature to move, either making or breaking an electrical connection. When current is removed from the relay coil, the armature returns to its rest position. It is important to place a diode across the coil of the relay because a spike of voltage is generated when the current is removed from the coil due to the collapse of the magnetic field. This voltage spike can damage the sensitive electronic components controlling the circuit.

The relay we are using in this example has a coil voltage of 5VDC, meaning the relay switch will be activated when 5VDC is supplied across the relay coil. The output pin of an Arduino does supply 5VDC, but the current that the relay requires to activate its switch is greater than the Arduino can safely supply. In this case, a 2N3904 transistor is used to supply a higher current 5VDC source to the relay coil (see multiple LEDs tutorial for more information on this circuit).

The primary reason to use a relay is to switch a circuit of higher current than the Arduino is able to directly handle. A relay switch is much slower than a transistor, but has advantages in certain situations. When using a transistor to switch a higher current and/or voltage circuit, both the controller and switched currents need to share a common ground. There are times when this is not an option (such as switching an AC current circuit with a DC control circuit) and using a relay can be an option because it provides a mechanical separation between the circuits.

Like standard manually operated manual switches, relays come with many different arrangements of switch poles and contacts, such as SPST (single pole, single throw - the relay type used in this example), SPDT (single pole, double throw), DPST (double pole, single throw), DPDT (double pole, double throw), among many others. The relays will have a coil voltage rating, which determines the voltage and current that is necessary to supply to the coil to activate the relay, as well as a rating of maximum current and/or voltage that can be passed through the switch (the relay we are using in this example is small and can only handle 1 amp of current through its switch - larger relays are common and can safely switch much higher currents.


relay breadboard circuit detail


See also high current transistor tutorial for another option for another option of power switching




relay schematic


relay pin layout


2N3904 pin layout