0

Help needed! I am using an Arduino Nano and a general purpose npn (2n2222a) transistor to provide a 12v signal to a low current 12vdc load in an automobile. The Arudino code is set to pulse D2 at bootup/startup for .5 second. The PWM output setting was 255 (since switched to digitalWrite). However, the switched output measures only 4.5v (expected close to 12v). What am i doing wrong? Applying 12v+ directly to the black box works. The purpose is to simulate a temporary button push in the car so an auto function is enabled.

enter image description here

  • 2
    the black box is raising the voltage on the emitter ... that in turn raises the base voltage necessary for transistor to turn on ... the nano is not able to supply that voltage .... connect the emitter to GND ... place black box at the collector .... this has been beat to death here and many places ... do research about driving a motor or solenoid or lamp with an arduinp – jsotola Oct 19 at 23:58
  • I did do research, and found this circuit (4th circuit, emitter-follower) which looked close to my desired application: electronics-tutorials.ws/blog/…. – handyguy Oct 20 at 5:07
  • the problem with your circuit is that D2 does not rise to 12 V – jsotola Oct 20 at 5:11
  • How much current is needed for your black box with 12 V supply? – Avon97 Oct 20 at 5:11
  • not much current - it's supplying a signal to an auto control unit simulating a short button press - a few milliamps at a guess. – handyguy Oct 20 at 5:15
10

The problem is that you are using an NPN transistor as a high side switch.

The voltage at the emitter of the transistor will always be about 0.7V below the voltage at the base. The "high" output from the Arduino is 5V. The emitter will be at about 4.3V.

Have a look at the Wikipedia "emitter follower" page. The emitter follower is also called a common collector circuit. That explains the "problem" in more detail. It is only a problem in so far as it is not the correct solution for your task.

You need to use a "common emitter" circuit.

This usage is commonly called a "low side switch."

That would look like this:

schematic

simulate this circuit – Schematic created using CircuitLab

If your black box really needs its input pulled up to 12V, then you would do something like this:

schematic

simulate this circuit

The resistor values and transistor part numbers are place holders. The values of resistors you will need depends on the transistors you use. The transistor selection will depend on how much current you need to deliver to the black box.

I see in a comment that your black box only needs a few milliamperes. In that case, the shown transistors should work just fine. The resistor values may be a little too high, but I think they'll be OK.


A couple of additional points:

  1. The Arduino has PWM outputs, not PCM.
  2. The output voltage for your black box will be pulsing if you use any PWM value lower than 255. Your black box probably won't like that, and your voltmeter won't read a correct voltage.

You should use D2 as a digital output rather than PWM. Just turn it on or off rather than fiddling with the PWM duty cycle. Use "digitalWrite" instead of "analogWrite" on pin D2.

| improve this answer | |
  • Thanks, i switched to digitalWrite in the code. – handyguy Oct 22 at 23:52
3

The 2N2222 is an NPN device. Skipping all of the physics involved, that means that (in your application) it will sink current as a low-side switch, but not source current as a high-side switch.

If you want a high-side switch, you should find a PNP transistor. In this case your Nano pin will sink current from the transistor's base terminal.

I would recommend you stick with the 2N2222, but make two changes:

  1. Connect your "black box" between the positive terminal (+) of your 12V supply, and the collector terminal of the 2N2222.

  2. Reduce the size of your base resistor from 10Kohms to 1Kohms

| improve this answer | |
  • The ground side of the black box is not available. The black box (control unit) circuit has to supply +12v to simulate the switch press. – handyguy Oct 20 at 5:05
  • 2
    @Seamus: An NPN transistor will quite happily source current as a high side switch. Tha'ts what it does - it is an emitter follower. What it can't do is to provide a voltage at the emitter that is higher than the base voltage. – JRE Oct 20 at 8:42
  • 1
    No, Seamus, I'm not looking for a "chat room." I spend most of my time on the electrical engineering stack exchange. The statement "but not source current as a high-side switch" is incorrect. As the original question shows it, the 2N2222 would try to deliver all the current available from the 12V source to the black box. If the black box were a short circuit to ground, the 2N2222 would quickly burn out from trying to pass many amperes of current from the car battery. So much for "not sourcing current." – JRE Oct 20 at 9:17
  • 1
    As used, the black box won't consume much current (there's a comment that says it only needs a few milliamperes.) That doesn't change the fact that an NPN transistor used as a high side switch can quite happily source current from its emitter. – JRE Oct 20 at 9:50
  • 1
    And an NPN transistor will deliver current as shown in the question. Or haven't you tried it? – JRE Oct 20 at 10:19
2

What I have thought about is using an opto-coupler enter image description here

Connect the Arduino pin output to pin 1 through 330 ohms resistor, pin 2 to ground of Arduino, connect pin 4 to Vcc of 12 V and finally connect pin 3 to the black box load.

Try this configuration

Since black box only needs few milliamps as you said May be the transistor is not saturated since base current has to go through the black box load opto-coupler s have no base current instead they use photons

Here is the circuit diagram

enter image description here

5 V supply looks like the Arduino pin D2 and lamp is the black box load. This is 4N35 example

| improve this answer | |
  • The opto coupler looks like a good idea. The part is cheap and small. If it can switch 12vdc at a few ma, it looks like the simplest solution. – handyguy Oct 22 at 15:18
1

enter image description hereok, so i chose the 2 transistor high side circuit as i had the needed pnp transistor laying around. Works great, thanks everyone for your help. The trace (5v/div) shows the Arduino signal at 5v and the circuit output at 12v - perfect! enter image description here enter image description here

| improve this answer | |
0

You can use a relay if you want

Relay module

Assuming you only need to turn on and off the blackbox

Refer more here

https://howtomechatronics.com/tutorials/arduino/control-high-voltage-devices-arduino-relay-tutorial/

| improve this answer | |
  • Thanks for the idea; however a programmable delay is needed before the pulse is issued, thus the use of an arduino. – handyguy Oct 20 at 18:40
  • @handyguy Your arduino can control the relay, a relay works a bit like a transistor, but it's connected to 2 circuits, your low voltage arduino circuit will toggle the relay like a light switch which will let the 12v pass on the second circuit. – Oylex Oct 20 at 21:04
  • @handyguy Depends on the delay you mentioned if the delay is quite big number in milliseconds I am sure that relay can handle it like 500 ms pulse, you did not say anything about the pulse duration thus I have thought about this idea. – Night Shade Oct 21 at 6:42
  • about 250ms for the button push – handyguy Oct 21 at 20:59
  • you better try this with a relay I think it will work – Avon97 Oct 22 at 7:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.