in the below Fritzing diagram, I have a button that has a pull-up resistor, which when pressed, sets the GPIO Pin 23 to HIGH. On the Raspberry Pi, when the button is released, the GPIO goes LOW. The Raspberry Pi detects when the button is released and pressed. This is my desired behavior.

However, in my current configuration, I have PIN 13 connected to the Base of a NPN transistor to try to simulate the same behavior as the button with a pull-up resistor. When pin 13 is set to high, it sets the GPIO 22 Pin to high. When I set the Arduino Pin 13 to low, The GPIO Pin goes low but the Raspberry PI does not detect that GPIO 22 pin went low. Is there a way to simulate the same behavior as a button with a pull-up resistor with an OUTPUT pin from the arduino?

enter image description here


First of all, I don't think you will need full simulation of a button. There are a couple of things this approach won't have:

  • Bouncing: it'll be (kinda, minus interference) a square wave. With a real button, the metal contacts "bounce," thus creating a weird waveform. Depending on interference, you'll still need debouncing code, although I would be surprised if it was necessary. I'd inlcude it in case I modified it to add a real button and/or there's some weird interference.
  • The time it's "pushed" may be very short, depending on your code. Keep this in mind when designing this.

Basically, you're hooking up the Arduino and the RPi together, with a voltage divider or a level shifter between the two.

Voltage divider:


That is a voltage regulator (drawn four different ways; it's the same circuit). I calculated the values you will need: 1700 ohm for R1, 3300 ohm for R2.

Of course, serial (with USB of the Arduino) communication would be a lot easier...


I don't think your circuit is correct. If red is positive and your switch is momentary closed then it actually pulls GPIO23 low.

Likewise with the NPN transistor, using it in this way gives you an inverter. It should work if internal pull ups are enabled on GPIO22 and you remove the resistor.

IF GPIO23 is 5V tolerant, you can instead connect the resistor to 5V and GPIO23 straight to the collector.

You should also have a 1K resistor between the arduino pin 13 and the base of the transistor to limit the base current.

This all assumes that the VCE of the transistor is lower than the 0.8V low-level cutoff of the GPIO pins (it should be).

In any case, if GPIO23 is 5V tolerant, just connect it straight to the Arduino. If it isn't, follow penguins advice and use a voltage divider.

  • I think you are correct. I tried all the suggestions and I believe the issue is the program running on the pi that translates the HIGH/LOWS key presses. The program is on GIT HUB and asked for clarification there. Thanks for the help
    – PhillyNJ
    May 29 '14 at 13:37

If you don't mind using SMD components you could use the NX3V1G66 analog switch.

When you send a signal to the IC it will simulate a push button.

Maybe there are leaded versions of this IC but I haven't found them on the website where I order all my components.


So the solution to this was to remove the transistor all together and connect the Arduino pin directly to the Pi. However, I need to change my Arduino sketch. The approach was to set the pin HIGH and go LOW when selected. I had it backwards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.