Inverting 5V to GND for a relay
I’m working on a project right now where I want a 5v output from a Raspberry Pi to switch a rely controlling 120V AC. The relay I’m using is this one:
The problem is that it switches the relay when the line goes LOW (ie. ground). I’m using a HAT on my Pi that always sets a certain pin HIGH when activated. So I needed a way to turn 5V into GND.
I found a blog post with a schematic:
I breadboarded everything and it looked great. I didn’t want a breadboard in my final project though, so I wired everything up into a simple cable:
Here’s what’s going on there:
Add some heatshrink and it looks like:
So, the single wire coming out going to the relay activation pin (technically it sends GND so the wire could be black) and the other two go to the Pi’s GPIO pin and GND. Nice and clean!