How to DC stop motor

How to DC stop motor , Our project is Automatic roof, by the use of LDR and Water sensor, it close and open the roof, what is other code that can be use of this,, because this code is interval, and it takes us to timing the sensors to open and close..

const int Clockwise = 7;
const int CounterClockwise = 8;

int ldrPin = A3;

long previousMillis = 0;
long interval = 5000;

void setup() {
// put your setup code here, to run once:
Serial.begin(9600);

pinMode(ldrPin, INPUT);
pinMode(Clockwise, OUTPUT);
pinMode(CounterClockwise, OUTPUT);
Serial.begin(9600);
}

void loop() {

int waterSensorStatus = analogRead(A1);
int ldrStatus = analogRead(ldrPin);
millis()-previousMillis;

if (((waterSensorStatus <= 20) && (ldrStatus < 500)) || ((waterSensorStatus > 20) && (ldrStatus > 500)) || ((waterSensorStatus > 20) && (ldrStatus < 500)))
{

if (millis() - previousMillis > interval){
digitalWrite(Clockwise, HIGH);
digitalWrite(CounterClockwise, HIGH);
previousMillis = millis();

}
else{
millis()-previousMillis;
Serial.println(previousMillis);
digitalWrite(CounterClockwise,HIGH);
delay(1000);

}
}

if ((waterSensorStatus <= 20) && (ldrStatus > 500))
{

if (millis() - previousMillis > interval){
digitalWrite(Clockwise, LOW);
digitalWrite(CounterClockwise, LOW);
previousMillis = millis();

}
else{
Serial.println(previousMillis);
digitalWrite(CounterClockwise, LOW);
delay(1000);
}
}
}

millis()-previousMillis;

What is that supposed to do?

Please read the "how to use this forum-please read" sticky topics to see how to format and post code.

Sorry.. i am new to arduino.. and i get that to other who posted here. Can you give me a code that can stop motor using water sensor with a giving time?

brint213:
Can you give me a code that can stop motor using water sensor with a giving time?

That is not what we do here.

You write the code and if you have problems you post your code and we will try to help you get it working.

It may be wise to put limit switches (simple microswitches) to detect when the roof is fully open or fully closed. I doubt if timing the movement would be sufficiently reliable.

...R