Automation pHAT


I am trying to use the pHAT with a door sensor to report the status of my garage door. I tested this locally by plugging one wire into the 5V pin and one wire into the input 1 terminal. When I did this, the input consistently read “1” when I shorted those two wires and “0” when I left them open. Now I have taken the Pi and pHat and connected the same pins to the longer wire that I plan to connect a magnetic door sensor to. However, even when the wires are open at the other end, it is sporadically reporting a “1” when I read input 1. I am just using the example that come with the HAT to test this.

I noticed that the input goes “on” at 3V and “off” at 1V. When I test this wire with w meter, it says there is consistently .33v on that wire. I am guessing this is just crosstalk of some sort. However, being below 1V, I wouldn’t expect this to cause this issue but I am guessing it is. Any suggestion on how to fix this?



Ideally your setup should involve a pull-up resistor to set a known state when the circuit is open, otherwise the capacitance of the longer wire, plus environmental noise, could result in the problem you mention.

Typically we’ll connect a button to an input, pull that signal line up to 5V with a weak ~10k resistor to generate a constant 5V signal, and then the button or sensor will short the circuit directly to ground rather than connecting it to 5V.


I am having trouble understanding how to connect this sensor based on your answer. Can you tell me specifically how to wire this sensor and the resistor to the pHAT? Thanks so much for the help.



This may help with the theoretical side of the wiring:

As for physically hooking them together, it depends what you have available. You can solder the pull-up resistor and signal line to your input pin, then hook the other end of the pull-up to 5V.