1
\$\begingroup\$

I'm debugging a circuit on a home project and hoping for some advice.

I have a relay set up like so:

enter image description here

The behavior I'm seeing:

  • When I toggle the Raspberry Pi GPIO to HIGH, The relay will begin to thrash (turn on and off very quickly).
  • If I take the GPIO line and connect it directly to a 3.3V source from the RPi, the relay turns on cleanly. Disconnecting it from the source turns it off cleanly.
  • Changing the RPi GPIO pin, (or changing the entire RPi module) still exhibits the thrashing, so I don't believe its a bad GPIO pin.
  • I swapped the relay out for a g5le-1-asi dc3 (It is still set up to be driven by a 5V supply), thinking I was on the operating threshold. However the relay will still thrash when the 2N7000 is driven by a GPIO out.

From the datasheet, I understand the 2N7000 should have no problem being driven by the 3.3V RPi output. But Plugging it directly to a 3.3V source vs the 3.3V GPIO seems to suggest its an issue with the RPi's ability to deliver enough current through the GPIO output. Could this be correct?

What would be the recomended way to drive this relay?

Edit This is the full schematic. RTN is connected to the RPi GND and the RTN on the flyback transformer.

enter image description here

  • The RPi is powerd off of the J3 connection
  • I have also powered the RPi off of an independent power supply
  • The GPIO and RPi ground pins are connected to J4

Edit 2

Everything is laid out on a PCB board with this design:

enter image description here

\$\endgroup\$
12
  • 1
    \$\begingroup\$ Where is the RTN connected? To some supply? To Raspberry Pi? Also, I would not be entirely sure about 2N7000 being able to drive much load with only 3.3V on gate. \$\endgroup\$
    – Justme
    Commented Dec 15, 2023 at 0:20
  • \$\begingroup\$ Yeah good question. RTN is connected to the Raspberry pi GND. It is also connected to the return on a flyback transformer I built (will edit post with the full schematice) \$\endgroup\$
    – Ben
    Commented Dec 15, 2023 at 0:22
  • \$\begingroup\$ Are you sure the RTN wire is propely connected to RPi GND? Also, the transformer and capacitor C4 are important for safety. They must be specially rated for safety. \$\endgroup\$
    – Justme
    Commented Dec 15, 2023 at 0:34
  • \$\begingroup\$ 99% sure the RTN is properly connected to GND, but it's worth the extra check.. C4 is a CER 150PF 440VAC Y5T RADIAL. The tranformer is homemade, I used Magnet Wire and Triple insulated wire for the windings. However, I did not dip the transformer in varnish... It's tightly held togeather with 3M polyester film tape \$\endgroup\$
    – Ben
    Commented Dec 15, 2023 at 0:45
  • \$\begingroup\$ The C4 does not sound to be an appropriately rated capacitor with required safety class. Please do not use random capacitors where a proper safety class capacitor is required to prevent death by electrocution. \$\endgroup\$
    – Justme
    Commented Dec 15, 2023 at 0:49

1 Answer 1

4
\$\begingroup\$

Your first relay's coil current is 80 mA, which is the problem. The second relay's coil current is 133 mA, which is worse.

The GPIO pin output current capability is not the problem. It's the output voltage. Assuming the output is not a PWM signal . . .

A 2N7000 threshold voltage can be as high a 3 V. At this voltage the FET is rated to conduct only 1 mA. The uC GPIO pin's output voltage is less than 3.3 V, which is so low that it is not fully enhancing ("turning on") the FET. Thus, the FET is a significant resistance in series with the relay coil, not the minimum Rdson shown on the datasheet. The small voltage difference between the GPIO high output and a direct 3.3 V connection is enough to lower the FETs resistance just enough to stop the relay armature from chattering.

IOW, the FET is being starved.

The second relay has a lower operating voltage, but a higher operating current, so it still chatters.

The solution is to change to a bipolar NPN transistor as a saturated switch. Use a base resistor of less than 470 ohms. Go back to the original relay with the lower coil current.

UPDATE:

You want to drive the BJT into saturation. The rule of thumb for this is that the base current should be at least 10% of the desired collector current. For an 80 mA relay, that is 8 mA of base current. The voltage across the resistor is the GPIO pin high voltage under load, around 3 V, minus the Vbe of the transistor. Use Ohm's Law to calculate the resistance, and use the next highest standard value. Of course this works only if the pin can source 8 mA; not all output pins can.

That "rule" is from the 1950's, when transistors were ... worse. By the late 60's and the 70's, things were significantly better, especially for small signal transistors such as the 2N2222. If you don't want to suck that much current out of the GPIO pin, use a ratio of 15:1 or even 20:1. Even if this adds a few tenths of a volt to the transistor's saturation ("on") voltage, the relay still will have 4.5 V across a 5 V coil, and will snap on crisply.

\$\endgroup\$
5
  • 1
    \$\begingroup\$ There are other FETs that are suitable for this too, though. The AO3414 would work well here. \$\endgroup\$
    – Hearth
    Commented Dec 16, 2023 at 15:07
  • \$\begingroup\$ Thanks for the reply! I think I understand what you're saying. So fig 1 here: rocelec.widen.net/view/pdf/orqxwkxkq1/… for 3V VGS it the Fet can only sink ~ 50mA, is that correct? \$\endgroup\$
    – Ben
    Commented Dec 17, 2023 at 0:19
  • \$\begingroup\$ You have to take those plots with a wide bit of latitude, but I think figure 1 and figure 5 agree. Note that in figure 2, the part is characterized only down to a Vgs of 4 V, nowhere near 3.3 V or less. I and many others have used the 7000/7002 in 3.3 V circuits, but with the drain current pushing 100 mA, I'd look for a different ("logic-level") FET or switch to bipolar. The AO3414 should work better for you. \$\endgroup\$
    – AnalogKid
    Commented Dec 17, 2023 at 4:11
  • \$\begingroup\$ Gotcha, I'm sure the latitude for this plot is similar.. but am I right in understanding that for something like the p2n2222. And a base current would be 3.3V/470 ohms (your recommendation) = 7mA. Then fig 4 says a 5Vce would draw 150-500mA? onsemi.com/pdf/datasheet/p2n2222a-d.pdf which would be appropriate for the 80mA relay \$\endgroup\$
    – Ben
    Commented Dec 17, 2023 at 6:11
  • \$\begingroup\$ See the Update. \$\endgroup\$
    – AnalogKid
    Commented Dec 17, 2023 at 14:26

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.