this is my first time working with Pi and I'm trying to control a single motor (closely following this tutorial: https://www.youtube.com/watch?v=OV0S_3KMj2A).

Specs are:

  1. Raspberry Pi 3 Model B+
  2. 5V DC motor
  3. MX1508 Dual H Bridge motor driver

Problem is, as soon as I power-up the Pi, the motor turns on on its own. The only instance when it is under control is when I run my program to get it working (where I have defined start/stop instances). As soon as I KeyboardInterrupt the program, the motor starts running again.

  1. I've been recommended to use a pull-down resistor, but it did not work.
  2. I've tried with other GPIO pins, same result.

Wiring: wirings


import RPi.GPIO as GPIO


pwr = 80
GPIO.setup(2, GPIO.OUT)
motor = GPIO.PWM(2, pwr)

while True:
  • 1
    If you want help explain what YOU have tried and how it is connected. I would rather poke my eyes out than look at youtube.
    – Milliways
    Commented Apr 22 at 12:42
  • 1
    Post your code and a photo of your wiring.
    – CoderMike
    Commented Apr 22 at 13:07
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Apr 22 at 17:15
  • Did you try adding a short delay at the beginning of your code? If not, plz try this. If you think of using L293D instead, you can find relevant code and circuit diagram here: theengineeringprojects.com/2022/04/…
    – liaifat85
    Commented Apr 22 at 21:13
  • @CoderMike and all, kindly check the updated post for codes and wiring schematics. Thanks!
    – peacer
    Commented Apr 23 at 1:58

1 Answer 1


It is hardly surprising that the motor runs on boot.

GPIO2 has a 1.8kΩ pullup resistor intended for I²C so it will always be HIGH.

It is unclear what the unspecified device will do in this situation.

  • Many thanks, @Milliways. Your expertise was valuable to me.
    – peacer
    Commented Apr 23 at 10:15
  • @PrithulChaturvedi this might help forums.raspberrypi.com/viewtopic.php?t=167734
    – jsotola
    Commented Apr 24 at 3:31
  • Thanks, @jsotola! I changed my GPIO pin to a pin that was PWM compatible and it works fine now
    – peacer
    Commented Apr 25 at 2:19
  • @PrithulChaturvedi please post an answer describing what you did, so that other people can benefit from your knowledge
    – jsotola
    Commented Apr 25 at 2:21

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.