# Controlling DC motor with L293D

Hi,

i hope i’m right here with my question… i try to control an dc motor with an L293D chip like this page tells:
http://www.arduino-tutorial.de/2010/06/motorsteuerung-mit-einem-h-bridge-ic/

i set it up with an 9v Block battery or 6v (4x 1xAAA) but the motor wont move…
here’s the code:

``````int motor1_A=11;
int motor1_B=10;
int motor1_Speed=9;

int motor2_A=6;
int motor2_B=5;
int motor2_Speed=3;

int led_lm = 16;
int led_rm = 17;
int led_red = 15;
int led_green = 14;

void setup(){
pinMode(motor1_A,OUTPUT);
pinMode(motor1_B,OUTPUT);

pinMode(motor2_A,OUTPUT);
pinMode(motor2_B,OUTPUT);

pinMode(led_lm,OUTPUT);
pinMode(led_rm,OUTPUT);
pinMode(led_red,OUTPUT);
pinMode(led_green,OUTPUT);

digitalWrite(led_red,HIGH);
}

void loop(){
//digitalWrite(led_red,LOW);
//digitalWrite(led_green,HIGH);
// motor1

//digitalWrite(led_lm,HIGH);
//digitalWrite(led_rm,LOW);
for (int i=0; i<256; i+=5){
digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
digitalWrite(motor1_B,LOW);
analogWrite(motor1_Speed,i); // speed counts from 0 to 255
delay(20);
}
for (int i=255; i<0; i-=5){
digitalWrite(motor1_A,HIGH); // A = HIGH and B = LOW means the motor will turn right
digitalWrite(motor1_B,LOW);
analogWrite(motor1_Speed,i); // speed counts from 0 to 255
delay(20);
}
}
``````

i wired it like this:

(if the images wont load: ownCloud)

did i setup a pin wrong? or did i miss something?
i tried the “other” motor ports too… it look i’m blind at the moment

9V block batteries are for smoke alarms and are useless for motors.

The L293D has limited current capabilities and is not suitable for most motors. What is the stall current of your motor (equivalently, what is the winding resistance)?

i tried with 4xAAA Batteries too....

about the motors... i bought them used from a flea market so about stall current or something.. theres no writing on it... is there a way how i can test this?

to be honest, i'm still new to this, and stall current or winding resistance with motors are new for me ^^'

Do the motors run if you connect them straight to the batt terminals? Can you post a wiring diagram? Pics are good but it’s hard to tell what’s hooked to what with wires running out of the picture and obscuring other connections.

the motors run if i connect them to battery ports directly.

seems i got a pack of damaged chips (6pcs) because now the motors sometimes start, sometimes just one, and again none of it.

the wiring is like in the tutorial in the link above. i checked it six times and even someone else check if the cables are the same...

Hi,
Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

A hand drawn circuit will be good, if you draw your circuit from your project, it will ensure you have wired it correctly.
Please label all pins and connections and include power supplies.
I know this sounds silly, but you will learn a lot from drawing your own diagram and may find your problem.

If you use REPLY rather then QUICK REPLY you will find there is an ATTACHMENT facility.
Pictures of protoboards are good, but do not include any text about PCB connections.

Please attach all your images, cloud is not good if you are using a handheld/pad device to view the forum.

Thanks .. Tom...

Hi ops pics

Tom...

I can’t easily check your wiring from the photos but there’s an error in your code for the ‘slowing down’ part:

``````for (int i=255; i<0; i-=5){
...
...
}
``````

‘i’ is never less than zero so this loop won’t ever fire. This won’t stop the motor from running but it needs correcting (to i>0).

Looking at the original code you linked to, there’s a similar error

``````  for (int i=0; i&gt;256; i+=5){
...
...
}
``````

‘i>256’ is ‘i > 256’ but it is never more than 256 - so this loop would never fire either.

So if the original code is wrong I wouldn’t trust the rest of the sample! I haven’t translated the German to see if the comments reflect this.

shame on me…

that was is… some loops dont fire…

i made it simpler in logic, and now they run xD