We were unable to load Disqus. If you are a moderator please see our troubleshooting guide.

Nir Geller • 9 years ago

soo even if we connect to batteries we still need to connect the rasberry pi to another power source? and can we achieve the same connections without a breadboard? because want to build like a little car with 2 motors and a rasberry pi, but i dont think ill be able to put a bread board on the car...
sorry for the stupid questions i am really new to this

David • 8 years ago

It's so late, but i have to warn about something. It's a better practice have two power supplies for pi and motors. The current draw of motors are huge, and that could exhaust your batteries. And if you are using 4xAA batteries, they will give less than 5v (4.8). When batteries discharge, voltage will be even less, wich will cause malfunction on pi.

This is solved with two different power supplies or using a buck converter to have an stable 5v input no matter the batteries charge.

MatsB • 9 years ago

Yes, as long as you run the raspberry and the motors on 5 Volts.

Tyler Fraser • 9 years ago

your enable is wrong for motor 2 you have:
Motor2A = 23
Motor2B = 21
Motor2E = 19
it should be
Motor2A = 19
Motor2B = 21
Motor2E = 23

this solves the only one motor going reverse when both should be.

refer to this image http://cdn.instructables.co...

Pratham Kh • 6 years ago

Thank you very much for the suggestion.

Mårten Thurén • 6 years ago

Spent hours plugging cables in and out, rewriting code and came to the same conclusion, should have read the comments :)

H. Dean Roberts • 7 years ago

Thanks so much! I'm not sure if I'm more frustrated at myself for not reading the comments sooner, or at Tuts+ and/or Jason Barnett for not fixing this in three years. I'm not even going to admit how long I spent troubleshooting this before I looked down here.

eliyahu desmond • 7 years ago

thanks! had this problem....

Ewan Gallacher • 8 years ago

Thanks

Dominic Benstead • 8 years ago

I'm using a DC brushless motor, with ESC. Aiming to control the motor in the same way you would a servomotor. Can I still use this chip etc?

Dev Synopass • 8 years ago

Thanks a lot for the great tutorial, I followed it and successfully build my first Pi car with four wheels. Thanks!

Corriibme • 9 years ago

RPi.GPIO.SetupException: No access to /dev/mem.

Mike Skovgaard • 9 years ago

GPIO access is a priviledged operation. So you need to run your script with sudo. I.e.: sudo python motorback.py

batmobil • 9 years ago

This is the kind of critical info you really need to add in a basic tutorial.

Arturs Lataks • 9 years ago

Can I use 3V rated FK-180SH-3240 motors?

Nick Demis • 6 years ago

Can i use an 24v motor and external power a batterry with 24v;

Aaron Mason • 6 years ago

According to the datasheet for the L293D chip, it can handle up to 36V, so you should be fine. IANAE, YMMV. EDIT: So long as you don't exceed a peak output current of 1.2A.

Mohammad Amaan • 3 years ago

When i use the h bridge the motor runs very slowly compared when i connect the motor directly to the power supply. I'm using a 9v external battery

atux atux • 3 years ago

Ok i got the wiring for two motors and the script. How do i move each motor, please? Which command do i have to type?

how to code python to make motor turn left and right sir?

Dhananjay Pundir • 5 years ago

In our project we are using raspberry pi 3 ,full control rc car, l293d motor driver and some sensors.
we control rc car motor with l293d and raspberry pi 3 i.e, by coding , but car is not moving when we put it on the ground but if we lift it up in the air then car motors are moving .
but if we control our rc car by remote it is moving fine on the ground and in the air when we lift it up.
Plzz help

JOE • 5 years ago

Hello, i am making a school project and i need to make one motor go backwards and one forward. I am using this code to make them move,

GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)

GPIO.output(Motor2A,GPIO.HIGH)
GPIO.output(Motor2B,GPIO.LOW)
GPIO.output(Motor2E,GPIO.HIGH)

When i do this code the motors are not moving, it's like they need to go to the same direction to move.
thanks in advance.

Bhabesh • 6 years ago

Hey can someone explain why this is happening? My wiring is correct and the enable too works (23,21,19 = 6,4,5), but I have to use the following code:
import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BCM)

Motor1A = 23
Motor1B = 24
Motor1E = 25

Motor2A = 6
Motor2B = 4
Motor2E = 5

GPIO.setup(12, GPIO.OUT)
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
GPIO.setup(Motor2A,GPIO.OUT)
GPIO.setup(Motor2B,GPIO.OUT)
GPIO.setup(Motor2E,GPIO.OUT)

print('forward')
GPIO.output(12, 1)
GPIO.output(Motor1A, 1)
GPIO.output(Motor1B, 0)
GPIO.output(Motor1E, 1)

GPIO.output(Motor2A, 1)
GPIO.output(Motor2B, 0)
GPIO.output(Motor2E, 1)

time.sleep(2)
GPIO.output(12, 0)
GPIO.output(Motor1E, 0)
GPIO.output(Motor2E, 0)
time.sleep(2)

print('backward')
GPIO.output(12, 1)
GPIO.output(Motor1A, 0)
GPIO.output(Motor1B, 1)
GPIO.output(Motor1E, 1)

GPIO.output(Motor2A, 1)
GPIO.output(Motor2B, 1)
GPIO.output(Motor2E, 0)

time.sleep(2)
GPIO.output(12, 0)
GPIO.output(Motor1E, 0)
GPIO.output(Motor2E, 1)
time.sleep(2)

GPIO.cleanup()

It works perfectly till the Forward and rest(first), but then it screws up.
Please, help!! I am using a Pi3

musiclover470 • 6 years ago

witch sd card did you exactly choose because i have a hard time choosing a right one that works on a PI and that is one off 64G

Marcelo • 5 years ago

I have been using a class 10 sd card, 32 GB from kingston, runs fine

Revanth Babu R • 6 years ago

I need to run a 12 volt DC motor is it possible to run it using the same circuit and connections by replacing the motor and batteries with the 12V ones' ??

Yanis Gomes-Zbairi • 6 years ago

Hello, isn't it dangerous to use the L293D without any MOSFET neither capacitor or diode ?

Andre Lehrbach • 6 years ago

Hi! I need to handle 5 DC motors with raspberry, just in one direction. Is it possible with L293D?

Stephen Tenniswood • 6 years ago

Nice discussion. Check-out www.beyond-kinetics.com/dri... for a USB connection to the RPI.

Paul Griffin • 6 years ago

Jason, many thanks for a fantastic tutorial. Worked perfectly.

Indronil Mondal • 6 years ago

Sir am confused about the common ground .after connecting everything are we using the batteries to power up the pi or we use the external power adapter

Eduardo Herrera • 6 years ago

this not worked for me i'm looking for this

Neha Girme • 7 years ago

hello i am trying to interface four 12V dc motors with raspberry Pi. Pls can anyone guide me on this? Thanks

Anonymous • 7 years ago

When I run the program, only one wheel turn, but neither of the motors go into reverse. I tried with the code from Tyler Fraser that has
Motor2A = 23
Motor2B = 21
Motor2E = 19
it should be
Motor2A = 19
Motor2B = 21
Motor2E = 23

What do I need to do?

PresidentPorpoise • 7 years ago

Is there any way to connect a 3rd motor?

Thushal Kulatilake • 7 years ago

Bro. Could you pls tell me how to code python to steer front wheels of an rc car??

Tks

Jack McCartney • 7 years ago

What Python version is this written in?

Ranjeet Singh • 7 years ago

its python 2 .Look at the print statements ,its doesn't have parenthesis ("()") around the to be printed message

James Vickery • 7 years ago

After reading this tutorial I decided to write a Python library to automate all of the GPIO stuff for the L293D chip. Feel free to use it, or even improve some of my code! - https://github.com/jamesevi...

rxistd • 7 years ago

would this work the same way with 12V battery and motor?

Rekinek • 7 years ago

Hi. Can you control speed of the motor? Need to know for my slider project. Can you tell me witch is the best motor to use with it. I want to buy the Raspberry Pi Zero + MotoZero. Thx.

Ranjeet Singh • 7 years ago

yes,you can control the speed of motor using pulse width modulation concept (PWM).Need an idea? well,check out the link :https://www.coursera.org/le...

Hans Hernandez • 7 years ago

Thank you Jason for this marvelous tutorial that I am working on with my 10 year old daugther. We shared evil laughs out loud followed by "its alive!!!" Thank you to Tyler for the post about how to get both motors to spin forwards and backwards...

Shane • 8 years ago

I'm trying to do the 2 motor version using a motor and an actuator. I have hooked it up properly and have tried having the actuator at point 2 and the motor at point 2 but when I run the program whatever is in point 2 doesn't work. Does anyone know why this is, I have double checked my wiring and it is right and I have even tried increasing the voltage to the breadboard.

Eli • 7 years ago

This is really late, but the fix is;
Motor2A = 19
Motor2B = 21
Motor2E = 23
What's happening is you're Motor2E as Motor2A (Authors mistake)

http://cdn.instructables.co...

Dark Star • 8 years ago

The motors work even with the batteries disconnected (I used a 4 batteries module with switch and I forgot to turn it on). Did I made something wrong?

Dark Star • 8 years ago

I forgot to mention that I'm using an external power source for raspberry pi

Eli • 7 years ago

You're running your Motors through your Pi's power. This is bad

Dark Star • 7 years ago

Luckly nothing bad happened with Pi, apparently ...
Now my wiring is correct and my robot is doing fine ... thank you!

TJ McKinney • 8 years ago

please message me about this! i need to go from raspberry pi b+ to sabertooth 2x25 using r/c signal inputs into sabertooth. i'm guessing the microcontroller pwm differential mode for a tank drive?