12v relay and transistor

Hello,

I have tried two 2N3904 transistors with the schematic shown in this tutorial:

http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=119

The only difference is that my supply voltage to the relay coil is 12v (base voltage is still 5v). I cannot get the relay to close. I am using this relay: http://www.radioshack.com/product/index.jsp?productId=2062482 which only takes 30ma across the coil to close.

I keep thinking I need to use a different base resistor, but I cannot figure out what to use... I'm not even sure how it was determined to use a 1k resistor in the original tutorial. It would have been easier if I had found a 5v relay here in town, but I could not.

I'm not sure this is a valid test with a meter, but when I supply 5v to the collector side of the transistor I can measure the voltage going from 0v to 5v on the emitter side of the transistor (measuring between emitter and ground). When I do the same test with 12v at the collector it only changes by about .5 volts.

Any help would be great :-)

Thanks, Ryan

This may help...

http://www.instructables.com/id/Connecting_a_12V_Relay_to_Arduino/

I keep thinking I need to use a different base resistor, but I cannot figure out what to use... I'm not even sure how it was determined to use a 1k resistor in the original tutorial.

I just asked the same question...

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1245734119

pwillard sums it up here...

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1245734119#5

Good luck, Brian

When I do the same test with 12v at the collector it only changes by about .5 volts.

Connect the ground of the 12v supply to the ground of the arduino.

http://www.thebox.myzen.co.uk/Tutorial/Power.html

I forgot to mention that the power coming into the arduino is a 12v wall wart. I then take a wire from vin to the relay. This should take care of a common ground right?

I'm not sure this is a valid test with a meter, but when I supply 5v to the collector side of the transistor I can measure the voltage going from 0v to 5v on the emitter side of the transistor (measuring between emitter and ground). When I do the same test with 12v at the collector it only changes by about .5 volts.

It's not clear to me how you are doing this test. In the circuit, the emitter is tied to ground. Are you disconnecting it and inserting the meter between it and ground? If so, I wouldn't call that a meaningful test.

If on the other hand you are measuring from the transistor emitter to ground with the transistor emitter still in your circuit, it means that your circuit is not wired correctly. You need to connect the emitter to ground. A 5 V drop across a wire is just not feasible. :)

Yeah I think my test was invalid. Now I have another issue.... I have the circuit wired like this:

12v (from vin)-> relay coil -> collector gnd -> emitter digital output pin->1k resistor->base

Now the relay clicks closed and just stays closed even when the pin is toggled high and low. This happens with both a 3904 and 2222 transistor. I've not put in a switching diode yet because I just want to get the relay toggling reliably, but I dont think that should matter. Now I am really confused :-?

I can drive a LED using this same setup, but with 5v going to the collector and it works fine. So there is something I am misunderstanding about having 12v going to the transistor.

Thanks for all the help so far.

switching diode yet because I just want to get the relay toggling reliably

Do you mean the diode across the coil, you do need that to prevent back voltages possibly damaging your output pins.

Now the relay clicks closed and just stays closed even when the pin is toggled high and low

Can you post the code? It sounds like a software error or damaged output pin. My guess is software.

int pin = 7;

void setup()
{
  pinMode(pin, OUTPUT);
}

void loop()
{
  digitalWrite(pin, LOW);
  delay(1000);
  digitalWrite(pin, HIGH);
  delay(1000);
}

I have tried other pins and they do not work either. I get enough current to drive a red LED so I think the pin is okay... I tried putting a 500ohm resistor between the relay coil and the collector pin. When I did that the relay started out as off and turned on when the pin went high, but then the relay never went off when the pin went low.

I tried putting a 500ohm resistor between the relay coil and the collector pin. When I did that the relay started out as off and turned on when the pin went high, but then the relay never went off when the pin went low.

Now what you are saying doesn't add up at all. I can only thing you don't have the hardware as you think you have it. Double check that you have identified the transistors legs. Connect an LED and resistor across the relay coil, that should come on and off with the relay. Connect the 12V ground to the arduino ground.

If you have done all that it is time to post a picture of what you have so we can try and sus out where you are making the mistake.

Okay, I hooked up an LED and it is always on, but it goes from dull to bright, but never fully off. So it looks like I am not getting a good cutoff on the transistor. I took a crappy cell phone picture of the circuit.

sounds about the same as my problem.
anyone that knows how to connect it using 12v with Positive output…
should it have both NPN & PNP, and if so, how to connect it?
i need about 6 Amps, to drive a rather big LED-strobe, so relays are not my first choice.
however, i guess the connection is the same…

FYI: i’m building 8 arrays of 28*12 LEDs,
driving them at about 25mA/led with <10% duty cycle.
(connected them as 28 banks * 4 rows of 3 * 25mA = 2,8A)
they are about 10x16cm, and produce about 2016cd = 300 lumen :slight_smile:

Sorry that has got me. I can't see what you are doing wrong unless your resistor values are way off. 1K is brown, black, red and 10K is brown, black, orange. I can't see that from the photograph.

SimBox There is a relay driver here http://www.thebox.myzen.co.uk/Workshop/Motors_1.html but I don't know what you mean by:-

using 12v with Positive output..

All 12V supplies have a positive output .

Part of the first one build, just found that 99 leds did not cover the whole pcb. :-/ in the end just [/color]+ should be switched. not ground. The LED arrays HAVE to be connected to ground, as the wires already exist, and it is NOT possible to re-wire the whole thing... and a note: your website does not display right when using internet explorer (v8) ...[/b]

Yeah it has me baffled too. The resistor is correct (also tested with a meter). The transistor works fine when I have 5v going to the collector (it fully turns on and off the LED). Unfortunately 5v is not enough to drive the relay. Does the voltage going to the collector effect the cut-off and saturation point?

This is something i have been thinking of, but i do not know for sure what values to use, and if this would work at all... NPN = BC547B (100mA) PNP = TIP137 (6-12A) R = 1/4w 1%

Does the voltage going to the collector effect the cut-off and saturation point?

No, not much to speak of.

. The transistor works fine when I have 5v going to the collector

Can you measure the voltage from your supply when it is on load?

However, this has all the symptoms of not connecting the grounds together

Yeah maybe something is going on with the wall-wart and the ground pin. I had to travel, but when I get back Ill try connecting directly to the outside of the wallwart plug for ground and see how it works. I should have just brought the project with me, but I think explaining it to TSA would have been quite an interesting experience.

but I think explaining it to TSA would have been quite an interesting experience

I've traveled with all kinds of tangly wires, loose electronic bits, and breadboarded things. They had a fit when I went through the security check-point carrying a mug of water.

Don't bring the project in your carry-on luggage and you should be OK.

  • Brian

Will this work with the Arduino Mini as well? Would I need a different transistor to trigger from 3.6v?

I tried manually tying the grounds together and I still see the same symptom. When I hookup to USB the LED goes off and on. Unfortunately there is not enough voltage to turn on the relay. When I hookup to the 12v wall-wart (no circuit changes) the relay switches on and the LED stays on all the time but goes from dull to bright. The LED stays lit even when I tie the base to ground.

I think my transistors are good, I read about 1.7 megaohms between collector and emitter. I know this post is about a PIC and PNP transistor but could something similar be going on in my case? http://www.nabble.com/-PIC--%2B12V-high-side-transistor-switch--td17782399.html

I think I am just going to have to declare defeat and get a relay rated for 5v. I have spent way too much time on something so simple :-(