Arduino Forum

Using Arduino => General Electronics => Topic started by: Bittsen on Mar 09, 2014, 12:05 am

Title: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 09, 2014, 12:05 am
I want to control things with transistors instead of relays.
Is this an accurate example of a basic transistor setup to control a 5A-12V device?

(http://)
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Caltoa on Mar 09, 2014, 12:19 am
No :smiley-roll:

Do you want to use a normal transistor, a darlington transistor or a mosfet ?
Do you have one ? which type ?

In the picture is a mosfet, but if that is a n-channel mosfet, the source should be connected to ground.

For protection you can add a resistor of 100 ohm (100 ohm to 10k) from pin 4 to the gate.
You could also add a fly-back diode over the load.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 09, 2014, 12:23 am
No. You have the D & S swapped.
http://www.digikey.com/product-detail/en/NTD5867NL-1G/NTD5867NL-1GOS-ND/2401422
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 09, 2014, 12:29 am
I have a ton of IRF9540N P-channel mosfets at my disposal.

My diagram shows the transistor from the back side because I drew it before I labeled the outputs. I know the difference in the pinouts so that won't be a mistake as long as the question is to the label of the pinouts and not the actual placement.

Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Grumpy_Mike on Mar 09, 2014, 12:47 am
If that device is a p-channel FET then no it will not work.
You have to get the gate up to 12V to turn it off and it is connected to an arduino pin which will only get up to 5V.

Yet again by not supplying all relevant information you have wasted the time of all those who have answered this thread so far.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 09, 2014, 12:49 am
Ah - P-channel.
In that case you need an NPN in front of it, the Arduino can't supply 12V to the Gate to turn the P-channel off:
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Caltoa on Mar 09, 2014, 12:57 am
The load seems to be 'things' or 'device'. So I would suggest to use a fly-back diode over the load.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 09, 2014, 01:21 am
Original post was a light bulb tho.  Not sure you need a diode for an incandescent bulb.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: runaway_pancake on Mar 09, 2014, 03:12 am

Yet again by not supplying all relevant information you have wasted the time of all those who have answered this thread so far.


If anything, they "wasted" their own time by anticipating the OP's deal.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 09, 2014, 06:51 am

Yet again by not supplying all relevant information you have wasted the time of all those who have answered this thread so far.


Hey Mike.
What would I have to do to get you to drink some prune juice?

I didn't supply "relevant information" because there isn't any information.
I said I had those transistors at my disposal. I didn't say I "Had" to use them.

As for the "device" I will be controlling, there isn't one yet. I am, at the very least, smart enough to know that I need to add a device (diode) to prevent back current (especially if powering a DC motor).

My purpose for posting the original question was to clarify if the basic theory was correct.

Now I would like to know if anyone has suggestions for a transistor that can handle a decent sized load at 12V but triggered with 5V from an arduino. I know some will suggest a relay. The potential speed of the switch may be faster than a mechanical relay can handle.

Or should I start a new thread for that?
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 09, 2014, 07:12 am
What was wrong with the transistor you had?
http://www.digikey.com/product-search/en?x=16&y=11&lang=en&site=us&KeyWords=IRF9540N
Just need a simple NPN to drive it's gate.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 09, 2014, 07:40 am
Probably nothing but I would like to stay as simple as possible.

I am attempting to assimilate knowledge and have been looking at some Darlington transistors. I'm in the infancy of my research on transistors. I know their basic function but not the specifics.

Am I accurate in seeing that a large darlington NPN would operate similarly to adding a NPN to the IRF9540N?
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Caltoa on Mar 09, 2014, 11:01 am
A darlington has two transistors inside, that is why it the collector does not get close to 0V, but stays at about 1V.
So with a 1A load, you dissipate 1W of power, and you need a heatsink.

The NPN transistor with the IRF9540N is a good and simple solution. You have to trust us on this.

If you are going to buy new parts, buy a 'logic level' n-channel mosfet. That is the most simple way.
https://www.sparkfun.com/products/10213
All the extra components you need are a protection resistor from Arduino to gate, perhaps a fly-back diode over the load, and maybe 100k resistor from gate to ground for a pre-defined state during startup.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 09, 2014, 07:38 pm

A darlington has two transistors inside, that is why it the collector does not get close to 0V, but stays at about 1V.
So with a 1A load, you dissipate 1W of power, and you need a heatsink.

The NPN transistor with the IRF9540N is a good and simple solution. You have to trust us on this.

If you are going to buy new parts, buy a 'logic level' n-channel mosfet. That is the most simple way.
https://www.sparkfun.com/products/10213
All the extra components you need are a protection resistor from Arduino to gate, perhaps a fly-back diode over the load, and maybe 100k resistor from gate to ground for a pre-defined state during startup.


Thanks for a good, easily understandable, reply.
A logic level mosfet sounds good.
I was reading about the darlington and the voltage loss it has.
No matter what I will add a heat sink to whatever I concoct. Heat sinks are cheap.
The flyback diode for my first idea might not be needed because I'm running LEDs but since I'm trying to put together a small "all-in-one" project the flyback diode might be a good addition. The Darlington was enticing because it has a built in flyback diode.
I came to the conclusion I should have a couple resistors to keep the transistor honest. Again, the Darlington was appealing because they are built in.

Of course I could accomplish the same thing by using some solid state relays but they are so expensive in comparison.
I know someone who insists they would be easy to "make" because of the way they function.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: runaway_pancake on Mar 09, 2014, 08:13 pm
Whatever you do, DO NOT buy any Darlingtons
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 09, 2014, 08:26 pm

Whatever you do, DO NOT buy any Darlingtons


Thanks.
I'm abandoning the Darlington idea as simple as it would be, the benefits don't outweigh the sacrifices.

I found a pretty informative page here
http://arduinodiy.wordpress.com/2012/05/02/using-mosfets-with-ttl-levels/
that lists a few logic level Mosfets

It would be nice if there was a list of Logic Level Mosfets with noob descriptions. All the technical lingo makes me cross-eyed.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: runaway_pancake on Mar 09, 2014, 08:47 pm
Noob descriptions... ohhhh

Here's my rec -- STP40NF10L
Others will have theirs (stand by).

Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 09, 2014, 09:23 pm

Noob descriptions... ohhhh

Here's my rec -- STP40NF10L
Others will have theirs (stand by).




Ha,
I have been playing with a p40NF0 all morning. By playing with it I mean I've been picking it up and trying to figure out if it would be right.
I think I have a few of these laying around.

I'm pretty sure I've figured out that the first couple (or few) letters are manufacturer numbers. My particular one is simply p40nf0 but has other numbers as well. Most important is that it has a ST logo.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: larryd on Mar 09, 2014, 09:24 pm
Quote
It would be nice if there was a list of Logic Level Mosfets with noob descriptions.

Why stop there?
Have  a list of  sketches and routines so all you have to do is cut and paste and not have too learn programming. ;)
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 09, 2014, 09:35 pm

Quote
It would be nice if there was a list of Logic Level Mosfets with noob descriptions.

Why stop there?
Have not a list of  sketches and routines so all you have to do is cut and paste and not have too learn programming.


If we are going to use hyperbole, why not have to learn the programming so you can put gas in your car.
Or go to college to learn electrical theory to change a light bulb.

I don't know why people, like you, feel it's necessary for a hobbyist to learn engineering to be able to build a simple circuit.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: larryd on Mar 09, 2014, 09:49 pm
If you don't learn the reasons why and why not, you get: why is this getting hot, why is this not turning on, it worked for a moment etc.
I recommend asking questions here  and you will get the help you need. There are some basic characteristics we recommend you to look at when selecting components.
There use to be a link "ABC Arduino" or something like that where you could down load a PDF of typical circuits for the Arduino. I recommend hunting it down if it is still available.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 09, 2014, 10:14 pm
See? That's where I like to live. Halfway between knowing everything and knowing nothing.
If there was a noob list of components, with their engineering add-on descriptions, then it would be much more useful to hobbyists than someone saying "use this one" without the "and here's why" added.

I am capable of looking up a component if I know it's basic function. I found a list of NTE logic level transistors and understood enough of what they were saying but I don't like NTE. I don't know why but I don't.

Graphs don't seem to help. Stating the maximum watts of wasted energy does.

If I found one with a max throughput of 17A @ 100V with a 60W max wasted energy, would that be a good one? I don't plan on 100V and I don't plan on 17A. So, in my thought process if I'm only using 10% of the maximum capability of the transistor then I should be around 6W of loss? I could live with that.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 09, 2014, 11:50 pm
OK, this is where I'm at in my thought process.

Will this work?

Where would the flyback diode go?

Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: runaway_pancake on Mar 09, 2014, 11:52 pm
Let's see what you've got.
Attached is a diagram for connecting that dude up.
The "load" could be a motor or LED/s + resistor.
+V could be +5 or "Vin".  You work that out.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Caltoa on Mar 09, 2014, 11:53 pm
Bittsen, if you use a mosfet, please make a new picture with 'G', 'S', 'D'.
A n-channel mosfet is a low-side switch. It has the 'S' (source) connected to ground.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: larryd on Mar 09, 2014, 11:58 pm
You are using a BJT image instead of N channel MOS fet IRL540.
If you are driving a incandescent lamp you do not need a fly back diode.
Use fly back diodes on DC components with a coil.
see this is what I mean.

Edit, see:
http://www.dnatechindia.com/Tutorial/Transistors/MOSFET-as-a-Switch.html
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 10, 2014, 12:27 am
I will reply in a bit. There's a three year old that's begging for my attention.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 10, 2014, 03:24 am
OK, new labels (I hope this is correct now).

I won't be using this, right away, for anything with a DC coil but I want to build a "go-to" thing for my future projects and I may, in the future, need a flyback diode.

Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: runaway_pancake on Mar 10, 2014, 03:33 am
Yes, but...

Yes, but that's missing the low-value resistor like I showed in my example.
It's a real good idea.

Did you try it?
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: runaway_pancake on Mar 10, 2014, 03:40 am
Crap!
Strike that.
You have +V and Gnd to the transistor wrong.

Why do I bother?
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 10, 2014, 03:44 am
Wiring diagram is still not correct.
Want to use N-channel as a switch to connect "bottom" of Light to Gnd.
Low value resistor prevents too overcurrent into MOSFET gate capacitance.
Large value resistor keeps MOSFET off during reset state when IO pins are floating.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 10, 2014, 03:45 am
I haven't tried anything yet. THis is all still theory because I don't have the correct transistor in my possession yet.

In your example, however, you show to be switching the ground. My application won't be able to do this as my applications are going to be mostly automotive.
As most know, automotive is a passive ground system where the entire body of the car is the ground. There's no easy way to put the switch on the negative side so most switching goes on the positive side.

In your example the gate appears to be activated from a negative source, is that correct? If so then adding a resistor from the gate to ground seems like it would trigger some activity in the transistor.

Or am I seeing it wrong?

I do see the benefit of a drain resistor on the gate though. It would assure a true zero if it's important that the gate stays zero in an "off" situation.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 10, 2014, 03:48 am
This is exactly why I'm posting.

Telling me I have something wrong doesn't help. Telling me how to fix it would help.


Do transistors not trigger with a positive? Or is positive not going to flow through a resistor?

What's the deal?
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: larryd on Mar 10, 2014, 03:50 am
Quote
I don't know why people, like you, feel it's necessary for a hobbyist to learn engineering to be able to build a simple circuit.

This is why. . .
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 10, 2014, 03:51 am
So you want "high side" switching vs "low side".
N-channel is not good for that.
You need P-channel to go between 12V and the "top" of the load - and that requires an extra transistor because the Arduino can't switch 12V on/off.
I posted that diagram earlier in this topic. A pullup resistor to 12V keeps the P-channel off, a high into the NPN base turns the NPN on, which pulls the P-channel gate low to turn it on.

You need a copy of my book - it covers the basics like this.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: runaway_pancake on Mar 10, 2014, 03:53 am
No, the transistor turns on when the Gate goes positive.
You cannot source current from an N channel MOSFET.
When did we start talking about cars?



Ha,
I have been playing with a p40NF0 all morning. By playing with it I mean I've been picking it up and trying to figure out if it would be right.
I think I have a few of these laying around.


THis is all still theory because I don't have the correct transistor in my possession yet.


Come again???
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 10, 2014, 03:54 am
See Reply #5 again, covered this before you got off into the Darlington discussion.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: runaway_pancake on Mar 10, 2014, 03:55 am
Here's your drawing rendered rightwise (attached).

Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 10, 2014, 04:00 am
Yes, for N-channel. See Reply #5 for P-channel & high-side switch.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 10, 2014, 04:01 am

No, the transistor turns on when the Gate goes positive.
You cannot source current from an N channel MOSFET.
When did we start talking about cars?


Come again???


The transistor I was "playing with" is different than the one I put in my drawing.
Your drawing makes complete sense if I'm switching the negative.

I have been looking for a solution for, primarily, car applications the whole time. ALl of my drawings have been to switch the positive side. It appears there was a misunderstanding wbout that and all the suggestions have been centered around switching the negative side.

It's frustrating because whenever I put a Pchannel somewhere someone says I need a Nchannel. Then I get a handful of advice that's completely the opposite of whatever I just learned.

Then some people come in and call me a fool (not in so many words).

If I wanted to switch the negative then it's not an issue. But everything I'm working on is built around a positive 5V digital output from the arduino.

I will look again at post #5
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 10, 2014, 04:07 am
We keep ending up on N-channel as that is what you showed in Reply # 27, even posted part of a datasheet there.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: runaway_pancake on Mar 10, 2014, 04:08 am

The transistor I was "playing with" is different than the one I put in my drawing.


I think it is the same as that in my example.


Then some people come in and call me a fool (not in so many words).


Not by me.
Anyway, just leave it go.


If I wanted to switch the negative then it's not an issue. But everything I'm working on is built around a positive 5V digital output from the arduino.


So has everything that I have showed you.


You changed the context to "cars" and "high-side switching" all of a sudden.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: runaway_pancake on Mar 10, 2014, 04:11 am
It'd be nice if you'd be so kind as to stay "online" till this gets sorted.

I'm going to turn it over to CrossRoads.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 10, 2014, 04:16 am
Crossroads-

This is why I glossed over post 5 (and because I was reading about Darlingtons.

Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: larryd on Mar 10, 2014, 04:21 am
http://forum.arduino.cc/index.php?topic=61308
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 10, 2014, 04:25 am

It'd be nice if you'd be so kind as to stay "online" till this gets sorted.

I'm going to turn it over to CrossRoads.



I am "online". I'm having major issues with this website though. I don't know why it keeps booting me to "about blank" every time I post, whether or not the post goes through.

Don't lose faith in me. I am just delving into transistors. I assure that when it clicks it will click.

I have watched over a dozen 15 minute transistor tutorials and they all say pretty much the same thing. And that's nothing helpful. ~LOL~

So, let's cut to the chase. Pretend I am stupid for a second.

I have never understood transistors. I have never understood "factoring" in algebra. Other than that I have assimilated most every topic thrown my way. So I am transistor dumb.

NPN vs PNP (which I was actually taught in high school a few decades ago).

I don't even know what question to ask.

As for buying a book... I bought a few. They all talk like the reader is an engineer. If the reader was an engineer then they wouldn't need the stupid book. Right?

Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 10, 2014, 04:31 am
Bittsen,
The box is the Arduino, the transistor is an NPN (as indicated by the arrow on the emitter leg),  may have said a generic 2N2222 would do, and the top resistor value is not critical. 1K, 2.2K, 5K.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 10, 2014, 04:48 am

Bittsen,
The box is the Arduino, the transistor is an NPN (as indicated by the arrow on the emitter leg),  may have said a generic 2N2222 would do, and the top resistor value is not critical. 1K, 2.2K, 5K.


The ground from the arduino in your drawing is part of what threw me off.

OK, so I think I'm getting it.

The top resistor is just to provide a "load" that will allow the current to flow through the NPN.
Then the drain (or is it emitter) on the NPN provides a +/-12V signal to the gate of the P-channel Mosfet which, in turn, allows positive current to flow through the mosfet to the eventual load.

Or am I still off?

I promise I'm not trolling. THis how I see it happening.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: larryd on Mar 10, 2014, 05:03 am
An important thing to remember with switching transistors or MOSFETs always check (using a DVM, or scope) the collector to emitter or drain to source voltage to ensure they are fully saturating (turning on).  This will confirm you have things wired correctly and the device will be dissipating minimum power.  The ON voltage may be: with regular transistors as much as .4V, with darlingtons this could be 1.4V and with logic MOSFETs you are looking for less than .4V @10+amps.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 10, 2014, 05:05 am
The top resistor is to pull the Gate of the P-channel MOSFET High to turn it off.
To turn the P-channel MOSFET on, the gate must be pulled low; that's what the NPN transistor is for.
The Arduino High output puts current into the NPN base to turn it on. When it is on, the collector goes from 12V down to ~0.7V, and that low voltage turns on the p-channel mosfet.

So there are two technologies at play - the MOSFET, which only needs voltage level changes at the Gate to turn it off & on, and the NPN, which is BJT, which needs current, and lack of current into the base to turn it on & off.

Do some reading at wikipedia of MSOFET and BJT, it is quite interesting.
The NPN could also be directly replaced with an N-channel MOSFET.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 10, 2014, 05:15 am
No no no....

We aren't going back to talking about N-channel Mosfets. That's where I went off the rails earlier.

Essentially we are back to the beginning. My best option is just to design my project around the NPN transistor and the P-channel mosfets that I can get and are relatively cheap.

I will just have to redesign my project to accommodate more components. At least they are still cheaper than solid state relays and can modulate at 20?S
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: CrossRoads on Mar 10, 2014, 05:18 am
That works too.
Title: Re: Basic Transistor with Arduino. Is this accurate?
Post by: Bittsen on Mar 10, 2014, 08:37 am
Well, it would appear that virtualbreadboard is useless for this stuff.