Single pin relay control

EDIT: The below schematic and circuit description are slightly incorrect – the PNP and NPN transistors should be reversed.

I am cheap when it comes to micro-controller pins. I don’t like using them if i don’t have to. I also don’t like throwing current around unnecessarily.

I was working on a project which i wanted to control a bunch of relays with my micro-controller, but didn’t want to dedicate 2 pins or an h-bridge to each relay driver. My relays were fairly small, and i came up with the following way to control them with a single (tri-state) pin, and some external components.

If you have a strong-ish pin driver or a low-current relay coil, you don’t even need the totem pole arrangement.

Background:

Relays work by putting a certain amount of current through an inductor, setting up a magnetic field that pushes a switch. A normal relay requires that current to be always on. Once you stop feeding it, it goes back to ‘off’ (or on, whatever the default is).  A Latching relay doesn’t have the spring or whatever to force the switch back once current is released. It acts more like a light-switch.

So, for a latching relay you need to supply a certain amount of current to get it to switch, then another amount in reverse to get it to switch back.

Relays usually specify the current needed to switch them, and the internal resistance of the coils.

The idea:

Use a latching relay with a capacitor behind it, sized such that it can store enough current to switch the relay back:

control-pin -> relay coil -> capacitor -> GND

you send 5v or whatever though the coil and the capacitor will start to charge up. That current is enough to switch the relay, so it turns on. As you leave the pin high, the cap will charge up and the current will drop off to zero. Once you are ready to unswitch the relay, connect the pin to ground, and the cap will discharge across the coil and switch the relay back.

If you have a big relay, small pin driver, etc you can add a NPN and PNP transistor pair in a ‘totem pole’ configuration to switch a larger amount of current.

Bingo! one pin, no excess current loss, and 1 (or 3) extra components.

Here’s a picture:

The switch at left simulates the microcontroller pin. The resistor and inductor simulate the coil of the relay.

Want to try it? here’s the falstad simulator code (See this link for how)

$ 1 5.0E-6 31.41906602856942 54 5.0 50
c 304 208 304 256 0 9.999999999999999E-5 4.4916891133897625
g 304 256 304 288 0
w 240 112 304 112 0
t 208 96 240 96 0 1 0.0 0.5013938559564375 100.0
S 176 112 128 112 0 1 false 0
t 176 128 240 128 0 -1 5.0 0.5013938559564375 100.0
R 128 96 96 96 0 0 40.0 5.0 0.0 0.0 0.5
w 176 128 176 112 0
w 176 112 176 96 0
w 176 96 208 96 0
R 240 80 240 48 0 0 40.0 5.0 0.0 0.0 0.5
g 240 144 240 176 0
r 304 112 304 160 0 135.0
l 304 160 304 208 0 0.01 5.129834965258037E-5
g 112 128 112 144 0
w 112 128 128 128 0
x 61 75 155 79 0 18 control pin
x 251 77 360 81 0 18 “totem pole”
x 347 190 424 194 0 18 relay coil
o 12 64 0 291 2.5 0.025 0 -1

Depending on the control voltage, you may need to add more resistance inline with the coil.

Advertisements

One Response to “Single pin relay control”

  1. Hi there, You have done an excellent job. I’ll definitely digg it and personally recommend to my friends. I’m sure they’ll be benefited from this website.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: