Electronic – Driving a single-relay board with Raspberry Pi

raspberry pirelay

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

Update:

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?

Best Answer

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.