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
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.
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.
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.
The solution of Figure 1 has advantages of simplicity, reliability, non-inversion and clear design intent. It won't confuse anyone.