I know I asked this question before, but this time I will give a more clearer description. I have been using the raspberry pi for approximately 6 months now. I am making a very simple robot car that includes a motor and ultrasonic sensor circuit. The ultrasonic sensor works perfectly but the motors aren't spinning with my circuit and programs. Please help:

Info and details: I am using a 9v battery, and l298n, 2 DC Motors and the raspberry pi and some wires for the motor circuit. You can see the circuit in the picture below made using the app fritzing: enter image description here

Then I programmed the circuit using the raspberry pi using python and the RPi.GPIO library / module. The code is below:

# importing all modules
import RPi.GPIO as GPIO
import time


# Setting up gpio pins for output
GPIO.setup(37, GPIO.OUT)
GPIO.setup(35, GPIO.OUT)
GPIO.setup(33, GPIO.OUT)
GPIO.setup(31, GPIO.OUT)

# Moving the car/ rotating the motor
# This part just moves the car front for 2 secs then back for 2 secs

GPIO.output(37, True)
GPIO.output(33, True)
GPIO.output(37, False)
GPIO.output(33, False)
GPIO.output(35, True)
GPIO.output(31, True)
GPIO.output(35, False)
GPIO.output(31, False)

# Cleaning up

There are no errors in the code when I run it (If there are in the code above, then that's probably true because I didn't copy and paste the code, I just wrote it here, so there might be a typo or something). The program just doesn't do anything. I ran it on idle in the raspberry pi. Please help, any good help will be useful thank you! Thank you as it means a lot!!

  • I have told you what is wrong with the code. I suggest you read my comment on your previous question.
    – joan
    Commented Apr 14, 2019 at 17:49
  • Please take the short Tour and visit the Help Center to get an idea how things work here.
    – Ingo
    Commented Apr 14, 2019 at 18:51
  • As I understood, You are setting one pin high and low to run and stop the motor. But what about second pin state? what is the default state? Always provide either pull-up or pull-down to the other pin. Ex: if pin no. 37 and 35 are controlling a single motor, then set one pin high and another pin low. And do the same with second motor. Do not put the pins in default of float state. You can also set the pull-up/pull-down while configuring the pins. Commented Mar 20, 2020 at 7:49

1 Answer 1


I know I asked this question before, but this time I will give a more clearer description.

I know I answered this question before, but this time I will give a more clearer description link.

Robot buggy - Assembling the motors and board - projects.raspberrypi.org

robot buggy

I have also assembled a 16450 power bank for my L298N robot buggy

power bank 16450

  • Yeah, I would have also tried to improve your last answer although I could see you put a lot of effort into answering my question! Thank you and your website gave a lot of information!
    – Hritik RC
    Commented Apr 16, 2019 at 19:44

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.