IOGateway tips: Driving Electromagnetic Relays IOGateway - a unified interface for a variety of interface boards

Driving Electromagnetic Relays

DISCLAIMER

This information is provided as a guide only; no responsibility is taken for any omissions, errors, inaccuracies or any damages arising directly or indirectly from the use of this information.

Why use a Relay?

There are situations where you may want to control switching a high power load or an AC load from a low voltage or low current circuit (for example from a microcontroller or a PC parallel port); in this situation it is hard to find a simpler or cheaper solution than a relay. But what if your output can’t provide enough power to drive the relay? This short article aims to give you enough information to design your own simple transistor drive relay circuit to suit almost any situation. You should however be aware that they are a mechanical device and, as such, have a limit to how fast they can switch off and on. You aren’t going to get 22,000 switch cycles per second out of a normal electromagnetic relay.

Relay Basics

An electromagnetic relay consists of a small electromagnet which pulls the contacts of a switch open or closed. The switch contacts are normally electrically isolated from the electromagnet giving the controlling circuit a reasonable amount of protection from the switched circuit.

When selecting a relay there are three basic considerations:

  1. The switch contact load rating – how much current the relay can safely switch (don’t try to control a 240v, 2400watt fan heater with a relay rated for 1 amp, unless you really like sparks and flames)
  2. The relay coil voltage – this is the minimum voltage required to overcome the resistance of the coil to pull in the switch contacts
  3. The relay coil resistance – this can be used to calculate the current required to pull in and hold the switch contacts

Hopefully, these three things are labeled on the relay, but at the very least the coil voltage and maximum switch load current should be visible. If you only know the coil voltage, you can always measure the coil resistance with an ohmmeter (or multimeter) and use the coil voltage with the measured resistance to determine the coil current.

Selecting a Transistor

The first thing to determine when selecting a transistor is whether you want the relay coil turned on when your control input is high (positive voltage) or low (negative or zero voltage).

If you want the relay coil turned on when your control input is high (also known as positive logic) it is easiest to use a NPN transistor. If you want the relay coil turned on when your control input is low (also known as negative logic) it is easiest to use a PNP transistor. See Figure 1 below.

Figure 1 - Positive and Negative logic circuits

Having decided which transistor type to use (NPN or PNP) the next thing to do is to determine the collector-emitter current that will be required, which just happens to be the coil current of our relay. If your relay has this detail written on it, use the value they give you, otherwise you can calculate it with Ohm’s law:

Coil Current = Coil Voltage / Coil Resistance

Don’t forget, Ohm’s law works in Volts, Ohms and Amps. Not millivolts, milliamps or kiloohms. It is a common mistake to forget to convert to or from these units and end up with a completely incorrect figure.

Our selected transistor must be able to “pass” at least this much current and preferably a bit more to allow for variation in coil resistance (and hence current) due to temperature or manufacture variations. This is known as the collector current and is usually noted in the transistors specifications as “Ic”.

Since we should only ever have our transistor in the “off” state or the “fully on” (saturated) state our transistor should actually never need to dissipate much power and so should never heat up. This is due to virtually no current passing in the off state (so power, which is current times voltage, is near zero) and the transistor having near-zero voltage across it in the saturated state (again, power is near zero). This means we can virtually ignore the power rating of our transistor as long as we ensure it is either off or saturated, which brings the next question; how do we ensure our transistor is saturated when on?

To ensure our transistor is saturated, we need to ensure that the current being supplied to the base of our transistor is greater than the collector current (coil current) divided by the transistor’s minimum DC current gain which is normally noted in the transistor’s specification as “hfe” or “min hfe”. This figure is used to calculate the value of R1 (Fig. 1) using ohm’s law and the highest voltage you are going to put into your control line.

For example:

We want to drive the following relay from a fictional positive logic CMOS output which has an output voltage of 4.7v when on and a maximum output current of 5mA (0.005A);

Relay coil Voltage: 12v
Relay coil Resistance: 400ohms
Relay coil Current = 0.03A or 30 Milliamps (= coil Voltage / coil Resistance)

We’ll use positive logic and so a NPN transistor will be used. Scrounging through a few datasheets, we find a suitable transistor;

bc548 –
Ic: 100mA - we only need 30mA, so this is plenty.
hfe min: 125

To ensure the transistor is saturated, we need to supply at least 0.03A / 125 = 0.00024A. It is generally a good idea to supply double that figure (0.00048A) to be on the safe side. Note that since our fictional CMOS output can provide up to 0.005A we can easily achieve this. If our output could not provide such a current, we would need to look for a transistor with a higher hfe.

Now we need to calculate the value of R1 using ohms law:

Given our maximum output voltage of 4.7volts and our required current of 0.00048A we get:

R1 = 4.7 / 0.00048 = 9791.66666 ohms

Or 9.791k which is close enough to the preferred value of 10k, especially since I’m going to use nice, cheap 20% tolerance resistors.

Figure 2 - Example CircuitFigure 2 shows the example circuit with the components we have selected substituted in. This might be a good time to introduce the protection diode and the pulldown resistor (R2).

The protection diode is there to protect the transistor from reverse voltage spikes from the relay coil when it transitions between on and off. The relay coil is, after all, an inductor. As the magnetic field collapses at the moment it is turned off, it induces a current in the coil which can result in a reverse-polarity spike that will not make the transistor happy. The diode is there to short out that spike (which is why it is installed “backwards” – we only want to short out that negative spike, not our relay driving current) and prevent it from reaching the transistor. Selection of the protection diode is not critical except that the reverse-breakdown voltage must be higher than the supply voltage for the relay. The breakdown voltage is the voltage at which the diode begins to conduct, even in the wrong direction, and the supply voltage for the relay is usually the same as the coil voltage. For 12v or lower, a 1n4001 or 1n4004 should be fine.

The pulldown resistor is required when your control output is an open collector output. Open collector outputs don’t set the output voltage to a specific level when the output is not on. Instead, they let the output level “float” as if it is disconnected. In this situation the base (control) of the transistor can pick up stray electrical noise which can be quite a problem (overheating transistors, mysteriously chattering of the relay and unexpected appearances of avocados!). The pulldown resistor’s job is to ensure that the base is pulled down to ground when no signal is present so that this doesn’t happen. The actual value of the resistor isn’t critical but it has to be high enough to ensure the transistor still saturates when required. As a rule of thumb, R2 should be about 10 times R1, so in our case R2 would be 100k. Note that if your control output is not open collector, R2 can be omitted completely.

In the case of the negative logic circuit you should note that the pullup resistor is connected to Vcc, NOT the relay supply voltage. Vcc should be about the same voltage as the maximum voltage of your control output and is often tied to the supply of your control circuit (e.g. if your output is from a CMOS chip, Vcc would be tied to the positive supply of that CMOS chip).

Well, I think that’s about it for now. Have fun, and don’t blow up your computer (or your house).

Google
 
Web www.industrialmightandlogic.com