I am working on a project automating my garage door.
The machine that operates the door provides a 24v out that is only on when the door is open (flashes while the door is moving then stays on for as long as the door stays open)
I intend to use that 24v power to let my Pi know whether the door is open or not.
I bought a step-down chip to get from 24v-> 3.3 (or 3v?) in order to intercept the signal with the pi.
This is the chip:Stepdown Chip

I need some help on how to actually connect the 3v output to my GPIOs.
With my limited knowledge, i suppose ill need to short my PI GPIO to PI GND with a resistor to act as a pull down.
Then the stepdown's + to the pi's GPIO and the stepdown's - to the pi's GND?
Do i have it figured out correctly or am i going the wrong way?
Will a 10kΩ resistor be enough?

Thanks in advance.

  • \$\begingroup\$ You will have to add the part-number of the chip you are referring to, for someone to help. Personally I would have used an opto-coupler \$\endgroup\$
    – sstobbe
    Commented May 28, 2017 at 10:45
  • \$\begingroup\$ I will attach a picture of the chip in my main question but i dont see what difference it makes. The sum up of my question is how to detect when a 3v output is on or off with raspberry pi, i need some help to figure the connections i must make. \$\endgroup\$
    – krasatos
    Commented May 28, 2017 at 11:00
  • 1
    \$\begingroup\$ The reason I asked is, a chip (Integrated-Circuit) has many input/output requirements to satisfy for voltage range, timing, load capacitors, minimum load, etc. You have purchased a complete module which has hopefully satisfied all requirements of the LM2596 \$\endgroup\$
    – sstobbe
    Commented May 28, 2017 at 11:26

2 Answers 2


You do not need to go through this much trouble. This is doable with dirt cheap components at a fraction of price. You can use this opto-isolated circuit: Opto isolated ckt

Consider these changes in the above image:

1) 12 V is actually 24 V in your case.

2) Left GND attached to PC817 is the GND of 24 V signal. Right side GND is not connected to Left side GND. Right side GND is GND of raspberry pi. VCC is 3.3 V which comes from raspberry pi.

3) ARD_GPIO will be a gpio of pi in your case.

Working of circuit:

When door opens and you receive that 24 V signal, the optocoupler will turn ON and you will get a HIGH on your GPIO.

Once the door closes, 24 V will be cut off and you will get a LOW on your GPIO.

RC network of 390K and 0.1uF is used to smooth out the signal. You will have to modify these values to suit your requirements. A minimum of 10K resistor is advisable. You can remove the capacitor altogether. Once you remove it, it will give you a pulsating output when door is opening and will give you a solid HIGH when the door has opened. Solid LOW if door is closed.

This also keeps your pi isolated from 24 V line which is usually a good thing to do.

  • \$\begingroup\$ An RC low-pass filter would have the resistor in series. \$\endgroup\$
    – CL.
    Commented May 28, 2017 at 14:53
  • \$\begingroup\$ @CL - It's not exactly an RC low-pass filter in my opinion. What it does is that as soon as opto-coupler gets activated, GPIO gets to see an instant logic HIGH. Once the opto-coupler turns off, the capacitor C2 will discharge through R6 slowly (it takes around 200 ms for the logic level to change if I recall correctly). However this feature might not be desirable for the OP. \$\endgroup\$ Commented May 29, 2017 at 3:28
  • \$\begingroup\$ Thank you for this solution and for the very detailed and starter-friendly description. I will go with this solution and report back! \$\endgroup\$
    – krasatos
    Commented May 29, 2017 at 12:32
  • \$\begingroup\$ Quick follow-up question: what is the minimum current that the PC817 requires to be triggered? \$\endgroup\$
    – krasatos
    Commented May 29, 2017 at 12:38
  • \$\begingroup\$ Sorry, I forgot to address that in my answer. I think 5 mA should work fine. I'm on mobile so couldn't check datasheet. That gives us a value of 4.7 kilo ohms resistor in place of 10k. But I suggest that you look at datasheet once. I'll update once I am on my pc. \$\endgroup\$ Commented May 29, 2017 at 18:05

You've actually bought a power supply. Not only is this intended to convert 100's mA or amps from 24 V to 3.3 V, it will also keep doing so when the 24 V falls right down to low voltages, certainly 10 V or lower.

You're looking to convert a signal voltage down, not a power voltage down. The difference is the amount of current you need from your converted supply. In your case, it's microamps.

What you do want to do, though is load your 24 V signal enough so you're sure it's a good 24 V and not something stray, radiated or otherwise inadvertent. This is to prevent false triggering off incorrect signals. You also want to make sure your conversion circuit only indicates 'on' when it gets a true 24 V signal and doesn't do so with a 6 V input. This is to draw attention to faulty wiring or breaking equipment. It's not that these are essential here but signal conditioning is an important part of designing detection circuitry and should be always be observed.

A non-isolated detector circuit will share a signalling ground between the voltage being sensed and your Raspbery Pi. This uses the minimum base-emitter voltage of a BJT as a crude comparator.


simulate this circuit – Schematic created using CircuitLab

With a 20.1 V detection voltage, the potential divider will draw 5 mA and deliver 0.6 V to the base of Q1, enough to turn it on (see datasheet). Below that sort of level, the transistor will stay off. When the voltage is above that-or-so, the base-emitter diode effect in Q1 will affect the potential divider as current will be diverted down the base. This is fine as Q1 can easily handle this current. D1 protects Q1 against accidental reverse voltages, be they transients or a moment of bad wiring.

Note that 20.1 V wasn't a voltage I was looking for - it was just around the 80 % mark and made for easy resistor values.

A isolated detector circuit will not share any electrical connections between the voltage being sensed and your Raspbery Pi. This uses the minimum diode drop of an opto-isolator as a crude comparator, in a similar way to the first circuit.


simulate this circuit

With a 17.7 V detection voltage, the potential divider will draw 5 mA and deliver 1.2 V to the Infra-Red LED (IRLED) of the opto-isolator, enough to turn it on (see datasheet). Below that sort of level, the IRLED will stay off. When the voltage is above that-or-so, the IRLED will start to draw current and reach the 1 mA necessary to turn its output logic-level buffer on. This buffer also contains a Schmitt trigger. D1 again protects the opto-isolator from accidental reverse voltages, as IRLEDs are quite fragile to reverse voltages.


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.