6

I have a simple circuit that runs on 5 volts. Let's just say for simplicity that it is a circuit with an LED that lights up when a push button is pressed. The problem is that it has a push button switch in it, but I need to control turning on and off the circuit from a Raspberry Pi GPIO pin instead of the push button.

How can I do this?

Edit: I guess the answer is a MOSFET.

Taylor
  • 131
  • 1
  • 3
  • 7

2 Answers2

8

Adding to the answer above, how to do this really depends on the load you want to switch.

Here's a post about how much current you can draw from the GPIO see here

A few cases:

1) You have only one LED, that's it, and 20mA or so will do. See here an internet article on how to do this with one resistorsee here

2) You have more than one LED, you want the LED to shine brighty or you have something else that can work with 5V but draws more than say 20 mA. Then use a transistor (BJT or FET) as below:

enter image description here

3) You want to switch a heavy DC load, or you want to switch an AC load, then the recommendation above with a relay is a good choice.

If you can be more precise what you want to switch, then just ask.

kxtronic
  • 281
  • 1
  • 4
2

Try this:

schematic

simulate this circuit – Schematic created using CircuitLab

Use either Option 1 or Option 2, depending on what parts you can find and what you're comfortable with. In either case, the Switch label on the transistor circuit connects to the Switch label on the relay circuit, so that the transistor is simply an amplifier to activate the relay. The functional difference is that the BJT needs a small continuous current to hold it on while the FET requires a spike in current to change state and then sits nicely without drawing anything. But since you're only going to blink it anyway, even that hardly matters.

Even though the FET doesn't draw any control current just sitting on, I'd keep R2 anyway to control the switching spike and avoid stressing the Pi's output driver. For either option, choose the resistance as if the transistor were a short-circuit.

Also don't forget D1. It limits the voltage spike when the relay turns off to a diode drop above +5V, so the transistor only has to handle that instead of theoretically infinite. (lower in practice, but easily 100V or more)

AaronD
  • 199
  • 1
  • 8