Raspberry Pi – switching 5V

So last weekend I was playing around with a new relay board, hooked up to the Raspberry Pi, this time I used a board that came with optocouplers build in to prevent engergy buildup in the coils of the relays. Normally you would add a bunch of extra resistors between ground and the data pin but since I’m working a fairly small box and didn’t want to clutter it I decided to spend an extra buck and buy the built-in version.

The only problem is, the Raspberry PI GPIO outputs 3.3 volts instead of the 5v, with the old relay board it didn’t seem to matter but this one didn’t work. My basic electrical engineering knowledge told me to add a transistor, hook up the collector to the 5v, the base to the GPIO and the emitter to the replay board. Sadly, this didn’t work either… The emitter only gave me about 2.8v… even less than before… After digging through my “e-leftovers box” I found a bunch of shift registers, 74hc595n and 74hct595n. Somehow this does work!


As seen below, I’ve connected the Vcc of the shift register to the 5v – the diagonal yellow wire at the right bottom – and the inputs, the clocks and data to the 3.3v GPIO of the Raspberry directly. With a simple Python script based on the work of mignev/shiftpi it was up and running in a few minutes.


Raspberry Pi - 74hct595n