What hardware do I need to power an external target. Preferably something that can be connected to USB.

I have a simple case where I want to turn on a device if someone has the right rfid-chip at my raspberry and turn it off, when there is none.

The hardware device now would need to create and transfer 230V electricity over some cord or wire to an external thing.

2 Answers 2


I'm not aware of any USB solutions, but a simple relay circuit connected to a GPIO pin should fulfill your needs.

Here's a mechanical relay circuit from this site. The main point here is not to draw too much current from the Pi, so what you should do instead is connect the GPIO pin to a MOSFET/Transistor. Switching a MOSFET on draws very little current. Once it's on, it will let more current through that will, in turn, turn on a relay.

It should be simple enough to follow: enter image description here

Don't forget to add the flyback diode D1 else your MOSFET/transistor will burst into flames burn out.

  • 1
    To make this a little less intimidating to those new to electronics, you need essentially two components: 1) A relay to control the high voltage, perhaps preferably one using an opto-isolator if this this is 240 V AC. These are cheap and plentiful. 2) Something to control the (higher amperage) signal from a 5V pin on the pi, so you can use that to control the relay. You can get ICs (integrated circuits, in DIP form those little black things with metal legs) that contain the necessary transistors and diodes; e.g. from the ULN family -- very cheap.
    – goldilocks
    Jun 20, 2016 at 11:31
  • Thanks to both of you. Sadly I have no idea what you are talking about, since I know next to nothing about electronics. Thats why I asked for a simple usb-solution where I can use my programming background.
    – Jackels
    Jun 22, 2016 at 12:11
  • 1
    You can get relays with a converter build in. Just check to make sure it is clearly stated they can be controlled with 3.3V, and work with 240V AC. They usually have a ULN chip visible (they are about a cm or so long, again, black thing with a row of aluminum legs on each side). Then you can just connect straight to the relay (may require four connections, 5V power, 3.3V power, ground, 3.3V control).
    – goldilocks
    Jun 22, 2016 at 13:47

Less technical answer (i.e. step-by-step): I prefer to teach people about MOSFETs since they just need a voltage. No need for complex resistor calculations (e.g. transistor).

Primary step: get another power supply just for the relay. Connect the ground of your Pi and the ground of the power supply together.

WARNING: Refer to your datasheets when choosing the correct voltages. In this answer, I'm using an NPN (N-channel) MOSFET connected as a low-side switch. Assume power supply is 5V. Make sure your MOSFET is rated above your power supply's voltage for safety (i.e. don't get a 5V MOSFET if your power supply is 5V).

Assume I'm using a logic-level MOSFET for simplicity sake. You can also get a logic-level MOSFET for simplicity.

Assume my mechanical relay will switch at 5V.

enter image description here


  1. Attach a 1k resistor to the gate pin. Then, attach the other side of the resistor to the GPIO pin of your choice.

  2. Connect the source to ground.

enter image description here


  1. Connect the drain pin of the MOSFET to either pin A or pin B (i.e. either pin of the coil pins) of the relay.

  2. Attach the other coil pin to your external power supply's positive rail/connector/pin/whatever.

  3. Attach the marked (usually with a white/black band) part of your diode to the coil pin that's connected to positive. Attach the other end to the other coil pin.


                               +---------------------+           +-------------+
+-------------+                |               NO pin+-----------+Wire end B   |
|Wire end A   +----------------+COM pin              |           +-------------+
+-------------+                |                     |
                               |                     |           +-------------+
                               |Coil     Coil  NC pin+-----------+Wire end B   |
                               ++---------+----------+           +-------------+
                                |         |
                                |  Diode  |
                     PositiVe   |         |
 +------------------+-----------+      Drain pin
 |                  |                 +--------+
 |POWER SUPPLY      |        +--------+ MOSFET |
 |                  |        |   Source--------+Gate pin
 +------------------+--------+     Pin         |
                     Negative|                 S 1K resistor
                             |                 |
                             |             +---+------------+
                             |             |   GPIO pin     |
                             |             |                |
                             +-----------> |Ground Pin      |
                                              Raspberry Pi

Your Pi is now ready to power external devices. Just connect one end of a connection (Wire end A on the diagram) and attach the other end (wire end B) to either the NO or NC pin.

  • The NO (Normally open) pin is high when the GPIO pin is high.
  • The NC (Normally close) pin is low when the GPIO pin is high.

|                                                      |
|   +---------+       +---------+      +-----------+   |
|   |         |       |         |      |           |   |
+---+ Battery +-------+  Relay  +------+ Lightbulb +---+
    +---------+       +---------+      +-----------+
                Wire end        Wire end
                    A               B

Image sources: MOSFET | Relay

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.