Controlling Sparkfun Beefcake Relay with Explorer Hat Pro


I’m trying to switch a Beefcake relay via the output pins of the ExplorerHat Pro (EHP).

I’m thus far having no success. I connected the 0v and 5v to the relevant pins on the EHP, the CTRL pin to output one and tried the following Python command:-

but this doesn’t do anything. I then tried


but this hasn’t worked either…

I then disconnected the Beefcake and tried the following experiment found at:-

This lights the onboard red and green LEDs momentarily and should then light the RGB LED however but although the onboard LEDS are lit the RGB LED isn’t.

Have I blown the outputs with the Beefcake, or am I getting the syntax wrong?

Also, there’s some confusion with the output pin labelling of the EHP - are they 0 to 3 or 1 to 4?

Is there a simple way of testing the EHP outputs?



How to use Sparkfun Beefcake relay from Raspberry Pi

This is a common pitfall with the Explorer HAT outputs, and one we really need to write a learning portal article about! ( poke @sandyjmacdonald )

Explorer HAT uses a ULN2003A Darlington Array to drive the Outputs. It sounds fancy, but it’s nothing but a set of transistor pairs- one transistor connected to another- that when the first is turned on, switches the second and finally your load.

These pairs are based around NPN transistors, so- in very basic terms- they take a high input signal, and connect their output pin to ground.

Because of this, the outputs don’t actually supply any current, they just sink it- give it some place to go. Imagine them like a switch positioned between your load and ground. This means that, unassisted, they could never switch on a relay, because they’re just pulling its input pin to ground.

The same applies to turning on LEDs, since they don’t supply current, it’s like connecting a LED to ground on both sides.

Page 12 of the datasheet ( ) includes a full functional diagram if you want to understand the gooey innards.

In order to switch your Relay, you will need to invert the outputs again. This can be done trivially with a pull up resistor. A pull-up, if you have not encountered one, will weakly drive a signal to your supply voltage. In the case of a relay, you might need to experiment and select a pull-up that’s weak enough (IE: a low enough resistance) to drive the relay on. This is a balancing act, since it also has to be a high enough resistance to not simply short your circuit when you turn the output on.

I’d suggest starting at 10k Ohms. Connect up your relay as normal, then place a 10k Ohm resistor between each output that you’re using, and +5V. If all goes well, your relays will turn on.

To turn them off, you set - this will connect the line, driven high by the 10k resistor, to ground. This should close your relay.

If this works, you can now swap your use of the NO (Normally Open) or the NC (Normally Closed) with its opposite on your relays, to ensure your logic is inverted back to where you want it.


So, for the relay, I should connect the 0V and 5V terminals of the Beefcake to the 0V and 5V pins of the EHP and then connect the output pin to the CTRL terminal of the Beefcake but with a resistor between the EHP output pin and its 5V pin? When the EHP’s output is low, the relay’s coil will be energised and will close the NO contacts, but when the EHPs output goes high, it will de-energise the relay coil and the NO contacts will open…? I’ve tried this with a 1Kohm resistor and it works! :-)


Nailed it. Does it work with anything greater than 1Kohm? The higher you can get away with the better, since when the Darlington Array is on you’ll be throwing away 5mA across that resistor to ground.


Hi there, I originally tried 10k but the relay wouldn’t latch, the led on the beefcake could be switched by the pi but not the relay. I then swapped the resistor for a 1k and that worked. I’ve just tried two 1k in series and that wouldn’t latch either. So I think 1k is favourite.