Electronic – 5v signal to switch 3.3v input

transistors

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.

diagram

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

Best Answer

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.

schematic

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?

schematic

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.