How to connect a relay correctly to a microcontroller

Post Reply
User avatar
Shane
Captain
Captain
Posts: 226
Joined: Sun Jul 19, 2009 9:59 pm
Location: Jönköping, Sweden

How to connect a relay correctly to a microcontroller

Post by Shane » Thu Jun 23, 2011 4:40 pm

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.
1.jpg
1.jpg (166.71 KiB) Viewed 3158 times
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.

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.
2.jpg
2.jpg (166.23 KiB) Viewed 3158 times
3.jpg
3.jpg (659.92 KiB) Viewed 3158 times
4.jpg
4.jpg (216.35 KiB) Viewed 3158 times
Courtecy of UMASS AMHERST
Post Reply

Return to “Arduino”