1. 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:

    image

    http://amzn.to/2ztmEKH

    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:

    image

    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:

    image

    Here’s what’s going on there:

    image

    Add some heatshrink and it looks like:

    image

    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!