I am using the pi4j library to control the gpios on the raspberry pi B, but I ran in the following problem: when I start a pi4j example like ControlGpioExample.java then the led(with resistor 220 ohm) or DC motor on the breadboard don't react at all.

Trying to isolate the problem, I've made the following observations:

  • when I test the example with an small audio-buzzer curcuit on the breadboard then it works fine.
  • when I connect the led or DC-motor directly with power(3.3V on pin 1) and ground(pin 6) it works fine aswell.
  • I used wiringPi's command gpio readall to read the gpio state. When GPIO 1(pin12) is wired to a led or DC-motor I can't change its state to high with command gpio write 1 1. When I type gpio readall again it shows me that GPIO 1 is still on low(0), but with the audio-buzzer curcuit it works without problems.

I tested it on two different raspberry pi's, breadboards, libraries(pi4j and rpi.gpio), exchanged cables and reinstalled raspbian, the problem is still existing. Maybe I am missing something so I hope you can help me out.

  • Depending on the ratings of that motor it might be highly unwise to directly connect it to GPIO pins. Keep in mind that those pins only support a very limited current. I am also not sure what would be your intent when reading the state of pins that are outputs?
    – Ghanima
    Commented Apr 18, 2015 at 20:18
  • 1
    I'd stop experimenting before you damage your Pi. It is really not safe to power a motor from a Pi gpio without protective circuitry. The same applies to a relay or any inductive load. Perhaps if you post details of your proposed circuits you may get useful advice. You should be able to see the state of an attached LED.
    – joan
    Commented Apr 18, 2015 at 20:47
  • @Ghanima You can read gpios regardless of which mode they are (input, output, etc.). Normally, for example, if you write high you'll read back high, unless the external circuitry is driving the gpio low with a stronger force.
    – joan
    Commented Apr 18, 2015 at 20:50
  • @joan, cool, thx. Though I'd consider the load over riding an output pin a little flawed in design...
    – Ghanima
    Commented Apr 18, 2015 at 20:54
  • @Ghanima Yes, a bit extreme, but the point is that if you read a gpio you'll read its level, regardless of its mode.
    – joan
    Commented Apr 18, 2015 at 20:56

1 Answer 1


Do not attempt to drive heavy loads like a motor from the GPIOs. They can output a max of 18 mA (What is the maximum current the GPIO pins can output?) but the motor probably draws several hundred mA. In other words, you have virtually shorted your GPIO to ground and it cannot output high.

The way to drive motors is to use the GPIO to drive a transistor and then run the motor using an off-pi power source (the 5V rail works too). If you motor is too big for a transistor, you can do a two-stage setup with the GPIO driving a transistor, the transistor driving a relay, and the relay turning the motor on and off.

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.