Run DC motor with IR Proximity Sensor

PLease help me to write a code to run a DC motor with IR Proximity sensor. I am using arduino uno and l293d IC…I am new to this…I am learning…Please help

Use the Google function up to the right in this window and search for running DC motor resp. Proximity sensor.
Nobody will write any code for You here.

Google lets me see what a l293d is, but I can't find any information about your motor or your IR sensor. Can you guess why?

Paul

I wrote the code but dc motor is not running
int sensor1 = 5;
int sensor2 = 6;
int motor1 = 7;
int motor2 = 8;

void setup(){
pinMode(sensor1,INPUT);
pinMode(sensor2,INPUT);
pinMode(motor1,OUTPUT);
pinMode(motor2,OUTPUT);
}

void loop(){
C:
if(sensor1==LOW){
digitalWrite(motor1,HIGH);
digitalWrite(motor2,LOW);
delay(500);
digitalWrite(motor1,HIGH);
digitalWrite(motor2,HIGH);
A:
if(sensor2==LOW){
digitalWrite(motor1,LOW);
digitalWrite(motor2,HIGH);
delay(500);
digitalWrite(motor1,HIGH);
digitalWrite(motor2,HIGH);
delay(1000);
goto C;
}goto A;
if(sensor2==LOW){
digitalWrite(motor1,HIGH);
digitalWrite(motor2,LOW);
delay(500);
digitalWrite(motor1,HIGH);
digitalWrite(motor2,HIGH);
B:
if(sensor1==LOW){
digitalWrite(motor1,LOW);
digitalWrite(motor2,HIGH);
delay(500);
digitalWrite(motor1,HIGH);
digitalWrite(motor2,HIGH);
delay(1000);
goto C;
}
goto B;
}
}
}

What motor?

@vaseemmirza

Other post/duplicate DELETED
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.

Could you take a few moments to Learn How To Use The Forum.
It will help you get the best out of the forum in the future.
Other general help and troubleshooting advice can be found here.

Here is your code posted properly and indented:

int sensor1 = 5;
int sensor2 = 6;
int motor1 = 7;
int motor2 = 8;

void setup() {
  pinMode(sensor1, INPUT);
  pinMode(sensor2, INPUT);
  pinMode(motor1, OUTPUT);
  pinMode(motor2, OUTPUT);
}

void loop() {
C:
  if (sensor1 == LOW) {
    digitalWrite(motor1, HIGH);
    digitalWrite(motor2, LOW);
    delay(500);
    digitalWrite(motor1, HIGH);
    digitalWrite(motor2, HIGH);
A:
    if (sensor2 == LOW) {
      digitalWrite(motor1, LOW);
      digitalWrite(motor2, HIGH);
      delay(500);
      digitalWrite(motor1, HIGH);
      digitalWrite(motor2, HIGH);
      delay(1000);
      goto C;
    } goto A;
    if (sensor2 == LOW) {
      digitalWrite(motor1, HIGH);
      digitalWrite(motor2, LOW);
      delay(500);
      digitalWrite(motor1, HIGH);
      digitalWrite(motor2, HIGH);
B:
      if (sensor1 == LOW) {
        digitalWrite(motor1, LOW);
        digitalWrite(motor2, HIGH);
        delay(500);
        digitalWrite(motor1, HIGH);
        digitalWrite(motor2, HIGH);
        delay(1000);
        goto C;
      }
      goto B;
    }
  }
}

The use of gotos is poor coding practice and rarely necessary. So rare, in fact, I haven't used a goto in decades.

Also, you are never reading the sensors. You need to use digitalRead() to read the sensor inputs.

I would suggest rewriting your code without using gotos and posting the details of your motors, sensors, and wiring.

Paul_KD7HB:
What motor?

100 rpm dc motor

int i1=12;
int ENA = 4;
int m1=6;
int m2=7;
int SPEEd=210;
void setup() {
pinMode(i1,OUTPUT);
pinMode(m1,OUTPUT);
pinMode(m2,OUTPUT);
pinMode(ENA,OUTPUT);

}

void loop() {
int a=digitalRead(12);
if(a==1)
digitalWrite(m1,HIGH);
digitalWrite(m2,LOW);
delay(1000);

}

So you've set pin 12 to OUTPUT mode and then you're reading from it. That's a bit eccentric.

You never set any value to ENA which would normally control motor speed except you've got it on a pin which doesn't allow PWM on most Arduinos.

And because you have no {} your if statement only controls one line. The other two lines run unconditionally.

But at least it compiles. Does it actually do anything?

Steve

You need to review basic C/C++ programming constructs. There are a multitude of tutorials and references online. Otherwise you will find constructing a working program very frustrating.