Basically I am trying to make a 2-bit DAC that can interface to an external device via one signal wire. I want to create a 3-step signal that can be ~0V, 2.5V, and ~5V.

For starters, I tried using two NPN transistors controlled by two 3.3V output pins from an MCU.

Here is the schematic I have simulated in LT Spice...

enter image description here

With this schematic, I can get my ~0V and ~2.5V fine, but I cannot get 5V. When I apply voltage only to Q5 (the top NPN), I only get 3.03V at the output.

Looking this up with google only yield results for a "tri-state buffer" that has the output possibilities of 0V, 5V, and high-z. I cannot find a shcematic or IC to accomplish what I am looking for exactly....but maybe my search terms are incorrect?

I need a suggested schematic mod or an IC to accomplish what I am looking for if anyone has any suggestions! Thanks!


I found this Fig. in another post which will take care of reaching up to the 5V. I just need to add a second transistor switch and create a voltage divider which I already know how to do. The LED will replaced by an outbound signal.

enter image description here

Image source.

  • 1
    \$\begingroup\$ If you are trying to digitally change the LED brightness you are much better off using PWM. \$\endgroup\$ – crj11 Sep 11 '18 at 14:32
  • \$\begingroup\$ Actually it is to control two LEDs with opposite polarities. I will update the post. \$\endgroup\$ – zme Sep 11 '18 at 14:34
  • \$\begingroup\$ Is there a common terminal between the LEDs that you are driving? In general, it would be useful to show the LEDs in the schematic. Also, what are the forward voltage drops of the LEDs? \$\endgroup\$ – crj11 Sep 11 '18 at 14:41
  • \$\begingroup\$ "only get 3.03V" yes, because there are voltage drops on R7 and Q5. \$\endgroup\$ – Long Pham Sep 11 '18 at 14:42
  • \$\begingroup\$ Q5 is an emitter follower - the emitter voltage will always be about 0.7 volts below the base voltage. You need a PNP transistor on top to pull the output to +5 V. \$\endgroup\$ – Peter Bennett Sep 11 '18 at 14:52

The LEDnique image is mine. Here's another.

enter image description here

Figure 1. A bi-colour 2-pin LED can easily be switched to either colour or any blend in between with two GPIO pins. Source: 2 GPIO, 1 bi-colour 2-pin LED.

With a 3.3 V MCU you should be able to drive a red-green LED by decreasing R1 to 100 Ω for about 10 mA through the LEDs.

If you need a higher voltage, such as 5 V to drive white or blue LEDs, then try this.

enter image description here

Figure 2. 2 x GPIO controlling a higher voltage LED from a 3.3 V GPIO. Source: 2 GPIO, 1 bi-colour 2-pin LED.

See the linked article for an explanation of how it works. The circuit will work for 12 or 24 V LEDs too.

  • \$\begingroup\$ Cool thanks! I pointed out in an edit to the original post that it will be a single output signal line interfacing to external devices. Can you provide insight to the updated question I added at the end? \$\endgroup\$ – zme Sep 11 '18 at 19:08
  • 1
    \$\begingroup\$ Your original post could do with a clean-up. Read it back to yourself from the point of view of someone who has no idea what you are really trying to do. If you're trying to control LEDs then why do you want a 2-bit DAC? Delete the last schematic and ask it in a new question explaining what it's supposed to do. \$\endgroup\$ – Transistor Sep 11 '18 at 19:12
  • \$\begingroup\$ Thank you for your patience. I did not want to seem like I was spamming questions. electronics.stackexchange.com/questions/395531/… \$\endgroup\$ – zme Sep 11 '18 at 19:28
  • \$\begingroup\$ There isn't a problem with a series of well asked questions. They are preferred to a jumble of questions in one post - especially if it keeps getting added to! I'm not convinced that I've answered your question completely. See my previous comment two up from here. \$\endgroup\$ – Transistor Sep 11 '18 at 19:46
  • \$\begingroup\$ I cleaned up the post to simplify the requirement to only needing an output signal (what it connects to is irrelevant now) that can be 0, 2.5, or 5V. The image I used of yours in the OP "update" is the answer to how to get the 5V on the output. \$\endgroup\$ – zme Sep 11 '18 at 19:55

An NPN makes a poor high-side driver. The emitter voltage can never be higher than the base voltage minus \$V_{BE}\$. As you observed, you won't get more than 3.0V at the emitter under the best of circumstances.

You need to add a PNP transistor between +5V and R7. Use Q5, (along with resistors to limit the current) to provide the base current to the PNP.


I suggest that what you want is called an H-bridge. Assuming that your coding is A high gives LED 1 on, B high gives LED 2 on, A and B low gives neither on, and A and B are never high at the same time, something like


simulate this circuit – Schematic created using CircuitLab

When B is low, Q4 is on and Q3 is off. When A is high, Q1 is on and Q2 is off. This provides voltage across LED 1. When A is low and B is high, Q2 and Q3 are on and Q1 and Q4 are off, turning LED 2 on. When both inputs are either low or high, the voltage across the LEDs is zero.

Now, a big gotcha. A and B, when high, MUST be greater than about 4.5 volts (one diode drop below 5 volts). Likewise, when low, they MUST be less than about 0.5 volts. Failure to comply with either of these limits will cause both transistors to turn on at the same time, and they will fry. This means that the transition from low to high and high to low must be fast. This is not normally a problem, but you must be aware of it.

In this circuit, the 5k values provide enough base drive (about 1 mA) to provide 10 to 20 mA to an LED. But you MUST make sure that your logic sources will drive 1 mA and still go above 4.5 volts. I don't know what logic family you're dealing with, but not all will do this reliably.

  • \$\begingroup\$ Doesn't the OP need a "both on" option? \$\endgroup\$ – Scott Seidman Sep 11 '18 at 17:21
  • \$\begingroup\$ @ScottSeidman - I dunno. He doesn't say. It's not what you call a clear spec, and it's a good example of an xy problem. He also doesn't specify what "opposite polarity" means. That's why I specified. \$\endgroup\$ – WhatRoughBeast Sep 11 '18 at 18:30
  • \$\begingroup\$ This output interfaces to different types of external devices. The requirement is simply to get an output voltage of 0, 2.5, or 5 volts and allow up to 40mA current flow. \$\endgroup\$ – zme Sep 11 '18 at 18:41

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.