Programming sensors & actuators with arduino

I am doing a project on waste management. I have to separate waste majorly as metal, plastic and other materials. For that using Arduino Mega 2560. I have connected Inductive proximity sensor @ A0(Anolog pin 1 of arduino) & Capacitive proximity Sensor @ A1(analog pin 2 of arduino). The two 5v dc motor which are to be used as actuators when the sensors sense the object.
I have given 12 v to the 2 sensors & I have directly connected the sensor's output pin with arduino.

If the Inductive sensor senses any metal object in the conveyor, the dc motor which is a actuator here has to rotate forward, wait sometime & to rotate reverse and stay until the next sense started.
the same for capacitive sensor.

But the problem was there is even though the sensor is not sensing the motor is running. The motor keeps on running forward, delayed and reverse. Plz help me out for this, I don't know where I have done the mistake.

The program I have tried is here:

#define motorpin1 4 \dc motor's pin 1
#define motorpin2 5 \dc motor's pin 2
#define motorpin3 6 \dc motor's pin 3
#define motorpin4 7 \dc motor's pin 4

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(A0,INPUT);
pinMode(A1,INPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(6,OUTPUT);
pinMode(7,OUTPUT);
pinMode(8,OUTPUT);
pinMode(9,OUTPUT);

}

void loop() {
// put your main code here, to run repeatedly:
if((analogRead(A0)<400) && (analogRead(A0)>100)
{
digitalWrite(motorpin1,HIGH);
digitalWrite(motorpin2,LOW);
delay(5000);
digitalWrite(motorpin1,LOW);
digitalWrite(motorpin2,HIGH);
delay(5000);
digitalWrite(motorpin1,LOW);
digitalWrite(motorpin1,LOW);

}
if((analogRead(A1)<400) && (analogRead(A1)>100)
{
digitalWrite(motorpin3,HIGH);
digitalWrite(motorpin4,LOW);
delay(5000);
digitalWrite(motorpin3,LOW);
digitalWrite(motorpin4,HIGH);
delay(5000);
digitalWrite(motorpin3,LOW);
digitalWrite(motorpin4,LOW);

}

I have given 12 v to the 2 sensors & I have directly connected the sensor's output pin with arduino.

If the output from the sensor exceeds 5V, you WILL damage the Arduino.

The two 5v dc motor

will likely draw more current than the Arduino can provide.

  pinMode(4,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(7,OUTPUT);

You gave these numbers meaningful names, but then don't use the names. Why not?

if((analogRead(A0)<400) && (analogRead(A0)>100)

Do you really think this way? If John is 150 cm tall, would you describe him as being less than 2 meters tall and more than 1 meter? Or would you describe him as being more than 1 meter tall and less than 2 meters tall?

But the problem was there is even though the sensor is not sensing the motor is running.

How do you know what the sensor is sensing? You are debugging by guesswork, which is the worst way possible.

Use Serial.print() to tell you what analogRead() returned. Then, you'd have a clue.