In other words, is it possible to solder on an LED or a fan or a motor (perhaps even a custom-made piece of hardware) and then write software that can send power from a battery to the added device?

For example, let's say I want to use a Raspberry Pi to light up a few LED lights that I have, in specific orders depending on what kinds of songs are being played on the Raspberry Pi. Does this device allow someone to hook up the LEDs somehow and then write code to handle diverting battery power to the lights in a specific order depending on whatever pattern is obtained from specific songs?

I'm looking for a fun personal project to undertake and I was wondering if something like this falls into the Raspberry Pi's capabilities. Thank you for your time.

4 Answers 4


Yes. One way to do that is if you created an external circuit using transistors, and hooked up the base pin of a transistor to the GPIO pins. That way you could have the Pi turn a pin on and off to turn that part of the external circuit on and off.

In other words, you want to create your own circuit/device, that you can control through the GPIO pins, and try not to have your external circuit share a power source with your pi

Here's an introduction to transistors


I would not recommend using the GPIO pins as a power source for things like motors, or directly hooking up power sources to the GPIO pins, as doing those things could deprive the Pi of power, or damage it. (LED lights are an exception I guess as they consume a tiny amount of power compared to motors)


Just for clarification on Alex's answer

For just a single LED, the RPi's GPIO pins would work fine. However, for a larger appliance such as a motor, you will need an external power source to give it the necessary power.

To incorporate an external power source, create a circuit with a transistor in it. Attach one of the GPIO pins to the transistor, and when power is applied to it, the circuit is completed, and the LED/motor turns on.

To control these elements, you can use the command line, or libraries are available for Python, C, and Scratch to make a script (which you would use in your example with the music).


  • Saying never solder anything directly to the Pi is over the top. It doesn't do any harm. It does make it slightly harder to re-purpose the Pi, but that is the owner's choice. If the Pi is operating in a vibrating environment soldering can make good sense.
    – joan
    Mar 7, 2015 at 8:56
  • @joan You can still use connectors even in a vibrating environment if you used poles to mount the board to the Pi. My MiniScreen board for B+ is pole mounted and survives being thrown around. Mar 7, 2015 at 23:52

Yes you can, I have done it.

I wrote it with a script that could be controlled with a web interface. I used Flask and Python to create a website where I was able to control a little motor that was connected with the GPIO. This was a school project for me, and it was very enjoyable! So yes, you can control LED light and a steppermotor.

Here is a script I used. You can even hook a LED sensor on the Pi that looks for a LED light so that when a light is detected the steppermotor of that particular Pi starts to go down or up. We have made an animation with several Pi's that way! Note that we used a very small steppermotor from China that costed about $2.

Edit: I did it with a driver board. Note that. Did not directly put it to the Pi, it'll destroy it. But it is possible to use the Pi with LEDs, steppermotors etc. That was the point I was trying to make.

  • NEVER connect a motor directly to the Pi's gpios. You will damage the gpios and/or the Pi. In your case the gpios were connected to a driver board which in turn was connected to a motor.
    – joan
    Mar 7, 2015 at 11:00
  • @joan that is true, forgot to mention that. I'll edit it in!
    – jrust
    Mar 7, 2015 at 12:21

Yes. My suggestion is to look into the myriad of attachments that can be purchased online to attach to the GPIO connections from the PI. There is a robotics package available that includes servos, stepper motors, led controls, etc. I've seen complete CNC mills that could easily have their own computers replaced by Raspberry Pi's producing an upgrade in functionality by connecting their motor controllers and sensors directly to the Pi GPIO connector. But note: users of the Raspberry Pi boards are generally up against power limits. You won't be able to draw much power from the Pi's power supply through the micro-usb power connector on the Raspberry Pi board to power a motor -- most uses like a motor must be self-powered and use only the control capability of the PI. One or two LED's lit at a time shouldn't be a problem in this regard.

  • Thank you. If I wanted to power a motor or a fan, would it be possible to add a battery of some kind to the PI board? For example, if I wanted to make a remote controlled car toy with the PI, a battery, and a motor of some kind to control the wheels. Would the PI be a poor choice for a pet project like this? Mar 11, 2015 at 20:06
  • Yes you can power the Pi with a battery. There are two connectors on the board of the Pi (TP1 and TP2) that can power it. Attach a battery to these. I believe it is also possible to power it by the GPIO ports, but I am not sure. Mar 19, 2015 at 7:40

Not the answer you're looking for? Browse other questions tagged or ask your own question.