1
int EN1=12;
int EN2=13;
int EN3=11;
int EN4=10;
int IR=15;
int LED=14;

void setup() {
  // put your setup code here, to run once:
Serial.begin(9600);
pinMode(EN1,OUTPUT);
pinMode(EN2,OUTPUT);
pinMode(EN3,OUTPUT);
pinMode(EN4,OUTPUT);

pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);
pinMode(IR,INPUT);
pinMode(LED,OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
digitalWrite(EN1,HIGH);
digitalWrite(EN2,HIGH);
digitalWrite(EN3,HIGH);
digitalWrite(EN4,HIGH);

forward();
}

void forward() {

analogWrite(2,255); // The speed value of the left motor//
analogWrite(3,0);

analogWrite(4,255); //The speed value of the right motor//
analogWrite(5,0);

analogWrite(6,255); // The speed value of the left motor//
analogWrite(7,0);

analogWrite(8,255); //The speed value of the right motor//
analogWrite(9,0);
}
{
int z = digitalRead(IR);
if (z==HIGH)
{digitalWrite(LED,HIGH);
}
if (z == LOW)
{digitalWrite(LED,LOW);
}
}

Browse other questions tagged or ask your own question.