# How to use PNP transistor as a switch for serial communication

I am trying to interface a 3.3volt TTY bluetooth dongle to my arduino. The dongle requires 3.3volt but the arduino's Tx and Rx signals are 5 volt. Apperently the 3.3volt is enough for the arduino Rx, but the 5volt Rx for the bluetooth will be too much.

I have a couple PNP transistors laying around. I am not at all familiar with transistors (I do more with large electronics and relays). I know that a transistor can be used similarly to a relay though.

Would it be possible to control the state of the transistor with the 5 volt Tx from the arduino. But have the transistor output 3.3volt from a separate power source?

If it is possible. How can I do this? Could someone please explain.

Thank you.

You don't even need the transistor. A couple of resistors will do.

If you pick 10 k$\Omega$ for R1 and 20 k$\Omega$ for R2 an input voltage of 5 V will be scaled down to 3.3 V out. In general:

$V_{OUT} = \dfrac{R_2}{R_1 + R_2} V_{IN}$

edit

Apparently the 3.3 volt is enough for the Arduino Rx

Olin rightly points this out. It may not be guaranteed, and then you're just lucky that it works, but then there's no guarantee that it will always work. The ATMega328 datasheet says

and since Arduino works at 5 V it looks like you're safe: 0.6 Vcc < 3.3 V, and Arduino's NCP1117 voltage regulator is 2% accurate, which also helps. Still you have little headroom, and you should check that the output high from the Bluetooth dongle will always be higher than 3.1 V (probably will).

• Thanks a lot for your answer. I should have thought of using resistors, myself. I guess I was just eager to use a transistor for something! Jun 21, 2012 at 16:50
• @Keegan - Yeah, I was almost tempted to make an intricate circuit with three or four PNPs ;-), but as my dear friend Albert says: "Everything should be as simple as possible, but not simpler." Jun 21, 2012 at 17:16

As Steven said, going from 5 V to 3.3 V is as easy as a couple of resistors unless you need really high speed. I usually use 1 kΩ at top and 2 kΩ at bottom. That's a good tradeoff between current and speed for most cases, but of course you should look at that tradeoff for your particular case. This also assumes a CMOS input or something else high impedance is being driven.

You should NOT just assume going the other way is OK without a level shifter. Look at the Arduino logic input levels carefully. I'm not familiar with the Atmel most Arduinos are based on, but with many Microchip PICs for example, 3.3 V is not enough to guarantee it will be interpreted as a logic high. PIC pins with Schmitt trigger inputs usually require 80% of Vdd to guarantee a logic high. That is 4.0 V on 5 V systems. 3.3 V may actually be enough most of the time, but it is a really bad idea to rely on this. Simple trying to see if it appears to work is not good enough. That does not guarantee it will work at a slightly different temperature, supply voltage, over time, or with a different Arduino board. You must check the specs.

This sparkfun tutorial has many strategies for different voltage level interfacing lined out.