Recommended value for pull-down resistor on input?



I’m using a Keyence LR-W70 Full-Spectrum sensor as an input to an Automation pHat. I’ve currently got it connected to an ADC input because the “off” state of the sensor is over 3v and thus never goes “low” on a binary input. (I wrote a function that evaluates the incoming voltage and returns 0 or 1 to emulate a binary input)

I’d like to put it on a standard binary input and in the past I’ve used a pull-down resistor in this situation but I’m unsure what value to use. The impedance of the circuit isn’t published anywhere I could find.

Or is this the right way to go about it? (The reason I’d like to get it on a binary input is because I want to use the RPi.GPIO library to set up event detection on that sensor and I can’t do that with the ADC inputs)


You can configure a GPIO input to use an internal pull up or pull down resistor
GPIO.setup(5, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
I don’t know what the actual value of the resistor is though. In any case your going to want to insure that the input voltage never exceeds 3V or your going to damage the Pi’s GPIO input.

EDIT: Thinking about this, I do believe the pull down will only pull down if the input is floating, no voltage present? The static state is a 0 low.


Hello. Thank you for the response.

The advantage of a Pimoroni Automation pHat in my application is that it allows for 24v logic, making it compatible with industrial automation parts and pieces.

All three inputs and two outputs used in my application are 24v NPN logic. I’m not really interested in trying to convert all of it to 3v logic.

A pull-down resistor sinks a floating or small voltage to ground in order to reduce it to the threshold below which a digital input will activate. Since the pHat is “in the way” so to speak, that voltage is different. (The pHat sees anything under 3v as off)

EDIT: You raise a question, however… When using the GPIO library (instead of the Automationhat library) are the pHat’s buffering features enabled? I would think so, but it’s safer to know.


I misunderstood what you wanted to do. I thought you wanted to switch to going right into one of the Pi’s GPIO pins, bypassing the automation pHat.
Instead I see now you just want to switch from the ADC input to the buffered inputs. You said you wanted to use the RPi.GPIO “library”, but all my brain heard was PRPI GPIO. Sorry about that.

The pinout is here,
I see input 1, 2, and 3. Best guess is those are the buffered inputs. The ADC data I would think goes via i2c. You’d have to ask somebody from Pimoroni like Phil @gadgetoid for confirmation. Or maybe put a volt meter on one to see if it follows the pHat input.
If those are the buffered inputs going to the respective Pi GPIO inputs then using the GPIO library should be doable.


No worries… I should have been more clear with my question.

Yes, I need the pHat’s buffering features but need to use the GPIO’s interrupt functionality, which is not (as far as I can tell) supported in the Automationhat library. Am I wrong about that?

I’m headed out to the machine to measure the impedance of that input circuit now. A slightly higher value on a pull-down resistor should accomplish what I’m after… I’m used (in the PLC world) to those specifications being published and value selection is simple.


I had a quick look at the examples and didn’t see anything dealing with GPIO interrupt. Not the stuff I’m used to using. I guess it comes down to what the installer does to those GPIO, setup wise, and can you override it with some Python code?


Right… if I can’t get this to work, I may end up digging into the Automationhat library and overriding some of it’s methods to incorporate the GPIO interrupt features. I have to assume that at some level Automationhat is implementing the GPIO library… I’m not aware of another way to address the I/O at the board level.


Where your going is over my head and above my current skill level.
Please post back how it works out though. I may learn something. ;)


I measured the resistance of the input on the pHat at 70kΩ. Since the pull down resistor should be a higher impedance than the input circuit, I selected a 200kΩ resistor. (It was handy… 100kΩ would have been fine too)

One leg of the resistor shares the input #1 terminal with the output of my sensor and the other leg is connected to the ground terminal.

When the sensor is low I now measure about 0.5v at the terminal and when the sensor is high, I measure 23.8v. (Low state prior to this modification was around 6v)

That has the wiring sorted, now I just need to see about implementing the RPi GPIO library.


Cool, nice progress.


What exactly does this sensor do? I googled it and all I got was single or dual spot detection? I’m guessing some type of light sensor?


Yes, it’s meant for part or mark detection. I’m using it to detect a registration mark on paper as it passes over a roller. The mark acts as a trigger to the pHat which, in turn, triggers a camera.

This particular model is an evolution from the standard “density” sensor which is measuring light reflection. Since it’s an RGB LED light source and the receiver is a wide-spectrum receiver it can even do clever things like tell red from orange. (or any color from any other) In dual-spot mode it can even detect green next to red instead of red next to green.

It’s way overkill for my purposes but I needed to detect the registration mark from a distance and this seemed like the best choice. In other areas of the plant I detect the same mark with a simple red LED brightness sensor but those have to be nearly in contact with the paper in order to detect it with good reliability. That’s not an option in this case.


Thank you for the detailed explanation. I’m a retired electronic technician. I wasn’t exposed to anything even close to what your doing though. Ground based radio communications and navigation for civil aviation. Plus I’ve been out of the loop now for 20 some years.


Sure! Once I have the entire system up and running, I’ll do a post in the Projects section. I see a lot of home automation stuff but no industrial automation so this might be a nice variant on the theme. :)

Just as a side note, the pull-down resistor ended up being unstable as well. For some reason I haven’t identified yet, the output of this sensor is floating much higher than I would expect on a 200kΩ circuit (up to 3.5 v in one instance) so I just took the easy way out and isolated it with a solid state relay. The SSR input impedance is about 800kΩ and the trigger voltage is 6v so it’s quite a bit more stable.

Now at the pHat I’m getting a true 0v in a low state… probably should have gone this route to begin with. I prefer to separate my input circuits from my logic circuits anyway. This is safer.

As an added bonus, I’m able to detect the rising edge of that input with the RPi.GPIO config now. Super simple code change. I only have one weird thing to sort out and I think it might have to do with the SSR I’m using.


Your making good progress. I think your right about the mostly home automation projects being posted. I look forward to seeing it when its finally all sorted out.