turning on relay from 5v signal

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View


I asked how can I turn on a 12V relay from a ttl signal before and I got the
circuit below as a response. I tested it and it works fine but unfortunately
I tested it by supplying 12V into the 2.2k resistor. Now when I've connected
it to my little cpu it doesn't work. When I switch on the appropriate pin it
can only muster .67 of a volt. The pin has an internal pullup and does
switch from 0 to 5V without the transistor connected. Did I get the wrong
transisitor or something? It's a BC338 from jaycar. I dunno what these
figures mean but in the catalog it says "Diss @25C 500mW, Vcb 30V, Ic 800mA
Hfe 100, Hfe Bias 100mA"

Many thanks yet again
Michael



             o----o----- +12V
             |    |
            ---  ---
             ^   | |
    1N4001  / \  | | Relay coil
            ---  ---
             |    |
             -----o
                  |
                 /
IN             |/
----\/\/\/-----|
    2K2        |\   Misc. NPN
                -V|
                  |
                  |
                --o-- GND



Re: turning on relay from 5v signal



Quoted text here. Click to load it
Change you cpu output to push-pull instead of open collector(drain)
and it should work ok

Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
We've slightly trimmed the long signature. Click to see the full one.
Re: turning on relay from 5v signal


Quoted text here. Click to load it

Do you mean pull it up to 5v with an external resistor?

Michael



Re: turning on relay from 5v signal



Quoted text here. Click to load it
You could do - use another 2k2 or 1k0 to +5v from the output of the
cpu.  

But you should be able to programme the cpu (normally) for push-pull
output.  ie it will either sink (low output) or supply (high output)
current.  If you cannot change the programming of the cpu then the
additionla resistor is probably the easiest (only) option for you.

Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
We've slightly trimmed the long signature. Click to see the full one.
Re: turning on relay from 5v signal


Quoted text here. Click to load it

Thanks for the reply. As far as I can tell the pins cannot be changed. It's
an 8051 and some pins are either open drain or have pull ups. All you can do
is set the pins to either a 1 or a 0 i think. What you suggested did work,
using a 2k resistor (because I didn't have a 1k here). I was under the
impression that the transistor would use an extrememly low current but I
guess that's not the case? Even with a 2k pullup + the internal pullup it
still only managed 3volts. I have one problem now that all the relays switch
on during the reset stage at startup, is there any way to avoid that?

Cheers,
Michael



Re: turning on relay from 5v signal



Quoted text here. Click to load it
Hi Michael

The 3v (measured at the micro pin) is OK.  Basically you have approx
0.7v on the base of the transistor when it is turned on.  That leaves
4.3 to be split accross the two 2k2 resistors. So the output pin of
the micro should be about 3v.

There will be no way (easily) to stop the relays switching on as the
micro will set it's outputs to hi/tri-state/open when it resets.  

You can try two things to overcome this in your case.  
1) a capacitor from the base of the transistor down to ground.  This
will slightly delay the turn on and turn off of the relay.  Experiment
with values to overcome the pwoer up turn on.
2) put another transistor inverter between the micro output and the
relay driver you have now and invert your output signal in the micro.
That way you need to output a low from the micro to turn the relay on.

HTH
Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
We've slightly trimmed the long signature. Click to see the full one.
Re: turning on relay from 5v signal


Quoted text here. Click to load it

That sounds good, I'll give it a try. Although, is there some sort of chip
that would do all this? I've got 3 relays.

Michael



Re: turning on relay from 5v signal



Quoted text here. Click to load it
You could use a ULN2003 or ULN2803 relay driver chip.  However you
still need to be able to drive them with input voltage/current so you
would still need inverters before them.  

You could even try using a 74LS04 hex inverter chip for the inverter
and then a ULN chip as the driver.

Lots of different ways to go!

Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
We've slightly trimmed the long signature. Click to see the full one.
Re: turning on relay from 5v signal



Quoted text here. Click to load it
As a follow up - you could probably even use a ULN2003 as both the
inverter and the driver.  It has 7 (ULN2803 has 8) drivers in the one
package.  Wire the output of one driver into the input of the second
driver and put the relay between the output of the second driver and
+12v.  

Both inputs should then be pulled to +5 with say a 2k2 and the input
of the first driver connected to the output pin of the micro.

The ULN2003/2803 even has built in clamp diodes for your relays.

Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
We've slightly trimmed the long signature. Click to see the full one.
Re: turning on relay from 5v signal



Quoted text here. Click to load it

They turn on because the base of the transistor is being pulled high by the
pullup
resistor before the micro has a chance to set the pin outputs low. Use a PNP
transistor in place of the BC338. Connect the emitter of the PNP to the diode
anode-relay junction, and the collector to ground. The base can be connected to
the
pullup resistor. This method ensures that when the micro is in reset, the relays
are off, because the pullup turns the transistor off. To turn the transistor on,
set the output pin of the micro to low, to turn it off, set the output pin high.


Re: turning on relay from 5v signal


Quoted text here. Click to load it

I tried this but for some reason there is 3v drop across the transistor so
the relay only gets 9v. It switches but it sounds like it is only just
switching. I'm not sure it will work anyway because the uC will set it's
outputs to 0 after reset I think

Michael
Quoted text here. Click to load it



Re: turning on relay from 5v signal



Quoted text here. Click to load it
Did you try another inverter stage before the relay driver as I
suggested?

Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
We've slightly trimmed the long signature. Click to see the full one.
Re: turning on relay from 5v signal


Quoted text here. Click to load it

Initially I tried the pnp transisitor because it appeared to be much easier.
I just tried using the 2 npns and it worked perfectly, powering it all up I
don't get a peep out of the relay. I think I'll have a look at your other
suggestion as it looks like a neater solution. As these will be put together
by hand it's much easier to solder in a 16 pin chip instead of 6
transistors, 9 resistors and 3 diodes. Jaycar sells the ULN2003 so I'll try
to pick one up tomorrow. I was a bit confused about the datasheet though, do
I just connect the port pin to the input of the uln2003? The datasheet shows
some fairly complicated circuits on the input which would defeat the purpose
of using the chip. (page 11 of
http://rocky.digikey.com/WebLib/Texas%20Instruments/Web%20data/ULN2001A-4A,ULQ2003A-4A.pdf).

Thanks for all your help,
Michael



Re: turning on relay from 5v signal



Quoted text here. Click to load it
The complicated circuit on the input is acutally part of a TTL gate
output circuit!  It's shown for reference only.

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.

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.

HTH

Have fun!

Alan

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
We've slightly trimmed the long signature. Click to see the full one.
Re: turning on relay from 5v signal


Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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.

Quoted text here. Click to load it

It certainly has, many thanks.

Michael



Re: turning on relay from 5v signal



Quoted text here. Click to load it
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

--
++++++++++++++++++++++++++++++++++++++++++
Jenal Communications
We've slightly trimmed the long signature. Click to see the full one.
Re: turning on relay from 5v signal



Quoted text here. Click to load it

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.





  








Re: turning on relay from 5v signal


Quoted text here. Click to load it

I'll have to do this tomorrow night. I've got a dmm that will measure
current but only 1.

Quoted text here. Click to load it

The CPU will act as the pulldown won't it?

Michael



Re: turning on relay from 5v signal



Quoted text here. Click to load it

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
We've slightly trimmed the long signature. Click to see the full one.
Re: turning on relay from 5v signal


Quoted text here. Click to load it

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.

Quoted text here. Click to load it

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



Site Timeline