I have one of these single-relay boards and I am trying to control it with my RasPi's GPIO. (I'm a complete noob).

I am using WiringPi and in this particular case I'm using pin 1 (aka BCM pin 18) as the control pin. From the relay board, I have the + pin wired to the RasPi's 5v, the - pin to RasPi's ground and the S pin to the control pin.

As soon as I connect the wires, the relay clicks and its led turns on. If I run a program that turns it on and off every 3 seconds, the relay's led turns on and off, but the relay stays connected (it doesn't click either). If I disconnect the control pin or gound then it clicks and turns off.

What am I doing wrong? Do I have to ground something else? I thought that by sending a LOW signal to the control pin, I was effectively sending it 0v, which should turn off the relay, but that doesn't seem to be the case.

Closeups of the relay board: Back and Front


I've gotten it to work by using the 3.3v pin on the RasPi instead of the 5v. Could anyone explain why the 5v + GPIO pin on LOW doesn't go to 0v, but to 1.5? Will having my 5v relay connected to the 3.3v damage it?

  • \$\begingroup\$ Does the board have a datasheet? \$\endgroup\$ – Ignacio Vazquez-Abrams Sep 14 '12 at 1:58
  • \$\begingroup\$ Unfortunately not.. I ordered it from that website assuming it's a pretty standard thing. \$\endgroup\$ – 0x6A75616E Sep 14 '12 at 2:14
  • \$\begingroup\$ It isn't at all clear why the relay board has three connections on the input side, rather than just two. I can only see a diode and a capacitor on the top side. Does it also have a transistor of some sort? \$\endgroup\$ – Dave Tweed Sep 14 '12 at 2:18
  • \$\begingroup\$ This is the bottom of the board imgur.com/BNuHx is it not standard for it to have a +/- and signal pin? \$\endgroup\$ – 0x6A75616E Sep 14 '12 at 2:25
  • \$\begingroup\$ @juand: Regarding your update, the relay itself is clearly designed for 5V. It may seem to work on 3.3V, but it will be pulling in more weakly. It will be slower, and depending on what you're switching, reduced contact pressure may cause reliability issues. \$\endgroup\$ – Dave Tweed Sep 14 '12 at 14:03

Looking at the photographs of the relay board, it looks to me like the transistor is acting as a high-side switch for both the relay and the LED, since one of the transistor leads goes directly to "+" and one of the relay coil pins goes directly to "-" (the ground plane). Therefore, the transistor would either be a PNP BJT or a P-channel FET. I'm betting on the PNP.

This would mean that you need to ground the "S" pin to activate the relay, and you need to open-circuit the pin, allowing it to float all the way to 5V, to deactivate it. Simply driving it to 3.3V will still keep the transistor activated. Although, I admit, this doesn't explain the changes in the LED, unless the voltage across the relay coil is changing enough to cause the LED to dim without allowing the relay to drop out.

In other words, the relay board is designed to behave much the way a bare relay coil would work (with low-side switching), but without requiring whatever's driving it to sink the full current of the relay. This makes a certain amount of sense.

  • \$\begingroup\$ This would make some sense - it looks like the LED is wired across the + and - pins, so maybe it's just a power indicator rather than for relay on/off (but in which case why does it dim? on switching?) \$\endgroup\$ – Oli Glaser Sep 14 '12 at 4:45
  • \$\begingroup\$ No, I think the LED (on the top) and its series resistor (on the bottom) are wired in parallel with the relay coil. \$\endgroup\$ – Dave Tweed Sep 14 '12 at 10:48
  • \$\begingroup\$ Do you mean the component (which does look like an LED, the die is visible on zooming in) on the top and at the top left? If so this definitely makes sense (I hadn't paid it much attention till now) I have been looking the component just above the mounting hole at the bottom right. Zooming in this looks more like a capacitor. +1 for getting it right (by the looks of things) while I'm here... \$\endgroup\$ – Oli Glaser Sep 14 '12 at 13:03
  • \$\begingroup\$ Im sure it's somewhere along those lines, I just couldn't figure out any combination of connections involving 5v that would work. If I have the + at 3.3v it works, but if I move it to 5v it doesn't. The difference is that a LOW on the pin, in combination with 5v gives me 1.5v, while in combination with 3.3v it gives me 0; thus releasing the relay (and its LED). How would I go about grounding/open-circuiting the pin with 5v? \$\endgroup\$ – 0x6A75616E Sep 14 '12 at 15:29
  • \$\begingroup\$ I can't explain these voltage readings in the context of my hypothesis. Do you have the negative probe of the voltmeter on the "-" pin and the positive probe on the "S" pin? \$\endgroup\$ – Dave Tweed Sep 14 '12 at 15:35

Okay, guess 3 :-)

Let's go with the assumption that you got the wiring right the first time (sorry, wasn't thinking straight ;-) )

If this is the case, then we probably have + going to emitter of PNP transistor, - to ground, and the S pin goes to the base of the transistor. Looking more closely at the pictures I think Dave is right about it being a PNP transistor since one side of the coil appears to connect to - pin (rather than + pin if it was an NPN)

You say that on plugging everything in the relay clicks and the LED turns on. On toggling the GPIO pin the LED turns off (does it turn fully off?) but the relay doesn't.
The fact you can remove the S control connection and the relay does switch seems to indicate that the 1.5V you have measured at the GPIO pin is the problem (is this measured when it is not connected to anything?) Figuring out why this is happening is the next step, though you could try another GPIO in the meantime.

EDIT - I just checked the Rpi schematics and it looks like all the GPIOs are 3.3V (I thought they mostly were, but I assumed there were some special purpose 5V ones on there too, though I can;t see any at a glance)
In this case, you should not be reading 5V on your GPIO unless there is smoething wired incorrectly.

It's possible the reason the LED turns off is due to the fact that it is wired directly across the S pin and - pin, and raising the voltage to 3.3V is enough to turn the LED off, since LED forward voltage is higher than (5V - 3.3V = 1.2V) However the driver transistor only needs >0.7V to turn on so unless the voltage rise to above V+ - 0.7V the relay remains on.

  • \$\begingroup\$ That's what I saw, but when I plug it in + to 5v and - to GPIO not even the led on the relay board turns on. The S could also stand for "signal", but so far I can't find any sensible way to drive this thing. \$\endgroup\$ – 0x6A75616E Sep 14 '12 at 2:40
  • \$\begingroup\$ The question is, what's the difference between unplugging the cable that goes from S to GPIO vs sending it 0v? Shouldn't it have the same effect? \$\endgroup\$ – 0x6A75616E Sep 14 '12 at 2:41
  • \$\begingroup\$ Just looking at the pic you posted now, didn't see it before, will edit shortly... \$\endgroup\$ – Oli Glaser Sep 14 '12 at 2:48
  • \$\begingroup\$ Here are closeups i.imgur.com/zGyTC.jpg and i.imgur.com/pb2E8.jpg \$\endgroup\$ – 0x6A75616E Sep 14 '12 at 2:53
  • \$\begingroup\$ Thanks, I'm pretty certain that the + pin goes to the base of the transistor. Try the edited answer and see how it goes. \$\endgroup\$ – Oli Glaser Sep 14 '12 at 2:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.