I'm currently trying to detect a 3.3v signal with a gpio pin (the signal is regulated). I made research and I found several solutions and I don't know which one choose:

My questions are the following:

  • Which solution is the best for the Raspberry pi
  • Why this solution?
  • Does the resistor have the right value?

Thanks in advance!

  • The answer depends on what you have connected to the other end of the wire. What is it apart from 3.3V?
    – joan
    Nov 10, 2016 at 14:10
  • Its directly connected to the 3.3v generator/regulator
    – Majonsi
    Nov 10, 2016 at 14:12
  • In that case I'd just use the in-line resistor. One of the electrical guys may know better.
    – joan
    Nov 10, 2016 at 14:14
  • 3
    inline resistor, unless the 3.3V source gets connected/disconnected, then use a pull-down like in the bottom right picture. However, no need to build a pull-down as the RPi has those built in, just make sure you activate them through your GPIO library.
    – Phil B.
    Nov 10, 2016 at 14:15
  • Your question is unclear. You say "detect a 3.3v signal" … "the signal is regulated". Are you trying to detect voltage, or logic level. The circuits you have posted will be high if voltage is > ~1.8V.
    – Milliways
    Nov 10, 2016 at 22:53

3 Answers 3


The upper two circuits are somewhat okay.

When the signal is from a digital output changing fast from 0V->3.3V and vice versa, you can connect it directly to the Raspberry GPIO pin configured as input.

When you aren't sure whether the GPIO pin is configured as input or output (accidentally), you put a 1kΩ resistor in series to avoid a short circuit, should the GPIO and the outer circuit have different output levels.

The lower two circuits in your question make little to no sense. Forget about them.

When your input isn't 0 to 3.3V but e.g 0 to 5V, use an input voltage divider.


simulate this circuit – Schematic created using CircuitLab

You can also use 3.3kΩ and 6.8kΩ to have less cross current to GND. Why these values? Because 3.3V is 2/3 of 5V. And 680Ω is 2/3 of (680Ω+330Ω), too. For another input voltage, you have to recalculate.

Another way to achieve overvoltage protection is a diode on input.


simulate this circuit

How does this work? The GPIO is pulled up to 3.3V by the resistor. When the outer circuit e.g. applies +20V, the diode is non-conducting, protecting your pi. When the out circuit applies a voltage below +2.7V, the diode gets conducting and that voltage is applied to the GPIO.

You may want to combine this with the 1kΩ input resistor on the GPIO to protect your Pi against misconfigurations.

You can also activate the GPIO pullup of the Raspberry instead of using the 10kΩ resistor.

When your input is bouncy (e.g. a mechanical contact), you should debounce it with a timer circuit.


simulate this circuit

The capacitator is loaded through the resistor. When the switch is closed first time, the capacitator is emptied very quickly through the switch. It doesn't matter whether the switch bounces a while between open and closed, as the capacitator, which directs the GPIO input voltage can only be loaded slowly through the resistor.

Again you can activate the GPIO pullup of the Raspberry instead of using the 10kΩ resistor. Have to recalculate the value of the capacitator in that case.

  • 1
    Good answer but the 4th diagram from the question does make sense, it is using a pull-down for cases where the 3.3V input is floating. I think the 3rd one makes sense too and debounces this way: The resistor limits the overall current. If the supply bounces within specific bounds, the capacitor should keep the circuit high (presuming it has time to charge, and not enough time to completely discharge). I could be wrong about that though...
    – goldilocks
    Nov 10, 2016 at 16:02
  • I'm a bit allergic to pulldowns, because they don't mix with the diode protection circuit, which is the simplest solution for a lot of cases. The capacitator || resistor circuit does not make much sense when there isn't an input resistor left of it, because the timing depends on it.
    – Janka
    Nov 10, 2016 at 17:45
  • Ah right they're in parallel. But if the input bounce is between 3.3V and high-Z (instead of 3.3V and ground), then the capacitor will charge ASAP while its discharge is limited by the 390k resistor, creating a fixed time span (?).
    – goldilocks
    Nov 10, 2016 at 17:54
  • 1
    Yes, for switching between 3.3V and high-Z it works. But digital outputs never work that way, they are either open-collector/open-drain or push-pull (okay you could program a µC to act that way, switching between 3.3V and high-Z, but it's absolutely non-standard.)
    – Janka
    Nov 10, 2016 at 18:02
  • So an example use case would be if you had a button inline with the 3.3V source and wanted the GPIO to read high when it was pressed and low otherwise.
    – goldilocks
    Nov 10, 2016 at 18:10

There is no "best" design, there are designs which are optimal in some cases (and perhaps bad in others) and designs which are suboptimal in all cases.

The upper left on your picture is the simplest one, so it's optimal as long as you can guarantee the signal stays between 0 and 3.3V in all cases, and your GPIO pin is configured as input.

The upper right adds a resistor and protects you in case the GPIO pin is erroneously configured as output. The resistor will limit the current, preventing overheat damage. But, you'll need an extra component compared to previous one.

The lower left is bad in may ways. It doesn't offer any protection and creates stress current via the capacitor. You're better off with upper left design instead.

The lower right provides overcurrent protection and guarantees you'll read it as LOW when nothing is connected to the input. Useless unless you're designing something that can be hot-plugged.

Bonus: debouncing circuit

This circuit can be used when connecting GPIO pins to mechanical contacts, to avoid multiple HIGH-LOW-HIGH transitions when the contact is closed:


simulate this circuit – Schematic created using CircuitLab


From my experience, if you are going to use gpio as a 3.3v or 3.4v input, not much more, I recommend that you do not use a resistor. The reason is that when detecting the entry, if at that time is at 3.2v 3.15v, the result of GPIO is that the input is at 0v, and adding a resistance all you will do is get more results below 3.3v Finally at the time of reading the entry, what I have done and recommend is to read the entry 100 times. We will get enough 0v that can really be 3.2v, but if we take 100 samples and the input is active we will get at least 20% positive and assume that the input is active otherwise we would get 100% 0v.

If you want to use input 5v in gpio you need to use a voltage divider.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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