Hi i am trying to connect the obstruction sensors on my garage door to the GPIO pins on a raspberry pi computer so i can monitor the state.

Since the garage door sensors runs on 6v and my raspi runs on 5v i was told to use a zener diode tied to ground, and a resistor to connect it to the raspi without frying it.

Is this hardware going to do what i want safely? (drop the 6v down to 5v so i can read the signal on the Pi and do something in software when i see a state change)

thanksenter image description here


1 Answer 1


Raspberry Pi has 3.3V I/O, so applying 5V to a GPIO will fry it.

You could use a simple voltage divider. Two 10K resistors, for example.

Using an optoisolator such as a 4N35 would be safer, as below, because you would not need to tie the ground of the RPi together with the ground of the garage door opener.


simulate this circuit – Schematic created using CircuitLab

When the +6V (relative to the 0V) is present, the infrared LED inside the 4N35 turns on, illuminating the phototransistor and causing it to conduct, making the GPIO go low. When the +6V input is less than about 1V, the LED is off and the GPIO goes high.

  • \$\begingroup\$ @user... For positive logic use the 0V as input . For inverted or negative logic use the 6V as input. If there is contact bounce , add a cap to the collector to ground with 15ms or so time constant , T for Rc*C=T \$\endgroup\$ Commented Dec 9, 2016 at 18:51
  • \$\begingroup\$ This here, is the correct answer. While you could make the simple resistor and zener work, over such long wire runs, you will end up having trouble with noise. This opto-isolator essentially breaks the noise paths in half, reducing susceptibility. Plus, if lighting strikes the garage, the opto(coupler) will die, sparing the (more expensive) RPi. Don't forget to put the opto in a socket for easy replacement, if needed. \$\endgroup\$
    – TezlaCoil
    Commented Dec 9, 2016 at 19:43
  • 1
    \$\begingroup\$ I cannot upvote Spehro Pefhany enough. #WhatSpehroSays Absolutely The 4N35 is less than a dollar. Just Do It \$\endgroup\$
    – neonzeon
    Commented Dec 9, 2016 at 19:44
  • \$\begingroup\$ order parts now, ill post up when i build thank you very much! \$\endgroup\$ Commented Dec 9, 2016 at 19:48

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.