# 5v signal to switch 3.3v input

I have an arduino that has one of its inputs pulled high and 'listening' for when either of two push buttons are pressed by pulling it to ground.

I would like this signal to also be sent to a nearby raspberry pi on one of its GPIO pins, so that it's pulled high by default and when either of the push buttons are pressed it is also pulled to ground. As the rpi expects 3.3v I was wondering if a simple transistor would suffice here. Would the above circuit work as expected? So when the transistor switches on it would pull the 3.3v away, leaving that input pin on the rpi reading 0 volts?

Lastly, if the circuit does make sense is the following calculation correct for the base resistor...

• current at collector = V/R = 3.3 / 10000 = 0.00033 A
• hfe = 35
• current at base... Ib = Ic / hfe = 0.00033 / 35 = 0.000009428 A
• R1 = V/I = (5 - 0.7) / 0.000009428 = 456000 Ohm
• also, would a resistor on the left side be recommended too to reduce the current being consumed when a switch is pressed? – user2921789 May 14 '16 at 10:46
• You need some revision on how a pull-up resistor is to be wired. They go between the positive supply and the switch and the GPIO is connected directly to the junction of the two. – Transistor May 14 '16 at 11:18
• Is there any reason you can't use a simple potential divider (two resistors) with the negative side resistor acting as a pull down? – Ian Bland May 14 '16 at 12:45

You have several problems with your schematic. S1 and S2 provide a direct short circuit on the 5 V supply. R1 is connected to GND - it will never switch high.

A simple solution is just to prevent the 5 V supply reaching the 3.3 V GPIO pin using a diode. simulate this circuit – Schematic created using CircuitLab

Figure 1. A diode prevents 5 V reaching Raspberry Pi 3.3. V input.

For your PN2222 base resistor, the standard approach is to drive the transistor hard into saturation to give minimum power dissipation in the transistor and maximum voltage to the load. A much higher base current is used as a result. A 1k to 10k resistor would be a good choice.

Out of curiosity though can you explain how/if I could get the same result using a transistor? simulate this circuit

Figure 2. Another way that doesn't work!

I can't think of a really clean way to step down from 5 V to 3.3 V logic while sharing a signal in this fashion. Figure 2 illustrates the problem.

• First note that the transistor will invert the signal logic feeding the RPi. When Ard GPIO is high RPi GPIO will be low.
• R1 is pulling the Arduino high but if we introduce R3 it will pull the Arduino input below 5 V. We could increase the value of R3 so that the Arduino input is high enough to read as a logic 1 but it's a little bit "vague" as a digital signal. You could probably get it to work.
• We can't leave out R3 as then the Q1 b-e junction will look like a diode connected across SW1 and SW2 pulling the Arduino input permanently low.

The solution of Figure 1 has advantages of simplicity, reliability, non-inversion and clear design intent. It won't confuse anyone.

• "R1 will never switch high"... that seems so obvious in hindsight, thanks for clarifying. The diode is definitely the simpler option - I'll go with that. Out of curiosity though can you explain how/if I could get the same result using a transistor? – user2921789 May 14 '16 at 11:29
• Though I think OP, @user2921789, should be commended for doing the maths with the Transistor. I don't see that often enough, regardless of the need to then go "at least divide that by 10 as long as it stays over 1k" – Asmyldof May 14 '16 at 11:38
• @user2921789: I added the explanation as requested as reward for accepting the answer. Thanks. – Transistor May 14 '16 at 12:21
• cheers for the addendum @transistor - it helped to try and get my head around when/when-not to use them. – user2921789 May 14 '16 at 12:32