User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Simple Motor with L293D Not Working (Solved!)

Sat Oct 21, 2017 11:04 pm

I'm following this tutorial: https://business.tutsplus.com/tutorials ... -cms-20051

I connected everything to my raspberry pi as per this Image: Image

I checked and double checked my wiring and it all appears to be correct. I ran the pin test application to ensure all my pins are functioning correctly and they are.

I attached 3 LEDs for debugging to the L293D chip's ENABLE pin, Motor 1 pin, and the Motor 2 pin Like so: Image

The ENABLE LED goes on when I run the python script but the other two LEDs do NOT. I checked the wiring and I tried different pins but I still cant get the motor to turn nor the two LEDs to turn on. Any advice or help?
Last edited by Katianie on Thu Oct 26, 2017 3:50 pm, edited 2 times in total.

drgeoff
Posts: 7448
Joined: Wed Jan 25, 2012 6:39 pm

Re: Simple 10v Motor with L293D Not Working

Sun Oct 22, 2017 9:09 am

Remove the LEDs or put 220 ohm resistors in series with them. If you do not you will have more serious problems.

pcmanbob
Posts: 2218
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Simple 10v Motor with L293D Not Working

Sun Oct 22, 2017 9:57 am

You should also post your code, and please use code tags.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple 10v Motor with L293D Not Working

Sun Oct 22, 2017 7:41 pm

Here is the code im using:

Code: Select all

import RPi.GPIO as GPIO
from time import sleep
 
GPIO.setmode(GPIO.BOARD)
 
Motor1A = 16
Motor1B = 18
Motor1E = 22
 
GPIO.setup(Motor1A,GPIO.OUT)
GPIO.setup(Motor1B,GPIO.OUT)
GPIO.setup(Motor1E,GPIO.OUT)
 
print "Going forwards"
GPIO.output(Motor1A,GPIO.HIGH)
GPIO.output(Motor1B,GPIO.LOW)
GPIO.output(Motor1E,GPIO.HIGH)
 
sleep(2)
 
print "Going backwards"
GPIO.output(Motor1A,GPIO.LOW)
GPIO.output(Motor1B,GPIO.HIGH)
GPIO.output(Motor1E,GPIO.HIGH)
 
sleep(2)
 
print "Now stop"
GPIO.output(Motor1E,GPIO.LOW)
 
GPIO.cleanup()
As for the resistors on LEDs. Do you think I already blew something because I didn't put resistors on the LEDs and that is my issue? I put the resistors between the LEDs and the LP293D chip just now but I still have the same issue.

pcmanbob
Posts: 2218
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Simple 10v Motor with L293D Not Working

Sun Oct 22, 2017 8:49 pm

Well if you disconnect the pi from the L293D and just connect resistors and LEDs to the gpio then run your program do you see the LEDs light up. ?
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

drgeoff
Posts: 7448
Joined: Wed Jan 25, 2012 6:39 pm

Re: Simple 10v Motor with L293D Not Working

Sun Oct 22, 2017 9:01 pm

Katianie wrote:
Sun Oct 22, 2017 7:41 pm
As for the resistors on LEDs. Do you think I already blew something because I didn't put resistors on the LEDs and that is my issue? I put the resistors between the LEDs and the LP293D chip just now but I still have the same issue.
You also need a resistor between the RPi GPIO and the LED. Without one you risk damaging the GPIO and eventually writing off the complete RPi.

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple 10v Motor with L293D Not Working

Mon Oct 23, 2017 4:13 pm

pcmanbob wrote:
Sun Oct 22, 2017 8:49 pm
Well if you disconnect the pi from the L293D and just connect resistors and LEDs to the gpio then run your program do you see the LEDs light up. ?
Removed the L293D Chip and kept everything else and yes the LEDs in fact all lit up at least once. It's sounding like a chip issue? but I have like 5 of them I tried this with and still the same result. Could all 5 of the L293D chips be defective? Perhaps its not a chip issue and just a red harring?

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple 10v Motor with L293D Not Working

Mon Oct 23, 2017 4:27 pm

drgeoff wrote:
Sun Oct 22, 2017 9:01 pm
Katianie wrote:
Sun Oct 22, 2017 7:41 pm
As for the resistors on LEDs. Do you think I already blew something because I didn't put resistors on the LEDs and that is my issue? I put the resistors between the LEDs and the LP293D chip just now but I still have the same issue.
You also need a resistor between the RPi GPIO and the LED. Without one you risk damaging the GPIO and eventually writing off the complete RPi.
I added the three resistors and this is the setup after: Image

But you are saying I need an additional one somewhere?

User avatar
Burngate
Posts: 5056
Joined: Thu Sep 29, 2011 4:34 pm
Location: Berkshire UK
Contact: Website

Re: Simple 10v Motor with L293D Not Working

Mon Oct 23, 2017 5:04 pm

That looks okay, except that, where you've placed the resistors - both legs on the same row as the LED anode - they're doing nothing.
oRVuV78b.jpg
oRVuV78b.jpg (31.63 KiB) Viewed 918 times
You need to put one resistor leg on the same row as the jumper-wire (and chip leg), the other resistor leg & LED anode on a different row.

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple 10v Motor with L293D Not Working

Tue Oct 24, 2017 12:57 am

I changed the resistors as you said, here is a pic:

Image

Still the same result after putting in a L293D different chip.

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 181
Joined: Fri Jan 06, 2012 7:46 pm

Re: Simple 10v Motor with L293D Not Working

Tue Oct 24, 2017 7:09 am

I would suggest that you remove the LEDs and resistors at this point as they are just confusing the issue.

Also, unless you really feel the need for manual control over the Enable pins, it is easier just to connect them straight to 5v to have them permanently enabled. Connect L293D pins 1, 9 & 16 together to 5v.

Do you need to use RPi.GPIO ? Have you looked at the gpiozero library, it makes things much simpler. Have a look at the resources pages, specifically https://projects.raspberrypi.org/en/pro ... -computing

Using gpiozero, your code would reduce down to:

from gpiozero import Motor
from time import sleep

motor1 = Motor(23, 24)

motor1.forward()
sleep(2)
motor1.backward()
sleep(2)
motor1.stop()

Hope that helps :-)

drgeoff
Posts: 7448
Joined: Wed Jan 25, 2012 6:39 pm

Re: Simple 10v Motor with L293D Not Working

Tue Oct 24, 2017 7:53 am

The latest photo appears to show three resistors doing nothing. They are not between a GPIO and a LED. One end of each resistor is not connected to anything.

pcmanbob
Posts: 2218
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Simple 10v Motor with L293D Not Working

Tue Oct 24, 2017 9:28 am

Hi Katianie

I guess you are having trouble understanding how a breadboard works so here is an example to show you how to connect your LED, resistor & chip.

Image

so we have our control wire connected to the same strip of holes as the required pin on the chip, to connect an LED to the same control wire we connect one side of the resistor to the same strip of holes and the other side we connect to a new strip of holes we also connect one leg of the LED to this same strip of hole while the other leg of the LED is connected to ground.

I would suggest you have a read of this web site on breadboard usage.
https://www.sciencebuddies.org/science- ... breadboard
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple 10v Motor with L293D Not Working

Tue Oct 24, 2017 4:21 pm

Thanks for the tip, I understand the LED part now.

I removed the LEDs as per suggestion for now to limit confusion. I am now using the code you provided as well which is much nicer to work with (thanks).

I tried to hook up a motor to it but still no luck, here is an updated screen shot (the two wires to the right go to the motor i have on a little platform):

Image

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 181
Joined: Fri Jan 06, 2012 7:46 pm

Re: Simple 10v Motor with L293D Not Working

Tue Oct 24, 2017 8:17 pm

Are you able to show details of your motor and power supply?

You say you have a 10V motor. What batteries are you using?

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple 10v Motor with L293D Not Working

Wed Oct 25, 2017 2:33 am

Here is the power supply (D Batteries):

Image

Here is the motor (I have a 4 wheel rover with 4 motors if we want to try that route too)

Image

Forris
Raspberry Pi Certified Educator
Raspberry Pi Certified Educator
Posts: 181
Joined: Fri Jan 06, 2012 7:46 pm

Re: Simple 10v Motor with L293D Not Working

Wed Oct 25, 2017 5:41 am

Ok, so you have a 6 volt power supply for the motor.

In your thread title, you say 10 volts. Where did that figure come from? The motor that you have looks like a cheap 3v -6v motor, which should be fine for your experiments.

I'm going to ask a really stupid question now, but have you tested the motor by connecting it directly to the batteries to check that both of those components are ok?

I've just noticed, after another look at your batteries, that your they are all the same way round. I can't make out how each of the batteries is connected to the next. Are they connected in series or parallel? The fact that they are all facing the same way would suggest that they are in parallel, because it looks like all their positive ends are connected to on wire and all their negatives to the other wire. If they were in series, I would expect them to face in alternate directions.

There's an excellent diagram here: https://electronics.howstuffworks.com/e ... ttery6.htm

If they are connected in parallel then you would only be getting 1.5v, which isn't enough to drive the L293D, which requires a voltage between 4.5v and 36v.

Hope this helps.

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple 10v Motor with L293D Not Working

Wed Oct 25, 2017 4:37 pm

(I apologize for the Noobie mistakes I'm making but alas, I am a Noob.)

Here is the kit the motor came with: https://www.sunfounder.com/rpi2-superv2.html . I thought I heard/read it was 10v but upon re-researching I couldn't find any reference to how much voltage the motor is. In the instruction manual it just says "DC Motor". I found a different kit with a similar motor and it said 3-6V.

I thought we're not supposed to directly connect a motor to a power source since it would damage it, I did however test the batteries with a volt meter and I am getting a reading of "-1.60" when on DCV20 Setting (I also shocked myself accidentally with it so I think its working to some degree lol).

Batteries in Series or Parallel? I'm not sure but here is the battery pack I am using: https://www.amazon.com/gp/product/B002MRFM48/. As you can see from the picture, I connected them in a row and looking at the link you provided, I think Parallel? This might be the problem since like you mentioned, its not getting enough power. (update) I put the batteries in series then did a volt meter test and got -6 so I think we're onto something. I'll re-solder the wire to the other end and I'll get back to you guys with an update.

User avatar
rpdom
Posts: 11860
Joined: Sun May 06, 2012 5:17 am
Location: Essex, UK

Re: Simple 10v Motor with L293D Not Working

Wed Oct 25, 2017 7:08 pm

You can't get a shock from 1.6V (you've got the meter connected back to front, which is why it shows a minus voltage). Hopefully that was a static discharge (which isn't good around computers) instead of a leaky PSU or something (which isn't good around computers or humans).

Connecting the batteries in series (end to end) will give you around 6V, which should be fine to drive the motor.

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple 10v Motor with L293D Not Working

Wed Oct 25, 2017 9:54 pm

OK, I re-soldered the wire on my battery pack and I'm now getting 6v in series when I test with my volt meter. Here is the new setup:

Image

A closer angle on the chip:

Image

I attached the motor to the wires and ran the python script. Unfortunately it still did not work, I tried swapping the wires on the motor too but no luck.

pcmanbob
Posts: 2218
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Simple 10v Motor with L293D Not Working

Thu Oct 26, 2017 9:26 am

HI Katianie

Seeing as things are still not working how about we do some basic tests.

1. With the pi powered, using you meter set on volts carefully measure the voltage on one of the connection points marked 5v
Image
be careful not to short the 2 pins together. A good way to do this is to clip one end of a breadboard jumper cable in to your meter lead and plug the other end in to your breadboard.
Image

If you get a reading of 5v then all is well, if you don't you might have the cable that connects it to the pi plugged in to the pi the wrong way round.

2. try connecting the wires from your batter directly to the motor it should spin regardless of which wire you connect to which terminal.

presuming the first two tests were OK.
3. with every thing powered unplug the 2 wires from the gpio connector on terminals 23 and 24 ( 2 yellow wires.)
now connect one to 5v and one to ground you can use the red + and blue - connection strips under the 5v connection point in the above image.
your motor should spin and if you reverse them then you motor rotation will reverse.
if it does then your l293 is wired correctly if it doesn't then there is a problem with the chip or your wiring.

One final note in your original code you had the gpio set to BOARD mode but you were using gpio numbering which is BCM mode.
Last edited by pcmanbob on Thu Oct 26, 2017 5:32 pm, edited 2 times in total.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple 10v Motor with L293D Not Working

Thu Oct 26, 2017 3:49 pm

It Works! :D :D :D

1. Yep, got a reading of 5.10
2. Yep, motor spins.
3. Yes that worked too.

I now thought there was something wrong with the chip. But actually, I re-ran the program with everything hooked up but this time i made sure the wires on the motor we're pressing hard enough for a connection and it spun! So one of the problems was that even though the wires on the motor we're touching the contacts on the motor, they still needed to be pressed a little harder against the contacts.

pcmanbob
Posts: 2218
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: Simple Motor with L293D Not Working (Solved!)

Thu Oct 26, 2017 5:31 pm

Glad you finally got it to work.
Probably the best thing to do is solder the wires to the motor.

So which program did you use in the end ? As you original one was set up to use board numbering rather than gpio numbering.
Please only ask questions in the forum I will not answer questions sent to me directly via PM
Remember we want information.......................no information no help

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple Motor with L293D Not Working (Solved!)

Fri Oct 27, 2017 3:31 am

I used the code provided by Forris, I'm working on getting it to work with my C++ library now that I have it working in general.

User avatar
Katianie
Posts: 41
Joined: Thu Jul 20, 2017 1:16 am
Contact: Website

Re: Simple Motor with L293D Not Working (Solved!)

Sat Oct 28, 2017 4:58 am

For my next step I'd like to set up a second motor to the same chip. Do I need another battery pack for that motor or do you think I have enough voltage already?

Return to “Troubleshooting”

Who is online

Users browsing this forum: DangDolphins and 23 guests