new here and to Raspberry PI. I want to use it to be able to toggle a relay, but that relay is a 5v one, and I read that the GPIO pins are only 0-3.3V. Is there a pin that can provide ground when toggled? Can any of the +5V pins be turned on/off? I'm afraid if I use the 3.3V to activate a 5V relay, it may not provide a good enough contact and cause a fire. It's switching 110V AC.
-
2Does this answer your question? Can you use a 5V Relay Module with the Pi? – Milliways Mar 21 '24 at 21:39
-
You can not use a Pi to switch a relay because the GPIO pins only output logic levels with limited current (16mA max). You probably have one of those cheap relay modules which are also unusable without extra components. – Milliways Mar 21 '24 at 21:43
4 Answers
Although the processor can set an output to a 0V level, there are various reasons why your proposal won't work, and might damage the Pi:
- When the pin isn't being pulled down to ground, the pin will be pulled up to 5V via the relay, which is beyond the 3.3V limit for the I/O.
- The relay coil probably needs more current than the I/O pin can supply
- When the relay is switched off, the collapsing magnetic field of the coil generates a high kick-back voltage which will destroy the I/O pin, and probably the CPU.
So you can't drive the relay directly, you need a driver IC or transistor similar to that already suggested, with a diode across the coil to catch the kick-back. Do check that the transistor is rated to carry the relay current.
And now the inevitable warning: if you have low-voltage and 110V signals in close proximity, be very careful with your wiring, as a short-circuit can be dangerous; if in doubt, seek advice from a qualified electrician.

- 585
- 2
- 3
For more info, have a look at: https://elinux.org/RPi_GPIO_Interface_Circuits#Buttons_and_switches

- 511
- 1
- 3
- 12
-
-
Yes. Instead of grounding the relay via the GPio like you were thinking about doing, you ground it via the transistor. – papatrexas Mar 21 '24 at 21:03
new here and to Raspberry PI. I want to use it to be able to toggle a relay, but that relay is a 5v one, and I read that the GPIO pins are only 0-3.3V.
This is very true! You should not use a GPIO pin to switch a 5V device (esp a relay coil) ON & OFF.
Is there a pin that can provide ground when toggled? Can any of the +5V pins be turned on/off?
No. The "+5V pins" you're referring to are not "GPIO pins" at all. They are simply "header pins" that are connected to the RPi's +5V bus. This +5V bus is the regulated input voltage (Vin) that comes from the USB power connector. These +5V header pins are not switched at all - they are simply provided on the header for convenience; for example, if you needed +5V to power something on a "breadboard" adjacent to your RPi.
I'm afraid if I use the 3.3V to activate a 5V relay, it may not provide a good enough contact and cause a fire. It's switching 110V AC.
Not much worry of fire, but you will most likely damage your RPi by connecting the 3V3 bus (aka 3.3V) to +5V. The 3V3 bus is derived from the +5V Vin used to power the RPi.
All of that said, you actually can toggle your +5V relay using a GPIO pin! Just wire it up as follows:
simulate this circuit – Schematic created using CircuitLab
In this circuit, the NPN transistor (Q1) acts as a buffer to isolate the GPIO pin from the the +5V connection to the relay coil; IOW this is safe, and won't harm your GPIO/RPi. When the GPIO line is set to HIGH (3.3V), current will flow into the Base terminal of Q1, causing it to turn Q1 ON, and allowing current to flow through the relay coil - thus closing the relay contacts. The diode (D1) serves as a snubber to limit the L * di/dt
voltage generated when Q1 switches OFF the current through the relay coil. Let us know if you have other questions re the schematic.

- 21,900
- 3
- 33
- 70
-
A 100Ω base resistor will result in ~33mA base current. This is unnecessary and exceeds the maximum recommended GPIO current. – Milliways Mar 21 '24 at 23:24
-
-
-
Yes - it is V*b*e - my bad :) But the Vbe drop is not necessarily limited to 0.7 V (reference). Q1 should be operating in saturation region in this application. – Seamus Mar 23 '24 at 00:58
While those wirings with transistors will work, given how you ask I assume less of more universal parts might work better for you.
Look at integrated circuit ULN2803A
this has all the transistors, resistors and diodes inside and works rather fool-proof in a breadboard. You could even use it for more relays or higher loads with higher voltages - so fairly universal with an RPi.
simulate this circuit – Schematic created using CircuitLab

- 101
- 2