# Is there a way to control the power output from raspberry pi3?

I'm new to electronics and I'm thinking of building a small racing car. I have this toy car that has a DC motor and a servo motor to control the direction of the car. My plan is to write some software to drive the car around from my phone. So far I can use pin4/6 to supply power to the dc motor. This would be sort of an uninterrupted power supply since I can cut off power only if I turn off the power to the Pi or by just pulling the power off to the motor. I wonder if I could control the power supply using a soft switch, for example to stop the power supply to the DC motor? I'm not sure if it's entirely possible though! Any thoughts would be appreciated.

For switching you could use a relatively high power Darlington transistor such as a TIP120.

Since inside that is actually a pair of bipolar junction transistors, there will be a 1.2V voltage drop across it (0.6 * 2), so you should use it in series after the motor. You also want a flyback diode in parallel with the motor to prevent damage to the rest of the circuit when it is switched off.

simulate this circuit – Schematic created using CircuitLab

The inductor (labelled "Motor") and the resistor after it (labelled "R1") both represent the motor; i.e., you don't want an actual resistor there. The values I took from here. Although I think the resistance is all that's significant to the circuit, the inductor is there to emphasize the purpose and need for the flyback diode, it is important that you read up on and understand that.

I've used a rectifier diode because they seem cheaper and easier to obtain with sufficient tolerance (that one is 3A); a more common recommendation is a Schottky diode.

Beware I've only tried this with small servos, but the logic is the same. I'm not sure if you can simulate the circuit above without a CircuitLab membership, but the motor is getting ~465 mA. This is really a product of it's resistance, so that value is a bit arbitrary. If it were only 5 ohms, that circuit could pull almost 1 amp.

The advantage of the Darlington (pair) transistor is its high current gain (that one is optimally 1000x) in relation to the base current (above, the 500 ohm resistor limits that to ~7 mA, which is within the 16 mA max recommended for a Pi GPIO). Another common recommendation here is a MOFSET, where the base current doesn't matter.

You should at least glance at all the linked articles here and do some more reading about motor control circuits.

It isn't possible to turn the 5v pins off, they're always going to sit at 5v. What you can do is use a GPIO pin to control a relay. Then you can turn any voltage you want on and off, using a totally power independent source on the other side of the relay if you like (e.g. 12V DC or even AC!).

Here's a great article that talks you through one of the ways to go about just that.

If that all looks a bit too complicated, you could buy yourself an Automation HAT or similar instead, which gives you several independently controllable relays.

@goldilocks' answer is excellent too of course, especially if you are happy that the 5V power line on your Pi provides all the power you need. There's a nice discussion of the relative merits of relays vs transistors here.