turning on relay from 5v signal

On Mon, 14 Nov 2005 14:46:04 +0800, Alan <me@somewhere.com.au.invalid>
wrote:

On Mon, 14 Nov 2005 17:22:50 +1100, "Michael C" <me@nospam.com> wrote:

"Alan" <me@somewhere.com.au.invalid> wrote in message
news:un8gn1hs9gavds6puthafm3b72tuvv222e@4ax.com...
The complicated circuit on the input is acutally part of a TTL gate
output circuit! It's shown for reference only.

hmmm, I thought most of that circuit shown probably wasn't needed but didn't
know why. Usually datasheets are quite clear and easy for a hobbiest like
myself to understand.

Using a ULN2003 all you need to do is:
1) connect micro output to (say) pin 1 and pull up to +5v with say a
2k2 resistor
2) connect pin 16 to (say) pin 2 and pull up to +5v with say a 2k2
resistor.
3) connect pin 15 to one side of your relay
4) connect other side of relay to +12v (or whatever)
5) connect pin 8 to ground
6) connect pin 9 to relay power supply +12v (or whatever)

You have to use the pull up resistors because all the inputs are
basically open collector/drain.

I'll see if I can get away with the pullup that's inside the cpu so I'll
only need the one pullup, although I might just go with the transistors.

Using pin 9 of the ULN2003 connects the internal back EMF diodes as
per fig 19 of the datasheet and therefor you don't need external
protection diodes.

That makes sense, I was a bit confused as to whether this was the power for
the chip or not and whether that voltage was going to appear on the outputs
or not.

HTH

It certainly has, many thanks.

Michael

If you use transistors you only need two resistors and two transistor
(plus a diode for the relay).

1) connect o/p of micro to base of transistor A and pull up to +5 with
say 2k2
2) connect collector of transistor A to base of transistor B and pull
up to +5 (or +12) with say a 2k2
3) connect collector or transistor B to one side of relay
4) connect other side of relay to +12
5) don't forget to connect both emitters to ground and put diode
across the relay (the right way round!)

Alan
After reading this thread I am beggining to think that neither
understand the problem.

First you need to know how how much current the relay draws. Take note
that there will be a surge current as the realy energises.

Second, you need to understand that your transistor has a limited
current gain.

The resistor on the base of your transistor should limit the amount of
current being drawn from the CPU. Try doing a test using the original
circuit. Add a 10k pulldown resistor to the base of the transistor to
ensure that it stays off (you should always do this anyway). Then use
a multimeter to measure the current between the 2k2 resistor and 5V.

How much current? Does the relay turn on?

IF you can get hold of 2 meters, measure the current throught the
relay coil too.

If the relay does not turn on, then lower the value of the 2k2
resistor. My initial guess is that 2k2 is probably an overkill and
that several hundred ohms is going to be closer to the ball park, but
in saying that, i do not know the specs of your CPU.


Most modern CPU's can source quite a bit of current. Read the
datasheet on the micro to find out how much current it can source
through the pin. If it cant supply enought current, you can use a
darlington transistor, or 2 transistors in a darlington pair. This
will provide more gain. More gain means a smaller base current can
drive a larger source current.
 
"The Real Andy" <will_get_back_to_you_on_This@> wrote in message
news:v7rgn1po6s65c11na3cag6he4nn64pdk08@4ax.com...
After reading this thread I am beggining to think that neither
understand the problem.

First you need to know how how much current the relay draws. Take note
that there will be a surge current as the realy energises.
I'll have to do this tomorrow night. I've got a dmm that will measure
current but only 1.

Second, you need to understand that your transistor has a limited
current gain.

The resistor on the base of your transistor should limit the amount of
current being drawn from the CPU. Try doing a test using the original
circuit. Add a 10k pulldown resistor to the base of the transistor to
ensure that it stays off (you should always do this anyway). Then use
a multimeter to measure the current between the 2k2 resistor and 5V.
The CPU will act as the pulldown won't it?

Michael
 
On Mon, 14 Nov 2005 23:20:09 +1100, "Michael C" <nospam@nospam.com>
wrote:

The resistor on the base of your transistor should limit the amount of
current being drawn from the CPU. Try doing a test using the original
circuit. Add a 10k pulldown resistor to the base of the transistor to
ensure that it stays off (you should always do this anyway). Then use
a multimeter to measure the current between the 2k2 resistor and 5V.
Michael has already stated that this ouput pin is open collector/drain
and not push-pull so it is incapable of supplying any current to drive
a transistor.

Michael - just go with the two npn transistors as we already
discussed.

Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
Manufacturers and Suppliers of HF Selcall
P O Box 1108, Morley, Western Australia
Tel: +61 8 9370 5533 Fax +61 8 9467 6146
Web Site: http://www.jenal.com
Contact: http://www.jenal.com/?p=1
++++++++++++++++++++++++++++++++++++++++++
 
"Alan" <me@somewhere.com.au.invalid> wrote in message
news:eo9jn1hi3667cc167i1odns627e1iefb8c@4ax.com...
Michael has already stated that this ouput pin is open collector/drain
and not push-pull so it is incapable of supplying any current to drive
a transistor.
Now I understand what andy was trying to say and why it doesn't matter :)
Current draw from the CPU is not a problem, the pin is designed to be able
to be shorted to ground when it is high. Forcing it to 5V when it was low
would be a problem but not the other way round.

Michael - just go with the two npn transistors as we already
discussed.
Do you think the uln2003 is not the way to go? I'm starting to think this
myself but will give it a try tomorrow anyway.

Michael
 
On Wed, 16 Nov 2005 00:04:07 +1100, "Michael C" <nospam@nospam.com>
wrote:

"Alan" <me@somewhere.com.au.invalid> wrote in message
news:eo9jn1hi3667cc167i1odns627e1iefb8c@4ax.com...
Michael has already stated that this ouput pin is open collector/drain
and not push-pull so it is incapable of supplying any current to drive
a transistor.
If it is what I suspect, then it will not supply any current. A
typical open collector is usefull only for sinking current.

Now I understand what andy was trying to say and why it doesn't matter :)
Current draw from the CPU is not a problem, the pin is designed to be able
to be shorted to ground when it is high. Forcing it to 5V when it was low
would be a problem but not the other way round.

I am begining to think you have a lot more problems than you think,
and I beleive that the origonal circuit you have may not fit the
problem you describe.

I am assuming that the output of your micro is is an open collector
transistor that has its emitter internally tied to ground? If so, can
you read the datasheet and tell us how much current the output pin can
sink? Can you also tell us how much current the relay draws?




Michael - just go with the two npn transistors as we already
discussed.
If you have an open collector output that has the emitter internally
grounded then you are better of using a PNP transistor.

Do you think the uln2003 is not the way to go? I'm starting to think this
myself but will give it a try tomorrow anyway.
I doubt that you will need a uln2003, unless you are driving
solenoids.
 
On Wed, 16 Nov 2005 00:04:07 +1100, "Michael C" <nospam@nospam.com>
wrote:

"Alan" <me@somewhere.com.au.invalid> wrote in message
news:eo9jn1hi3667cc167i1odns627e1iefb8c@4ax.com...
Michael has already stated that this ouput pin is open collector/drain
and not push-pull so it is incapable of supplying any current to drive
a transistor.

Now I understand what andy was trying to say and why it doesn't matter :)
Current draw from the CPU is not a problem, the pin is designed to be able
to be shorted to ground when it is high. Forcing it to 5V when it was low
would be a problem but not the other way round.

Michael - just go with the two npn transistors as we already
discussed.

Do you think the uln2003 is not the way to go? I'm starting to think this
myself but will give it a try tomorrow anyway.

Michael

This is getting far too complicated for such a simple problem.

You can use either the two transistor (and two resistor) per relay
method or try the ULN2003 (plus two resistors per relay driven).
Either solution will work, just depends on how much space you
have/what takes your fancy/etc.

Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
Manufacturers and Suppliers of HF Selcall
P O Box 1108, Morley, Western Australia
Tel: +61 8 9370 5533 Fax +61 8 9467 6146
Web Site: http://www.jenal.com
Contact: http://www.jenal.com/?p=1
++++++++++++++++++++++++++++++++++++++++++
 
"The Real Andy" <will_get_back_to_you_on_This@> wrote in message
news:v26ln115td808ibhrlg7teql62dnan6gi7@4ax.com...
If it is what I suspect, then it will not supply any current. A
typical open collector is usefull only for sinking current.
It has an internal pullup, although I could just as easily use a pin that
doesn't have the pullup.

I am assuming that the output of your micro is is an open collector
transistor that has its emitter internally tied to ground? If so, can
you read the datasheet and tell us how much current the output pin can
sink? Can you also tell us how much current the relay draws?
It looks like the CPU pins can sink 3.2mA. I measured the relay at 120mA.

If you have an open collector output that has the emitter internally
grounded then you are better of using a PNP transistor.
I tried that and it worked but there was a voltage drop of approx 3V and the
relay didn't give such a positive click at 9V.

Michael
 
"Alan" <me@somewhere.com.au.invalid> wrote in message
news:t9aln19457e8drdlnhrd29e6d4cmpvb342@4ax.com...
You can use either the two transistor (and two resistor) per relay
method or try the ULN2003 (plus two resistors per relay driven).
Either solution will work, just depends on how much space you
have/what takes your fancy/etc.
I think I've dropped the idea of uln2003 because the cost will be higher and
it still needs 6 resistors anyway. I gave it a try and it has about a 0.8v
drop where the transistors had a 0.2v drop. Unless the real andy can find
anything wrong I'll go with the transistors. Thanks for all your help, it is
much appreciated :)

Michael
 
On 2005-11-14, Michael C <nospam@nospam.com> wrote:
"Jasen Betts" <jasen@clunker.homenet> wrote in message
news:slrndnd755.7t6.jasen@clunker.homenet...
the above circuit is for where the microcontroller
can actually drive the pin positive sourcing atleast 2.5ma. if you've
only got the internal pullup it's unlikely to work.

I used an external pullup as Alan suggested and it worked quite well.
Basically I did pretty much what you suggested in your diagram except
connected the pullup to 5v instead of 12.

what's the processor you're using? I used a very similar circuit with an
Atmel AVR 2313 (except I used 1K resistors), it worked fine.

It's an 8051, specifically the phillips p89c668hba but I'll probably use the
atmel AT89C2051 when I get a board made for it.
I'm sure the atmel 89C series is different to the atmel 90S series
but did I hear that you have it working using two transistors?

with the AVR you need to put the pin in output mode (by setting the
apropriate data-direction register bit) AIUI other microcontrollers
behave similarly. The pull-up is intended for when you use the pin
as an input.

I've only got 2 options, I can set the pin at either 0 or 1 and it can be
used as an input or output. Some pins have internal pullups and some don't
but the one I'm using does. How a pin could only have 2 states and be used
for both input and output had me confused literally for weeks when I first
started using the 8051 a few years ago. :)
:) as i understand it a similar trick is done with PC parallel ports to use
the data pins as inputs.

Bye.
Jasen
 
On 2005-11-14, The Real Andy <will_get_back_to_you_on_This@> wrote:
After reading this thread I am beggining to think that neither
understand the problem.

First you need to know how how much current the relay draws. Take note
that there will be a surge current as the realy energises.
what causes that? I'd have expected the opposite.

Second, you need to understand that your transistor has a limited
current gain.


Most modern CPU's can source quite a bit of current. Read the
datasheet on the micro to find out how much current it can source
through the pin. If it cant supply enought current, you can use a
darlington transistor, or 2 transistors in a darlington pair. This
will provide more gain. More gain means a smaller base current can
drive a larger source current.
He measured ~0.7V on the ouput driving that 2k2 and the transistoor base
in serries.

it seems that his outputs are essentially open collector.







--

Bye.
Jasen
 
On Wed, 16 Nov 2005 16:22:00 +1100, "Michael C" <nospam@nospam.com>
wrote:

"Alan" <me@somewhere.com.au.invalid> wrote in message
news:t9aln19457e8drdlnhrd29e6d4cmpvb342@4ax.com...
You can use either the two transistor (and two resistor) per relay
method or try the ULN2003 (plus two resistors per relay driven).
Either solution will work, just depends on how much space you
have/what takes your fancy/etc.

I think I've dropped the idea of uln2003 because the cost will be higher and
it still needs 6 resistors anyway. I gave it a try and it has about a 0.8v
drop where the transistors had a 0.2v drop. Unless the real andy can find
anything wrong I'll go with the transistors. Thanks for all your help, it is
much appreciated :)

Michael

I se transistors or ULN2003/2803 depending on the number of circuits
(relays,etc) I need to drive.

You have the additional unfortunate problem of not being able to
source drive current out of your micro. No big deal - just needs a
few more components (another transistor and resistor) to get what you
want.

The pnp idea won't work in your case because the base of the
transistor (ie the micro output) can only go between 0v and (probably)
one diode volt drop above the micro power supply (I guess +5v) that is
assuming the micro has built-in I/O protection diodes.

I'd say stick with the two transistors and two resistors. It's easy,
cheap and doesn't really take up much room plus it works!

Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
Manufacturers and Suppliers of HF Selcall
P O Box 1108, Morley, Western Australia
Tel: +61 8 9370 5533 Fax +61 8 9467 6146
Web Site: http://www.jenal.com
Contact: http://www.jenal.com/?p=1
++++++++++++++++++++++++++++++++++++++++++
 
On Wed, 16 Nov 2005 15:45:13 +1100, "Michael C" <nospam@nospam.com>
wrote:

"The Real Andy" <will_get_back_to_you_on_This@> wrote in message
news:v26ln115td808ibhrlg7teql62dnan6gi7@4ax.com...
If it is what I suspect, then it will not supply any current. A
typical open collector is usefull only for sinking current.

It has an internal pullup, although I could just as easily use a pin that
doesn't have the pullup.

I am assuming that the output of your micro is is an open collector
transistor that has its emitter internally tied to ground? If so, can
you read the datasheet and tell us how much current the output pin can
sink? Can you also tell us how much current the relay draws?

It looks like the CPU pins can sink 3.2mA. I measured the relay at 120mA.
plenty of current :)


If you have an open collector output that has the emitter internally
grounded then you are better of using a PNP transistor.

I tried that and it worked but there was a voltage drop of approx 3V and the
relay didn't give such a positive click at 9V.
Lower the current limiting resistor at the base of the transistor.
 
On Wed, 16 Nov 2005 14:17:25 +0800, Alan <me@somewhere.com.au.invalid>
wrote:

On Wed, 16 Nov 2005 16:22:00 +1100, "Michael C" <nospam@nospam.com
wrote:

"Alan" <me@somewhere.com.au.invalid> wrote in message
news:t9aln19457e8drdlnhrd29e6d4cmpvb342@4ax.com...
You can use either the two transistor (and two resistor) per relay
method or try the ULN2003 (plus two resistors per relay driven).
Either solution will work, just depends on how much space you
have/what takes your fancy/etc.

I think I've dropped the idea of uln2003 because the cost will be higher and
it still needs 6 resistors anyway. I gave it a try and it has about a 0.8v
drop where the transistors had a 0.2v drop. Unless the real andy can find
anything wrong I'll go with the transistors. Thanks for all your help, it is
much appreciated :)

Michael

I se transistors or ULN2003/2803 depending on the number of circuits
(relays,etc) I need to drive.

You have the additional unfortunate problem of not being able to
source drive current out of your micro. No big deal - just needs a
few more components (another transistor and resistor) to get what you
want.
You dont know what you are talking about. The micro will be barely
able to source any current. IT is designed to sink current.

The pnp idea won't work in your case because the base of the
transistor (ie the micro output) can only go between 0v and (probably)
one diode volt drop above the micro power supply (I guess +5v) that is
assuming the micro has built-in I/O protection diodes.
You dont know what you are talking about. The output does not go
anywhere. When the output is diven into its active state, the uC's
output transistor will conduct. Most micro's which supply an open
collector/drain have the emitter/source internally tied to ground.
This means that when the output is active (active low) then the
saturated output transister is essentially at ground potential plus
the small collector-emmiter voltage.

So if you decide to use a PNP then all you must do is put the relay
between the collector and ground, and connect the emitter to 12Volts.
The circuit is essentially reversed.


I'd say stick with the two transistors and two resistors. It's easy,
cheap and doesn't really take up much room plus it works!
2 transistors will only be needed if there is insufficient gain with
the transistor being used. You cannot design an good circuit without
some basic understanding of what is going on. I doubt very much that
modern transistor will have such little gain that a darlington is
required. This would only be required if the OP wants to switch a
large current.


I just went searching for a good web page and found this.

http://www1.jaycar.com.au/images_uploaded/relaydrv.pdf

Use the PNP circuit, this is what fits you application. This is a very
brief description and is not entirely correct, but i should help the
OP to understand.


To drive the relay on, set the port pin to its active state, in your
case I am assuming that this will be '0'. Use the internal pullup,
whose sole purpose in life is to keep the output in a known state when
your output is not in its active state.
 
On Wed, 16 Nov 2005 05:51:23 -0000, Jasen Betts
<jasen@clunker.homenet> wrote:

On 2005-11-14, The Real Andy <will_get_back_to_you_on_This@> wrote:

After reading this thread I am beggining to think that neither
understand the problem.

First you need to know how how much current the relay draws. Take note
that there will be a surge current as the realy energises.

what causes that? I'd have expected the opposite.
Inrush current is common with inductive loads. As the relays coil is
energises, it draws a large amount of current until it becomes
saturated with magnetic flux. When you pull the power, the magnetic
flux collapses and induces a current in the coil, called back EMF. The
reason the OP has a diode in the circuit is to suppress this back EMF.


Second, you need to understand that your transistor has a limited
current gain.


Most modern CPU's can source quite a bit of current. Read the
datasheet on the micro to find out how much current it can source
through the pin. If it cant supply enought current, you can use a
darlington transistor, or 2 transistors in a darlington pair. This
will provide more gain. More gain means a smaller base current can
drive a larger source current.


He measured ~0.7V on the ouput driving that 2k2 and the transistoor base
in serries.

it seems that his outputs are essentially open collector.
More to the point, it seems that the output transistor is internally
tied to ground, so the OP should really use a PNP transistor to drive
the circuit. An NPN will be fine if it has enough gain, as all the
current is being sourced from the internal pullup resistor. The
internal pullups are normally quite a high value, so only a very small
amount of current can be sourced through them.

If you were to use a large external pullup to souce more current, you
would have to be carefull that when you turn on the uC's transistor,
that it does not sink to much current through the external pullup.

Understanding that there is not enough current via the internal
resistor, the OP is experiencing a problem where the transistor is not
being driven into saturation. More gain will fix this, however it is
better to implement a proper design in the first place rather than
making a flawed design work.
 
On Wed, 16 Nov 2005 19:50:56 +1000, The Real Andy
<will_get_back_to_you_on_This@> wrote:

On Wed, 16 Nov 2005 15:45:13 +1100, "Michael C" <nospam@nospam.com
wrote:

"The Real Andy" <will_get_back_to_you_on_This@> wrote in message
news:v26ln115td808ibhrlg7teql62dnan6gi7@4ax.com...
If it is what I suspect, then it will not supply any current. A
typical open collector is usefull only for sinking current.

It has an internal pullup, although I could just as easily use a pin that
doesn't have the pullup.

I am assuming that the output of your micro is is an open collector
transistor that has its emitter internally tied to ground? If so, can
you read the datasheet and tell us how much current the output pin can
sink? Can you also tell us how much current the relay draws?

It looks like the CPU pins can sink 3.2mA. I measured the relay at 120mA.


plenty of current :)


If you have an open collector output that has the emitter internally
grounded then you are better of using a PNP transistor.

I tried that and it worked but there was a voltage drop of approx 3V and the
relay didn't give such a positive click at 9V.

Lower the current limiting resistor at the base of the transistor.
Actually, dont do that just yet. Start using a PNP transistor first.
Se my other post.
 
On Wed, 16 Nov 2005 20:15:07 +0800, Alan <me@somewhere.com.au.invalid>
wrote:

On Wed, 16 Nov 2005 20:33:42 +1000, The Real Andy
will_get_back_to_you_on_This@> wrote:

On Wed, 16 Nov 2005 14:17:25 +0800, Alan <me@somewhere.com.au.invalid
wrote:

On Wed, 16 Nov 2005 16:22:00 +1100, "Michael C" <nospam@nospam.com
wrote:

"Alan" <me@somewhere.com.au.invalid> wrote in message
news:t9aln19457e8drdlnhrd29e6d4cmpvb342@4ax.com...
You can use either the two transistor (and two resistor) per relay
method or try the ULN2003 (plus two resistors per relay driven).
Either solution will work, just depends on how much space you
have/what takes your fancy/etc.

I think I've dropped the idea of uln2003 because the cost will be higher and
it still needs 6 resistors anyway. I gave it a try and it has about a 0.8v
drop where the transistors had a 0.2v drop. Unless the real andy can find
anything wrong I'll go with the transistors. Thanks for all your help, it is
much appreciated :)

Michael

I se transistors or ULN2003/2803 depending on the number of circuits
(relays,etc) I need to drive.

You have the additional unfortunate problem of not being able to
source drive current out of your micro. No big deal - just needs a
few more components (another transistor and resistor) to get what you
want.

You dont know what you are talking about. The micro will be barely
able to source any current. IT is designed to sink current.

Very kind of you to point out that I don't know what I'm talking
about, I just didn't realise that - I guess I should bow to your
superiority complex.

Read what I said - quote - "You have the additional unfortunate
problem of NOT being able to source drive current out of your micro".


The pnp idea won't work in your case because the base of the
transistor (ie the micro output) can only go between 0v and (probably)
one diode volt drop above the micro power supply (I guess +5v) that is
assuming the micro has built-in I/O protection diodes.

You dont know what you are talking about. The output does not go
anywhere. When the output is diven into its active state, the uC's
output transistor will conduct. Most micro's which supply an open
collector/drain have the emitter/source internally tied to ground.
This means that when the output is active (active low) then the
saturated output transister is essentially at ground potential plus
the small collector-emmiter voltage.

So if you decide to use a PNP then all you must do is put the relay
between the collector and ground, and connect the emitter to 12Volts.
The circuit is essentially reversed.

You cannot do this because the base will not go up to +12v when the
micro output is "off" IF there are protection diodes on the I/O pin.
And this is a problem how?

I'd say stick with the two transistors and two resistors. It's easy,
cheap and doesn't really take up much room plus it works!

2 transistors will only be needed if there is insufficient gain with
the transistor being used. You cannot design an good circuit without
some basic understanding of what is going on. I doubt very much that
modern transistor will have such little gain that a darlington is
required. This would only be required if the OP wants to switch a
large current.


The two transistors are not to give enough gain, they are to give a
double inversion and drive a relay - nowhere did I mention using two
transistors as a darlington - look at the description of how they
should be wired - coll 1 to base 2 - not emitter 1 to base 2. The
only close mention of darlingtons were the ULN2003/2803 which where
discussed - however the OP would still need to use two sections of
these to reach his objective!
Double inversion ey?

I just went searching for a good web page and found this.

http://www1.jaycar.com.au/images_uploaded/relaydrv.pdf

Use the PNP circuit, this is what fits you application. This is a very
brief description and is not entirely correct, but i should help the
OP to understand.


To drive the relay on, set the port pin to its active state, in your
case I am assuming that this will be '0'. Use the internal pullup,
whose sole purpose in life is to keep the output in a known state when
your output is not in its active state.

You might actually read that pdf yourself and learn something. It
states (4th para right hand side) that the circuit needs +12 to switch
the relay off and 0v to switch it on. In actual fact it will need
only need a slightly lower than 12v signal to switch in on but we
won't discuss that here it might get too confusing for some.
An there I am thinking that by controlling the base current through
bipolar transistors would control the collector current. Oh how silly
of me. I guess all my physics books are wrong, not to mention all
those application notes that I have for my old CMOS and TTL logic.

I think before you anything else you should reread the whole of this
thread to see what the OPs problems were/are and what has been
suggested.
I have read the posts.


Meanwhile I'll just go back to designing things I know nothing
about...
Alan
Good idea.
 

Welcome to EDABoard.com

Sponsor

Back
Top