Invert input reading on Automation Hat


#1

Hello,

as found here https://learn.pimoroni.com/tutorial/sandyj/getting-started-with-automation-hat-and-phat

I have connected Automation Hat 5V to Input 1 and the reading is 1. Just fine.

I would like to reverse it, i.e. to get 0 when 5V is connected to Input 1 and vice versa.

How can I do that? Please advise.
Thanks,
dan


#2

Not meaning to a smart @ss, but one has to ask why? What are you coding in? And or wanting to do?


#3

I have to invert the reading of a opening sensor for Homebridge/Homekit.

sensor open -> gate closed
sensor closed -> gate open or opening.

How can I do that?


#4

Change your code to
sensor closed -> gate closed
sensor open -> gate open or opening.


#5

Better yet, please post your code. On my keyboard I have a key in the top left with a ~ and a under it. Three then your code and three more` will retain the syntax and indents.


#6

There is no code to post, I use Homebridge and HomeKit and I can not modify them.

I need to do this via hardware


#7

Ok, that explains that. I have to give that some thought?


#8

One of these may work, https://shop.pimoroni.com/products/optoisolator-1-channel
Or a 5V relay. You have the +5V turn the relay or opto isolator on and wire it so it sends a ground / short.


#9

You could use an NPN transistor and pull-up resistor to form a simple inverter circuit, in theory.

The accepted answer here explains it better than I could: https://electronics.stackexchange.com/questions/30238/how-to-invert-a-digital-signal