0

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.

1 Answers1

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.

dpdt
  • 220
  • 2
  • 8