understanding transistor use with arduino.

Hello guys,

I am having a hard time still understanding how to work with transistor for my arduino project.

I have read several websites and watches several videos and learned that a transistor does two things :

1, it works as a switch 2, amplifies a signal ( does this mean voltage?)

I also learned that in a transistor the 'base' is what triggers the conductivity between the collector and emitter and that the 'C' and 'E' are interchangeable ? In terms of connecting them to a power source's pos and neg. ?

Now the main question is, does the power source at the base need to come from a separate circuit that the power that is at the collector and emitter?

If this is true, What if I have a 12v power source that I am using to power the entire circuit and arduino and relays etc ?

Lastly, in the attached images, the author is using the same type is transistors, yes in one he says that a low triggers the transistor, whereas on the other diagram, a pos signals triggers it. Is there a mistake is any of the schematics or am I mistaken with something ?

I would appreciate some help warping my head around this.

Here the images, sorry

This one shows that the transistor will activate upon the pin going to ground?

This one if the opposite.

In both scenarios, they author is using NPN transistors.

http://www.mcmanis.com/chuck/robotics/tutorial/h-bridge/bjt_theory.html

yes in one he says that a low triggers the transistor, whereas on the other diagram, a pos signals triggers it. Is there a mistake is any of the schematics or am I mistaken with something ?

In both cases a “high” from the port pin turns on the transistor (the collector-to-emitter portion becomes a good conductor) and therefore, turns on the lamp or relay to which it is connected. In both cases, the Arduino and the rest of the circuit must share a common ground (not shown on the diagram).

2, amplifies a signal ( does this mean voltage?)

Both, depending on the circuit. A transistor at it's heart is a current amplifier. In the linear range the collector-emitter current is proportional to the base-emitter current.

But, most amplifier circuits are voltage amplifiers... Let's say you have an audio amplifier with a gain of 10... That's the voltage gain. If you put 1 Volt in, you get 10 Volts out. But in fact, it's also amplifying the current... If you have a speaker connected you are getting more current out than you are putting in. But with nothing connected, you are still getting the 10 Volts out, but no current, so no current gain. Since the output voltage is always proportional to the input voltage (when everything is in the proper range and operating normally), and the current depends on the load, we classify it as a voltage amplifier.

If you open-up an electronic device, most of the time there is one power supply (or battery) powering all of the transistors and everything else.

I also learned that in a transistor the 'base' is what triggers the conductivity between the collector and emitter and that the 'C' and 'E' are interchangeable ? In terms of connecting them to a power source's pos and neg. ?

No, they are not interchangeable. The base-emitter voltage & current "control" the collector-emitter current.

Now the main question is, does the power source at the base need to come from a separate circuit that the power that is at the collector and emitter?

No. In fact you need a common connection, usually a common ground. If you want to boost the Arduino output to 12V, you might use a separate 12V supply or you might use the same 12V supply that's powering your Arduino. But, "separate" does not mean "isolated" because you need that common ground. (You can use an optical isolator if you need isolation.)

If this is true, What if I have a 12v power source that I am using to power the entire circuit and arduino and relays etc ?

Usually that's fine. But with relays & motors, sometimes you can get electrical noise on the power supply that will cause a glitch or crash your Arduino. Just something to be aware of.. There are "tricks" with diodes & capacitors that can help to block/isolate the noise.

Lastly, in the attached images, the author is using the same type is transistors, yes in one he says that a low triggers the transistor, whereas on the other diagram, a pos signals triggers it. Is there a mistake is any of the schematics or am I mistaken with something ?

The author is made a mistake! Both circuits are the same! It can get complicated, and you have to analyze the circuit in by figuring-out the base-emitter current/voltage and then what happens when the current gain is applied through the collector-emitter. In circuits where the emitter is not grounded, the emitter voltage changes depending on the emitter current, and the voltage applied directly to the base may not be equal to the base-emitter voltage.

And, because of the inverse relationship between the collector-emitter current and the collector-emitter voltage, most amplifier circuits are inverting amplifiers (i.e. +1V into an inverting amplifier stage with a gain of 10 will put-out -10V). In the switching examples you've shown, the voltage logic is inverted, and it's the collector being "pulled down" nearly to ground that creates a voltage drop across the lamp/relay and turns it on.

Thank you all for the help and clarification.

Here is a image of my replication / attempt to make a simple circuit with a transistor. but I am still having a little issue I want to understand.

The transistor is from radioshack: 2N2907-331

About the image:

So I am using a 13.8v power supply to bring power to the bread board (whit and black wire). I am also using the same voltage across the transistor. I am also using some resistors to split the 13.8 to simulate a lower voltage ( think an high output from the aurduino) into 6.5v that I am connecting into the base of the transistor (blue wire). All the black wires are ground.

The idea here is to actuate the 12v relay.

When I connect the blue wire to the base, nothing happens. Yet there is 13.8v on the emitter and collector at all time. Here is where things get very confusing for me, if I use a 9v or even a 1.5v AAA and connect it to the base, the circuit works.

This is why I asked originally if the power and ground for the base of the transistor needed to be isolated. I would really like to know why this happens; what I am doing wrong. As it is, I think I sorted my Arduino and I Am waiting for a replacement =(

there are two types of transistors. PNP and NPN

the NPN goes between your device and ground and it pulls the power through your device to ground.

the PNP gets power and sends that to your device.

please check the data sheet.

the 2907 is a PNP device.

power to the collector, the emitter to the relay, then the relay to ground.

then send the base 5 volts.

also, may I recommend you put in some LED's on the relay to watch it change state ? some relays do not make much noise.

Thank you all for the help.
What I needed to do was connect the Base to ground (0v) since this was a PNP transistor and it worked all well from within the same circuit.

When I get my replacement arduino tomorrow, I will need to connect the wire from the base to a digital I/O.
When I get tot he code, let’s say I use PIN 3, will I need to set it to an output? what will be its state while not making 0v?

Thank you.

While connecting the base of a PNP transistor to ground through a resistor will turn it on, you need to put the base to a voltage closer than 0.7V of the emitter to turn it off. As the emitter is connected to 12V you can't do this direct from an arduino pin which will only output 5V.

^ while the arduino can't produce 13.8v or rather 13.1v as per your suggestion (Btw where did you get that info from?) If I set the pin to low, isn't that the same as grounding the wire ?

http://incredulist.blogspot.com/2012/10/high-side-switching.html

crullier: ^ while the arduino can't produce 13.8v or rather 13.1v as per your suggestion (Btw where did you get that info from?) If I set the pin to low, isn't that the same as grounding the wire ?

Yes.

But when you set it HIGH (or even INPUT) it's connected to the +5V line so a PNP will switch on when you're using 13V.

See this video: https://www.youtube.com/watch?v=CFt8hkh17_w (go to 16 minutes 15 seconds).

crullier:
(Btw where did you get that info from?)

If you are using a PNP transistor with a 12V supply the emitter has to be at 12V, if not then your circuit is totally screwed. As you do not post schematics I don’t know how screwed it is.

If I set the pin to low, isn’t that the same as grounding the wire ?

Yes sure it is, it will turn on the transistor. And that transistor will be permanently turned on you will never be able to turn it off. Thus rendering it a chocolate teapot device.

Thus rendering it a chocolate teapot device. [/quote]

I NEED a schematic for this !

crullier:

You should include a diode for that relay coil. It would be connected in row 1 (cathode) & 2 (anode) right next to your two orange wires. This is the same as the schematic in your second reply.

When you switch the relay coil off it creates voltage spikes that can damage or mess things up; typically causes the Arduino to reset. The diode prevents that problem.

fungus:

crullier: ^ while the arduino can't produce 13.8v or rather 13.1v as per your suggestion (Btw where did you get that info from?) If I set the pin to low, isn't that the same as grounding the wire ?

Yes.

But when you set it HIGH (or even INPUT) it's connected to the +5V line so a PNP will switch on when you're using 13V.

See this video: https://www.youtube.com/watch?v=CFt8hkh17_w (go to 16 minutes 15 seconds).

I watched the video and I get that the pin will have 5v even when set to input etc. But what I would be setting the pin in the ARD to be an output.

I think though that what you are saying, is that the PNP I am using which turn on when it sees 0V or ground will also turn on when the pin sees 5v - because I am using 13v? can you please elaborate? can you please explain why do you say that the PNP will turn on when it sees 5v? that is basically the same scenario I had Post #4? where I was applying 6.5v to the base, and nothing was happening. I would appreciate you help understanding this.

It seems like the solution will be to get an NPN transistors isn't it? - this way it will turn on when it sees 5v (input or HIGH) and be off when set to 0v. In other words, the PNP does not work for what I am trying to do (which explains why radioshack was out of NPN and had a surplus of these). Am I on the right track?

guys, I don't have a schematics but I will TRY to draw something that hopefully makes sense. I noticed the wiring on the pictures I poster previously was wrong and after reading some of the post here I have made some changes.

I realized one of my mistake. I was under the impression that both PNP (my case) and NPN transistors needed positive power at the base to work. But in my case, [u]I need a ground or 0v for it to work.[/u]

This was confirmed by the way I have set things up at the moment. When the blue wire touches ground, I get 13.8v across the transistor, when the wire is disconnected (as in the picture) the connection is off Someone mentioned that in order to turn off the transistor, I really need to apply 13.8v - 0.07v = ~13.7v ? Again I want to understand why it is the transistors seems to be turning on when when its seems ground and not when it sees voltage as you guys are suggesting.

I can say,

int pwr = 3;
pinMode(pwr, OUTPUT);

// if such and such are met, then

digitalWrite(pwr, LOW);
delay(950)

@Chagrin: I will add a Diode next to the relay, I looked it up and I now understand how and why. Thank you

crullier: Someone mentioned that in order to turn off the transistor, I really need to apply 13.8v - 0.07v = ~13.7v ? Again I want to understand why it is the transistors seems to be turning on when when its seems ground and not when it sees voltage as you guys are suggesting.

I explained in my blog, previously referenced, to wit: The PNP conducts when its Base is at a potential less positive (more negative) than its Emitter. Equally important, but what's not grasped, is that it does not stop conducting till its Base is at or near its Emitter - just as an NPN does not stop conducting till its Base is at or near its Emitter. When the PNP's Emitter is at +12V, you cannot turn it off by presenting +5V to its Base - because 5V is still less positive than Emitter potential (in fact, 7 volts less positive).

I understand (but only after reading you blog twice and this link http://www.electronics-tutorials.ws/transistor/tran_1.html)

I also realized that my transistor is connected backwards. I currently had it connected as in Picture #1 and someone it worked... I have now connected it as in #2 (which is the correct way based on what I have read)

PNP, Power comes in through the Emitter and out the Collector. And it is an Common BC configuration. When I connect the Base to ground it also works. Now here is the part that was confusing me, when the blue wire was "floating" it would turn off the transistor, okay fine. I realize the within circuits this is not a valid state and of course the ARD pin will be either pos or neg.

And from what everyone is telling me, this state of (as am going to call it) neutrality cannot be replicated by the arduino. It's pins are either + or neg. And, the ARD will open the gave when it goes to low, but it will need 13.1v to close it with my 13.8v PSU.

Now just to see if I understand the concepts (and thank you for your patience), Hypothetically, if were to bring 6v through the C-E of the PNP transistor (because let's say my relay is a 5V relay), then the 5v HIGH from the ARD would turn off the transistor, and LOW would let the 6v pass.

The same applies to the NPN transistor, From the ARD I will have no problem keeping it off, but I will need 13.v to turn it on with my current setup of 13.8v source

So going back to this image, how is the author / or why is he suggesting that we can use 12v on the Collector after the relay?

crullier: When I connect the Base to ground it also works. Now here is the part that was confusing me, when the blue wire was "floating" it would turn off the transistor, okay fine. I realize the within circuits this is not a valid state ...

Nope.

"Floating" implies that the voltage applied to the base is important, and that's completely wrong for a BJT.

What matters to a BJT is how many amps are flowing through the base. If the base isn't connected to anything then the answer is obviously "none" so the transistor is switched off.

This is an utterly different concept than 'floating'.

(nb. None of this applies to MOSFETS, where the gate voltage is what counts and they can float).