user69577: 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.


user69577: ok, 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!



user66535: What I have thought about is using an opto-coupler

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

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

user47458: 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:

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

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



user10567: 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:

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:

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:

The Arduino has PWM outputs, not PCM.
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.

69577: <p>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.</p>
<p><a href="https://i.stack.imgur.com/6gJ8K.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6gJ8K.jpg" alt="enter image description here" /></a></p>
 69577: <p><a href="https://i.stack.imgur.com/ReotF.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ReotF.jpg" alt="enter image description here" /></a>ok, 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!
<a href="https://i.stack.imgur.com/TPelO.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TPelO.jpg" alt="enter image description here" /></a>
<a href="https://i.stack.imgur.com/U1ZEK.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U1ZEK.jpg" alt="enter image description here" /></a></p>
 66535: <p>What I have thought about is using an opto-coupler
<a href="https://i.stack.imgur.com/Y9PY3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Y9PY3.png" alt="enter image description here" /></a></p>
<p>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.</p>
<p>Try this configuration</p>
<p>Since black box only needs few milliamps as you said
May be the transistor is not <em><strong>saturated</strong></em> since base current has to go through the black box load opto-coupler s have <em><strong>no base current instead they use photons</strong></em></p>
<p>Here is the circuit diagram</p>
<p><a href="https://i.stack.imgur.com/dB2Rp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/dB2Rp.png" alt="enter image description here" /></a></p>
<p>5 V supply looks like the Arduino pin D2 and lamp is the black box load.
This is 4N35 example</p>
 47458: <p>The 2N2222 is an <a href="https://www.electronics-tutorials.ws/transistor/tran_2.html" rel="nofollow noreferrer"><em>NPN</em></a> device. Skipping all of the physics involved, that means that (in your application) it will <em><strong>sink</strong></em> current as a <em>low-side switch</em>, but not <em><strong>source</strong></em> current as a <em>high-side switch</em>.</p>
<p>If you want a <em>high-side switch</em>, you should find a <em>PNP</em> transistor. In this case your Nano pin will <strong>sink</strong> current from the transistor's base terminal.</p>
<p>I would recommend you stick with the 2N2222, but make two changes:</p>
<ol>
<li><p>Connect your &quot;black box&quot; between the positive terminal (+) of your 12V supply, and the <strong>collector</strong> terminal of the 2N2222.</p>
</li>
<li><p>Reduce the size of your base resistor from 10Kohms to 1Kohms</p>
</li>
</ol>
 10567: <p>The problem is that you are using an NPN transistor as a high side switch.</p>
<p>The voltage at the emitter of the transistor will always be about 0.7V below the voltage at the base.  The &quot;high&quot; output from the Arduino is 5V.  The emitter will be at about 4.3V.</p>
<p>Have a look at the Wikipedia <a href="https://en.wikipedia.org/wiki/Common_collector" rel="noreferrer">&quot;emitter follower&quot;</a> page.  The emitter follower is also called a common collector circuit. That explains the &quot;problem&quot; in more detail.  It is only a problem in so far as it is not the correct solution for your task.</p>
<p>You need to use a <a href="https://en.wikipedia.org/wiki/Common_emitter" rel="noreferrer">&quot;common emitter&quot;</a> circuit.</p>
<p>This usage is commonly called a &quot;low side switch.&quot;</p>
<p>That would look like this:</p>

<p><img src="https://i.stack.imgur.com/FoH9v.png" alt="schematic" /></p>

<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fFoH9v.png">simulate this circuit</a> &ndash; Schematic created using <a href="https://www.circuitlab.com/" rel="noreferrer">CircuitLab</a></sup></p>
<p>If your black box really needs its input pulled up to 12V, then you would do something like this:</p>

<p><img src="https://i.stack.imgur.com/DcNCM.png" alt="schematic" /></p>

<p><sup><a href="/plugins/schematics?image=http%3a%2f%2fi.stack.imgur.com%2fDcNCM.png">simulate this circuit</a></sup></p>
<p>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.</p>
<p>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.</p>
<hr />
<p>A couple of additional points:</p>
<ol>
<li>The Arduino has PWM outputs, not PCM.</li>
<li>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.</li>
</ol>
<p>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 <a href="https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/" rel="noreferrer">&quot;digitalWrite&quot;</a> instead of <a href="https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/" rel="noreferrer">&quot;analogWrite&quot;</a> on pin D2.</p>
