Why does 3-to-5 volt with transistor not work the way it should?

A quick google for "3v to 5v transistor" gives me dozens of circuit diagrams that look like option A below with a NPN transistor and a pull-up resistor. If I build the diagram in iCircult, it works as expected. However, when I wire it up on a breadboard, it doesn't work quite the way it should. Without any power to the base, I get Vout = 4.95v. With power to the base I get Vout = 0v so it is inverting my wave.

A few experiments later, I solve my problem using a PNP transistor and a pull-down resistor (option B). In both cases I am taking Vout from the Collector side of the transistor.

It's a pretty simple circuit, you'd think it would just work. I double and triple checked the connections. I have also posted a photo of the breadboard below. I always seem to have weird problems like this when working with transistors, so now I am sort of on a quest to understand why option A doesn't work like it should for me?

• What are the output impedance of the previous stage and the input impedance of the next stage? May 18, 2015 at 3:48
• Did you connect the grounds of both power supplies together? May 18, 2015 at 3:53
• @Ignacio the incoming 3v is 2.65mA and the incoming 5v is 4.95mA May 18, 2015 at 3:57
• I apologize, I went through so many iterations with the circuit that I forgot the original problem wasn't the 4.97-4.99 cycle -- that only happened in iCircuit. On the breadboard, the NPN circuit the Vout was low when the base had power and high when it didn't so it was inverting my wave. I will update my question accordingly. May 18, 2015 at 4:00
• This circuit is a level shifter AND inverter. When you push current through the base, the collector will go low. So the inversion is expected. If you need level shifting without inversion, then you can use two of them, or just use a CMOS buffer powered from 5V to level shift. May 18, 2015 at 4:06

Both circuits invert your input signal. The second one will not work properly.

If you want a non-inverting level shifter you can use this circuit:

simulate this circuit – Schematic created using CircuitLab

When the input is close to 3.3V, the transistor is off and R2 pulls the output up to 5V. When the input is close to ground, the transistor is saturated and the output is equal to the input plus maybe 50mV.

• This is a good idea. If it is not fast enough, add a small cap from emitter to collector of Q1. That may help. May 18, 2015 at 4:26
• Will this protect the input side from receiving anything over 3V? That is very important. May 18, 2015 at 4:30
• Yes. This only pulls up to 3.3 (or whatever) Volts. Where it says 3.3V in the circuit above, use the same power supply that you are using for your Raspberry Pi I/O and all will be well. May 18, 2015 at 4:34
• @mkeith Maybe 20-30pF across R1 would be better. May 18, 2015 at 4:37
• @ThatAintWorking, you only had to add the pulldown because you were testing on the breadboard, and "IN" was not connected to anything, right? If so, OK. But when "IN" is connected to your Raspberry Pi, the Raspberry Pi should drive it and no pulldown should be needed. May 18, 2015 at 5:02

Based on the updated information in the question, I believe Option A is working as I would expect. It both inverts the signal and level shifts it. I guess the examples you found didn't emphasize the inverting nature of this circuit.

Although I would suggest using 10k in series with the base. You want the collector current to be 10x or 20x the base current.

Option B is risky because it may expose the 3V output (the signal that is trying to control the base) to high voltages. Also, 3V may not be high enough to always turn off the PNP, so you may get incorrect data.

If you need to boost the level and maintain polarity, you could use a CMOS buffer powered from 5V, but driven with the 3V signal. If the signal is not super high-speed this will probably work OK, but may affect the duty cycle of the signal.

You could also use two transistors. The first one level shifts and inverts, and the second one just inverts it back to the desired polarity. Whether this will work depends on what you are using the signal for. This will be a sluggish setup, and may change teh duty cycle just as much as the buffer.

A last easy option is to use a comparator. You can set the inverting input to 1.5v with a voltage divider, and the non-inverting input will be your signal input. Power the comparator from 5V. Don't use an open-collector comparator. Use one that actively drives the output up to VCC.

Good luck to you!

• I'm sorry you answered before I got to correct my question. I misspoke about how it was behaving on the breadboard. May 18, 2015 at 4:07
• Add a diode to the 3v line doesn't seen to work. My 3v source will be a Raspberry Pi so I do want to protect that source because it is very sensitive to more than 3V. What alternative would you suggest? May 18, 2015 at 4:19
• I updated my answer, but Spehro's answer is very good. I have used a similar circuit to what Spehro suggested, except I used an N-channel FET. I just didn't think of it this time. I suggest you try his circuit first. May 18, 2015 at 4:30

If you don't want inverting, you can do the following. I use it for 5v sensors feeding a 3.3v arduino digital input.

• No base resistor? Apr 28, 2017 at 21:42
• Definitely want a base resistor there, as Enric says. Apr 28, 2017 at 22:15
• if there was a load, the transistor could consume a lot of current if it failed, but since it's feeding a high impedance input, the base resistor is optional. May 17, 2017 at 14:45