H Bridge

i am a newbie........

i am having problem controlling 2 motors with L293D h bridge....
one motor works fine....but m not able to control speed of 2nd motor(it always runs max speen n in one direction nly.....stops when i yry to change direction).....:frowning:

int m1p1 = 5;
int m1p2 = 3;
int en1= 2 ;

int m2p1 = 10;
int m2p2 = 9;
int en2= 8 ;

int ldrPin = A0;
int VCC1 = 13;


void setup()
{
  Serial.begin(9600);
  pinMode(m1p1,OUTPUT);
  pinMode(m1p2,OUTPUT);
  pinMode(m2p1,OUTPUT);
  pinMode(m2p2,OUTPUT);
  pinMode(en1,OUTPUT);
  pinMode(en2,OUTPUT);
  
  digitalWrite(VCC1,HIGH);
  digitalWrite(11,HIGH);


}

void loop()
{
 
 int val = analogRead(ldrPin);
 Serial.println( val );
 if(val>50)
 {
   digitalWrite(en1,HIGH);
   digitalWrite(en2,HIGH);
   digitalWrite(m1p1,HIGH);
   digitalWrite(m1p2,LOW);
   digitalWrite(m2p1,HIGH);
   digitalWrite(m2p2,LOW);
 }
 
 else
 {
   digitalWrite(en1,LOW);
   digitalWrite(en1,LOW);
   
 }
}

It could be your wiring. How do you have things wired up?

Also, what is the meaning of the VCC1 pin (pin D13)? Are you providing VCC power to your L293 from this pin?? Not a good idea.

--
The Ruggeduino: compatible with Arduino UNO, 24V operation, all I/O's fused and protected

http://itp.nyu.edu/physcomp/Labs/DCMotorControl

wired as shown here....(here 1 motor only)........hav added another motor as in the circuit of h bridge....even if i power l293d with 5v oin ...same problem

motor 1 .......correct
motor 2.......runs only at max speed in one direction....if try in other...simply stops..!

The code for you've written doesn't seem like it would change directions of the motors based on val>50. To change direction, you need to change loop() to:

void loop()
{
 
int val = analogRead(ldrPin);
Serial.println( val );
if(val>50)
 {
   digitalWrite(en1,HIGH);
   digitalWrite(en2,HIGH);
   digitalWrite(m1p1,HIGH);
   digitalWrite(m1p2,LOW);
   digitalWrite(m2p1,HIGH);
   digitalWrite(m2p2,LOW);
 }
 
 else
 {
   digitalWrite(en1,HIGH);
   digitalWrite(en2,HIGH);
   digitalWrite(m1p2,HIGH);
   digitalWrite(m1p1,LOW);
   digitalWrite(m2p2,HIGH);
   digitalWrite(m2p1,LOW);
   
 }
}

The above code would reverse motors depending on value of val.

In fact, as long as you don't intend to use pwm for motor control, you can simply connect both enable pins to +5V and forget about setting them high with digitalWrite().