1

If I connect a relay to Raspberry PI (Ground to Ground, VCC to 5v, and switch pin to one GPIO), when I write 1 on that pin, the relay switches on and off.

But, if I connect the relay Ground and VCC to USB power wires (5v), I can't control it from Raspberry GPIOs. An external switch, also connected to the USB wires, triggers switching in the relay.

Does anybody have an explanation for this behaviour ?

TLDR; power and control signals are working only if they have the same source (Raspberry or USB powered devices)

1
  • Please make sure your relay and your rPi have a common ground and try your test again - it should work
    – Phil B.
    Commented Apr 27, 2015 at 16:24

1 Answer 1

2

When you power the relay from the same source (either the rPi or a USB power source) the relay and the controlling GPIO pin share the same ground. Since voltages are relative to ground, this means that the 3.3V GPIO voltage is sure to be high enough to trip the relay.

When you connect the rPi to one power source, and the relay to another, and you DO NOT connect the grounds together, the 3.3V GPIO output from the rPI is relative to the rPi's ground, and that ground level can be totally different than the ground of the relay - in effect turning that 3.3V into an "undefined" voltage level, likely not high enough for the relay to work.

Once you connect a wire between the GND pins on your rPi and the GND pins on your relay, the same ground voltage holds for both devices and the relay should see the correct 3.3V GPIO voltage again, and work correctly.

1
  • You are right. When I connect the power related USB to the Raspberry PI USB hub, the relay is working. So it's true that a common ground is required. Thank you.
    – nucandrei
    Commented Apr 27, 2015 at 16:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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