Arduino Forum

Using Arduino => General Electronics => Topic started by: aj88keys on Jun 26, 2013, 03:59 am

Title: Controlling a 5v relay, only getting 2.4v?
Post by: aj88keys on Jun 26, 2013, 03:59 am
Im trying to switch on a 5v relay (Huigang HRS2H-S-DC5V) using a digital pin on my Uno, and for some reason when I set the control pin high, I only get about 2.4 volts across the relay, the rest is getting burnt across the collector-emitter of a 2n3904 transistor. I have everything wired up according to http://playground.arduino.cc/uploads/Learning/relays.pdf, the only difference is that I'm using a 3904 instead of a 2222 and Relay Power+ is connected to the arduino 5v supply pin. I have tried playing around with different base resistors to no avail. What could be going on?
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: 1ChicagoDave on Jun 26, 2013, 04:40 am
Check your DATASHEETS to be sure...
Small signal transistors like those vary how much voltage they allow through the collector-emitter based on how much current they get at their base. Since, I believe, Arduino's digital pins only put out something like 40mA of current, your 3904 may not be getting fully turned on. Therefore, it's letting less than full rail voltage pass through.

I would try setting up two 3904's together (like a Darlington pair) and see how much voltage that gives you....?

Good luck!
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: nickgammon on Jun 26, 2013, 05:23 am
40 mA absolute maximum rating. Aim for 20 mA.

Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: 1ChicagoDave on Jun 26, 2013, 05:56 am

40 mA absolute maximum rating. Aim for 20 mA.




Right. So the question is....will 20mA (up to 40mA) fully turn on a 3904 transistor?  And if not, what to do?
Again, I'm too lazy to check the Datasheet for ya, so find out how much current you need.

If Arduino can (safely) source ~20mA per pin, could one use more than one pin to equal required current? Say, if 60mA is needed, could one use three pins to source that to the transistor?

(I'm still a bit new to Arduino myself, so I'm sorta spit-balling here.)
Thanks!
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: aj88keys on Jun 26, 2013, 09:03 am
Alright so I got it going, hooking up two 3904's in a darlington config seems to do the trick, and with a 1k resistor on the base of the first transistor I (should) only be drawing 5 mA, right?


If Arduino can (safely) source ~20mA per pin, could one use more than one pin to equal required current? Say, if 60mA is needed, could one use three pins to source that to the transistor?


I would think that you probably wouldn't be able to do it directly. You might be able to connect a resistor between each pin and the base, but then not only are you using three pins for one transistor but I would also worry that you could accidentally connect two output pins together, and I'm not sure how much the micro would like that.
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: sonnyyu on Jun 26, 2013, 01:32 pm
Huigang HRS2H-S-DC5V;-



The current to drive relay : 5/120= 41.7 mA

A 2N3904 transistor's beta max value is 150 and min value is 100.  When figuring out DC current gain, the beta value is part of the formula.  In the sheet above, it is also known as as hFE.  (hFE = beta = gain for easier understanding)

The transistor drive current= 41.7/100= 0.417 mA.  Your circuit is fine. Replace an other 2N3904 or check connection might be the way to go.

Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: aj88keys on Jun 27, 2013, 11:36 pm
I had figured that maybe the transistor was to blame, so before wiring up the darlington I tried replacing the transistor but got the same result. I have also noticed that sometimes when the pin is low, the relay buzzes quietly, what would be causing that?
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: sonnyyu on Jun 28, 2013, 01:18 am
(http://s13.postimg.org/iqb73jyvb/relay.jpg)

don't forget diode, double check  transistor connection or change an other type one.
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: oric_dan on Jun 28, 2013, 03:25 pm
The problem is the 3904 was not driven into saturation. 5mA drive on the 3904 base
should have been adequate, if the relay current was 40 mA.  Possibly you had the
transistor wired backwards, so the current gain was low. Easy to do.
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: MarkT on Jun 28, 2013, 06:48 pm
Don't forget that the flyback diode is absolutely required - otherwise the relay coil inductance
can easily destroy the transistor, and possibly other parts of the circuit.

I'd suggest not using a darlington for low voltage switching like this - a darlington costs at least a volt,
sometimes 2V, so your 5V supply is only 3V at the relay winding.  Or use a 6V supply, darlington
and 5V relay...  Darlington's tend to run hot because of the wasted power too.

A single switching transistor, if saturated, only costs 0.05 to 0.2V lost, shouldn't get very warm.
Make sure it has plenty of current overhead (so for a 200mA load use at least a 500mA transistor,
otherwise its hard to get good saturation).
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: aj88keys on Jun 28, 2013, 06:54 pm
I wired it up with the exact same circuit sonnyyu posted, no luck. sometimes get a very quiet tick out of the relay, but it doesnt get enough to switch over. Tried replacing with 4 other 3904s, could it be the difference between the 3904's and the 2222's thats doing it? (What exactly is the difference, anyway? From what I have read, the 2222 is just able to handle higher current, is that true?) I do have the flyback diode (1N4004) in place, and according to my tests when connected directly to 5v, the coil draws about 41-43mA.
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: pwillard on Jun 28, 2013, 07:48 pm
Depending on the package metal or epoxy, the 2n2222a can handle between 500 and 800 mA through emitter-collector and the base is quite happy with 5mA to turn on fully.  You are not *burning* current in the transistor unless you wired it wrong.
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: RPCoyle on Jun 28, 2013, 08:03 pm
It's such a simple circuit. seems like something must be mis-wired. make sure you don't have the transistor hooked up backwards. In bread boarding, I've done that more than once. check the ohms on your resistor, it's easy to mistake orange for red. Not much else could be wrong.
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: aj88keys on Jun 28, 2013, 09:17 pm

Depending on the package metal or epoxy, the 2n2222a can handle between 500 and 800 mA through emitter-collector and the base is quite happy with 5mA to turn on fully.


If the only difference between the 3904 and 2222 is power handling, I should be just fine using a 3904 for driving a 42mA relay, no?


It's such a simple circuit.


That's what's got me so f%$@#&* confused, what am I doing wrong? I have tried replacing the transistor, connecting it both ways, replacing the relay, different resistor values, reversing the diode, replacing the diode, even changing the digital pin on the arduino, but yet I still end up losing half the voltage over the transistor. The only thing that works right now is the darlington, which I'd rather not use because it uses up 2 transistors. Here's how it's all wired with just the single transistor, maybe someone will see something that I've overlooked:
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: tocpcs on Jun 29, 2013, 02:05 am
What's going on at A1 ?
Can I suggest checking voltage across the left side  + / - to ensure you have 5V there?
You say you are losing 2.5V through the transistor, it's connecting to ground, so are you measuring from the E pin to ground? (after the 5V has passed through the relay coil)..?
I wonder if the current to initially pull the relay in is too great? And 42mA is the current to hold it in?
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: aj88keys on Jun 29, 2013, 02:25 am

What's going on at A1 ?


A1 is a 12 volt source going through a diode and a 750 mA polyfuse for some 12 volt electronics and a motor. Negative terminals are both connected to gnd, left side positive rail has +12.2V supplied by Vin, right positive rail has +4.85V supplied by arduino 5V out.


You say you are losing 2.5V through the transistor, it's connecting to ground, so are you measuring from the E pin to ground? (after the 5V has passed through the relay coil)..?


I am measuring from Collector to Emitter. I also measured across the relay coil and got about 2.3 - 2.4v


I wonder if the current to initially pull the relay in is too great? And 42mA is the current to hold it in?


I hadn't thought about the pull-in current, however I measured the coil's resistance to be 121 ohms, which still works out to  5V / 121 = 0.0413 or 41.3 mA. That is just math though, and stupid reality is never as easy. :0 Do relays normally draw more current while pulling in?
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: runaway_pancake on Jun 29, 2013, 03:05 am
Slightly more, not major.

Attached drawing.  Is yours set up accordingly?
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: aj88keys on Jun 29, 2013, 03:20 am
560 ohm instead of 470, but otherwise identical
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: runaway_pancake on Jun 29, 2013, 03:23 am
Have you measured the coil resistance (out of circuit) with an ohmmeter?
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: aj88keys on Jun 29, 2013, 03:27 am
121 ohms. Just did some poking and prodding with the voltmeter and discovered that I'm only getting 0.7 volts out of my digital pin when its connected, and only 4.3 volts unconnected. 5 volt rail is still solid at 4.95V
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: runaway_pancake on Jun 29, 2013, 03:29 am
4.3/0.7 = OK

The resistor, 560?, is green-blue-brown, verified with ohmmeter?
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: aj88keys on Jun 29, 2013, 03:37 am
Yep. And it had nothing to do with the problem whatsoever. Turns out I forgot to set pinMode(dirPin, OUTPUT).   :P

Oops.

All is well now. I guess the lesson is, don't give a pin a name that sounds like derpin'  ;)
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: oric_dan on Jun 29, 2013, 03:57 am
The way to do something like this is in 3 steps:

1. check relay directly with 5V.
2. check NPN driver ckt exclusive of Arduino - connect base R to 5V.
3. hook to Arduino I/O pin.

Then you know exactly where the problem comes in.
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: runaway_pancake on Jun 29, 2013, 04:00 am

Yep. And it had nothing to do with the problem whatsoever. Turns out I forgot to set pinMode(dirPin, OUTPUT).   :P

Oops.

All is well now. I guess the lesson is, don't give a pin a name that sounds like derpin'  ;)


Carumba.
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: aj88keys on Jun 29, 2013, 04:02 am
You know, the stupid thing is, I was thinking of trying to connect the transistor base directly to 5v to see if the Arduino was the problem, I really don't know why I didn't do that. I guess that's why my profile says "Newbie"  :smiley-mr-green:
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: larryd on Jun 29, 2013, 05:10 am
Quote
I was thinking of trying to connect the transistor base directly to 5v

I was thinking of trying to connect the transistor base resistor directly to 5v ;)
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: 1ChicagoDave on Jun 29, 2013, 06:27 am
What's the 1K resistor there for? Can someone more experienced than I explain why it would be needed?
I could be wrong.....probably am (so someone please verify?)....but if the Arduino is putting 5V @ 20-30mA through a 1000 Ohm resistor.....wouldn't that limit current to the transistor to only like a half a mA?

Personally, I'd try it without the resistor. But, I'm a bit of a risk-taker. Maybe try a smaller resistor?

Anyone else have an opinion on this?
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: nickgammon on Jun 29, 2013, 06:34 am
Where do you see a 1K resistor?
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: 1ChicagoDave on Jun 29, 2013, 07:51 am

Where do you see a 1K resistor?


On base of transistor. In the photo he posted. And the schematic.

I didn't see the whole second page of the conversation until after I asked about the 1K though. Guess it's working now.

I am a little curious about it though.
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: oric_dan on Jun 29, 2013, 08:27 am
Risktaker is always fun, but with electronics you need to learn a little theory,
although the good thing is, when you make a bad, something usually smokes
as a result. Or just stops working, so then you can sit there and 2nd guess the
universe.

You ALWAYS need a series base R with an NPN inverter, as it sets the actual current
into the base.

Ib = (5V - 0.7V) / 1K = 4.3mA.

Do a google search on NPN inverter, and read a bit.
Title: Re: Controlling a 5v relay, only getting 2.4v?
Post by: MarkT on Jun 29, 2013, 01:18 pm

Yep. And it had nothing to do with the problem whatsoever. Turns out I forgot to set pinMode(dirPin, OUTPUT).   :P

Oops.

All is well now. I guess the lesson is, don't give a pin a name that sounds like derpin'  ;)


Do you see now why the guidelines say "post all of your code"?