6
\$\begingroup\$

On the RaspberryPi.SE it was suggested that one can use MOSFET BS170 to switch a USB device on and off by a GPIO pin (3.3V). I need to get 500mA to power a GSM dongle; the voltage drop should preferrably be minimal since USB is quite strict on voltage).

I'm not sure if I did the right thing. I cut the power wire of the USB cable, and connected the MOSFET to it in the following way:

schematic

simulate this circuit – Schematic created using CircuitLab

(I use a speaker in the schematic to represent my USB device, and a switch to represent a pin of the GPIO.)

The problem is that:

  1. I'm not sure that the two grounds are actually connected.
  2. According to a scheme on RPi's elinux page, I should have cut the GND wire instead of the PWR one.
  3. The official gate voltage is 3V and I supplied 3.3V to it.

I think I demaged the transistor I bought. I can buy a new one (even couple of them, they're really cheap), but I would prefer to know what to do before I experiment again or cut some more wires.

EDIT:

I did some more search, and I found a schematic by bretth on sparkfun.com, which seems to do what I want, using a P-MOSFET instead of N-MOSFET. Is this schematic angood way to go? It is a problem that GPIO provides 3.3V and maximal V_GS is 3V for N-FET and (minus) 2.4V for P-FET?

schematic

simulate this circuit

\$\endgroup\$
6
  • \$\begingroup\$ (I hope my question is not too poorly stated. I'm just an amateur experimenting, so please excuse my lack of knowledge.) \$\endgroup\$
    – yo'
    Commented Mar 21, 2014 at 0:08
  • \$\begingroup\$ Also remember that USB 1 and 2 (IIRC) only guarantee 500 mA after the peripheral device negotiates for it. \$\endgroup\$
    – The Photon
    Commented Mar 21, 2014 at 15:43
  • \$\begingroup\$ I have not used it or reviewed the data sheet in detail, but something like the Ritchtek RT9701 lists use as a USB power switch among its intended applications. Internally it is an N channel MOSFET with a circuit to translate the enable input above the supply voltage to allow such high side switching usage. I actually ordered mine after seeing them used to enable small RC servos (and never installed them) but you might find the data sheet interesting reading at least. \$\endgroup\$ Commented Mar 21, 2014 at 18:57
  • \$\begingroup\$ @thephoton the rpi does not have spec usb ports. straight to 5v input power, no power management. Not an issue. \$\endgroup\$
    – Passerby
    Commented Mar 22, 2014 at 0:19
  • \$\begingroup\$ N channel mosfets or npn transistors switch low side/ground. P channel or pnp switch high side. Just a fyi. And usb typically allows +- 0.25. \$\endgroup\$
    – Passerby
    Commented Mar 22, 2014 at 0:25

4 Answers 4

5
\$\begingroup\$

So I decided I'd give it a try, I bought AOP605, wired everything, and it works! :) So the following scheme is what can be used to control USB power using 3.3V input voltage:

schematic

When the GPIO pin is off, the USB DEVICE is off, switching the GPIO on switches on the USB DEVICE as well. I use 7.5k as R1 (I don't have 10k by hand) and it works well, too. Credit to betth and his post on sparkfun.com, I only changed the transistors to something more suitable for my case that I can buy here.

\$\endgroup\$
1
  • 3
    \$\begingroup\$ Congratulations on getting your circuit working (and on learning how to use P-channel MOSFETs nice and early in your electronics career). The one addition you might want to make to this circuit is a resistor between the GPIO output and M1's gate, say 100 ohms; this is to limit the current drawn from the GPIO pin by the gate capacitance when the GPIO changes state. You might also add a pulldown resistor (100k should be fine) from the GPIO end of this 100 ohm resistor to M1's source; this ensures the power is definitely turned off if the GPIO is disconnected. \$\endgroup\$
    – nekomatic
    Commented Dec 2, 2014 at 15:02
3
\$\begingroup\$

Alternatives: There are dedicated USB power switch ICs, for example Maxim 1562 and lots of others.

Or, you might consider a small reed relay. If you want to avoid the holding current, then you might choose a latching reed relay.

\$\endgroup\$
5
  • \$\begingroup\$ It seems that I'll simply have to drop the idea of doing electronics, whatever datasheet of whatever device I open, I have no idea how I would use it :( \$\endgroup\$
    – yo'
    Commented Mar 21, 2014 at 9:54
  • 3
    \$\begingroup\$ Don't be too discouraged. Official datasheets always contain lots of info that's either boilerplate, or for obscure corner cases, or otherwise not essential for you. The key is to learn what the core character of each component type is, and seek out the specs that describe that. Still not trivial, but far less daunting. For example, a typical transistor may have a 5 or 10 page data sheet, but there are only 2 or 3 numbers and maybe one or two graphs that tell most of what you want to know. \$\endgroup\$
    – gwideman
    Commented Mar 21, 2014 at 10:05
  • \$\begingroup\$ And that's the problem: I open the sheet, and from the mixture of numbers I might be able to see something. But obviously not everything needed: for example the voltage drop value at D-S in a transistor is a complete mystery for me. (If you were willing to come to the chat, I would be grateful for that and thank you a million times for your help :) ) \$\endgroup\$
    – yo'
    Commented Mar 21, 2014 at 10:10
  • \$\begingroup\$ @tohecz - Don't get hung up, no-one is born knowing it all. Start with the basics and don't try to run before you can walk (or if you do, don't beat yourself up if you fail). "Getting started in electronics" by Forrest M Mims III is a great book for a beginner, explaining stuff in basic terms with some good circuits to build & explore. \$\endgroup\$
    – John U
    Commented Mar 21, 2014 at 14:37
  • \$\begingroup\$ So I took your advice, wasn't discouraged, and made the thing working :) \$\endgroup\$
    – yo'
    Commented Mar 21, 2014 at 19:07
2
\$\begingroup\$

Following advice from Dave Tweed it is apparent that switching a USB load via the ground rail is not good so, what remains of this answer is all about choosing a mosfet and checking the appropriate graphs in the spec for the device. In short, look at the graph of drain current versus drain-source voltage and choose a device that has the lowest volt drop for the gate voltage you are able to provide. In this particular case it's appropriate to use a p channel mosfet switching the positive rail to the load and to do this requires an NPN BJT to interface between the gpio and the mosfet's gate.

You should have inserted the N channel mosfet in the ground wire to the load with source to ground and drain to the positive rail connected load. Also you need to put a resistor across the gate and source to leak away charge once the switch has open circuited. The gate-source pins are effectively a small capacitor with very little ability to drain away charge / voltage fed to them when the switch is closed. Try 10kohm or 100kohm.

EDIT NOTE - originally the question showed an IRF530 in the circuit

3.3V may be a little too lightweight for the the MOSFET you've shown in the diagram. The IRF530 is a 100V rated device and it has quite a high gate-source threshold voltage (2V min to 4V max). This means at 3.3V it may be only just starting to turn the MOSFET on fully: -

enter image description here

I've marked in red what the volt drop across the MOSFET is at a current of 1A flowing when the gate-source voltage is 4.5V - they don't specify any less than 4.5V so this is also a big clue that you should look for a device with much smaller Vgs(threshold). As you can see, with 1A flowing you are losing 1V across the MOSFET and this isn't what you should be aiming for. Clearly if you could supply a gate drive voltage of (say) 10V then at 1A drain current the volt drop will be about 100mV.

Try finding a device that shows the same graph with gate voltages down to 3V and look for no more than 100mV lost across the FET when 1A is flowing.

A BS170 FET is going to be worse if you want 1A: -

enter image description here

At 1A you'll need at least 6V to drop maybe 1.8V. Miles worse than the IRF530. However, if your load current was more like 100mA, a 3V gate-source voltage might only "lose" 0.5volts across the device.

\$\endgroup\$
9
  • \$\begingroup\$ Sorry, my bad (and lack of experience with the schematic editor). The transistor used is BS170. \$\endgroup\$
    – yo'
    Commented Mar 21, 2014 at 0:34
  • \$\begingroup\$ I've added that device too - it's worse !! How much current do you want to provide and how much volt drop can you suffer? That's the crux of things. \$\endgroup\$
    – Andy aka
    Commented Mar 21, 2014 at 0:37
  • \$\begingroup\$ The desired current is <500mA, I can't suffer much volt drop since USB devices are in general quite strict on voltage levels... \$\endgroup\$
    – yo'
    Commented Mar 21, 2014 at 0:42
  • \$\begingroup\$ Please, do you think there's some significantly better option how to cut a USB device using GPIO than by MOSFETs? \$\endgroup\$
    – yo'
    Commented Mar 21, 2014 at 0:45
  • \$\begingroup\$ Start looking for mosfets with a low drain voltage, probably 20volt and with low on resistance. Likely is it'll be a surface mount device from Fairchild or IR but I can't rule out others. TI are strong candidates two. \$\endgroup\$
    – Andy aka
    Commented Mar 21, 2014 at 0:47
1
\$\begingroup\$

First, you don't need the 10k resistor, I guess it was inherited from a diagram involving NPN+PNP transistors. Second, there's another option which is sometimes even simpler, consisting in using an LDO regulator with a shutdown input pin. That's what is used on the BusPirate board and a number of other ones. Such regulators are able to show almost no voltage drop between input and output and come in a 5-pin SOT23 package and are small and very convenient. Otherwise there are USB power switches which include the two transistors as well (and sometimes current limiting and possibly fuse emulation).

\$\endgroup\$

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.