NPN as switch for arduino D gpio

Hya,

sorry if the question seams stupid, but i'm a complete newbee in electronics.

i'm trying to use a 2N2222 as a swtich, triggered by a gpio from my uno.

the 2N2222 have 12V on collector and 5v as trigger for base.

Problem is that emitter only outputs ~5V on emitte, but i need 12V.

Any suggestion?

How did you wire your BJT?

What you are getting is correct, you have it configured as an emitter follower circuit. You need to ground the emitter. Put a resistor a few hundred to 1K Ohms between the gpio and the base of the transistor. The collector becomes your output and goes to the - side of your load while the load + goes to the + of the power supply. If it is an inductive load add a diode with the cathode on the positive and the anode on the collector. Let us know how this works. Knowing your load would make this much easier to answer correctly.

@ J-M-L

                                             12VDC
                                               |
                                               |
                                             /
                       gpio ----  10K ----|<
                                             \
                                               |
                                             LOAD
                                               |
                                            ground

@gilshultz - yes, it's an emitter follower - project is quit simple.

arduino reads the LDR on A1, and triggers 12v to the ilumination of my car's navigation headunit, so it dims according light conditions, not when headligths are triggered.

As all grounds are common, i just need to feed this connection with 12V, and the most simple way, imho, is to have a transistor feeding it, as the power drain is very low.

But seams tha NPN is not a good idea, due the tension drop.

connecting the illumination connection to the collector side, will make it llways active, as collector is feeded by 12V.

I'm ready to consider PNP instead of NPN.

or any idea?

Thx in advance.

The load needs to be in the collector with the emitter connected directly to ground.

No it won’t, there is no connection from the collector to the emitter when there is no voltage on the base.

                                             12VDC
                                               |
                                               +---------------------- illumination wire [ NAVI HEAD UNIT ] --+                                              
                                               |                                                              |
                                             /                                                                |
                       gpio ----  10K ----|<                                                                 GND
                                             \
                                               |
                                               |
                                               |
                                              GND

will it work using this way?

No.
The load needs to be between the collector and the supply.
The GPIO needs to be one capable of PWM and you need to write to it using an analogWrite function call.

As you have it when you turn on the transistor you will short out your 12V supply and get a big bang, or things will melt.

If you need to switch the high side and leave the load connected to ground, then a PNP is what you would use. But you can't drive a PNP directly from a GPIO if it's switching 12V. You would need to have the GPIO drive an NPN, which in turn drives the PNP. You would need base resistors for both transistors.

ok, PNP might be the way.

could you please explain with diagram, npm -> pnp?

thx!

Why? You have not demonstrated why you want a top switch.

How are your headlights wired?

Do you turn them on with a connection to ground or do you turn them on with a connection to +12V.

I think he has.

Probably "very low" compared to a headlight, but likely in the order of an Amp. A 10k base resistor was never going to "cut it" anyway, nor I suspect was a 2N2222.

You need a P-FET with source to 12 V and drain to the panel lights. The gate then needs to be pulled down with an N-FET or NPN transistor.

This device would do the job nicely as it includes both FETs.

remote_switch_interface_schematic

will this work?

It might work, depending on how much current you need to switch. Anyway, below is an all-mosfet version.

ok. but what i have are:
2n2222 and 2n3906

2n3904 and 2n2222 are quite equivalent for this use, but seams that bc327 and 2n3906 are not equivalent, even being PNP transistors

i'm trying to learn.

a quick and dirty solution may be a 12V relay shield, but i think it's an overkill for such humble use.

the diagram with the remote swicth is exactly what i need...

any help most appreciated.

It will provided your load doesn't overload Q2.
But you may add a resistor between basis (base?) of Q2 and +12V to have this pin not floating when Q1 is off. And a diode in series with R1 may help also to shift the "off" level to 1.4V (instead of 0.7V in your design) to increase robustness in case of noise on your GND.

"But you may add a resistor between basis (base?) of Q2 and +12V to have this pin not floating when Q1 is off. And a diode in series with R1 may help also to shift the "off" level to 1.4V (instead of 0.7V in your design) to increase robustness in case of noise on your GND."

  • basis (base?) of Q2 and +12V to - R2 on this one.
  • diode - 1N4001 - 1N4007

Right?

Yes. Looks perfect!

Pretty uncritical. Voltages are all low, current as well. So even a small 1N4148 would do the job - it is just to add 0.7V voltage (drop) to properly separate high-level from low-level output of your controller. So take what you have.

I am waiting for you to specify just what current that illumination draws, which you need to have measured.

The 2N3906 is almost certainly completely unsuitable, while the BC327 at 800 mA rating may be usable if the current is no more than 500 mA and you drive it with 25 mA with a value of R3 as 470 ohms. You don't need a pullup on Q2 using BJTs in this application.

If the current is more than 600 mA, then I repeat that this device would be vastly more suitable using ShermanP's circuit.

=< 500mA -

facto: Pioneer and other head units have a lead for hooking the dash illumination for dimming when lights (head, tail and dash lights) are on. It's just a sensor, like the remote switch of car amplifiers.

Yes, by setup you can define by time (dim from hh:mm to hh:mm), auto (car lights) and manual.
neither of those fits my desire.

what i want: have the dash head unit dim according light conditions, independent of the car lights on or off - so simple as that.

No as complex as that. What is going to stop your light sensor picking up the light from your head unit or from the car’s lights?