Rain Drop sensor with Motor Shield

i wan't to control my dc motor in situaion , my sensor is rain drop

-if sensor have signal (ex valuae >500)
+motor turn left in 10s then stop

-if sensor no signal (ex: valuae =0)

+motor turn right then stop

i'm just begin program arduino

thank you very much!!!

my code and my skecht

#include <AFMotor.h>
int potPin = 0;    // select the input pin for the potentiometer
int val = 0;       // variable to store the value coming from the sensor
AF_DCMotor motor(2, MOTOR12_64KHZ); // create motor #2, 64KHz pwm

void setup() {
  Serial.begin(9600);           // set up Serial library at 9600 bps
  Serial.println("Motor test!");
  
  motor.setSpeed(200);     // set the speed to 200/255
}
void loop() {
  val = analogRead(potPin);  
if(val > 500)
  {  // read the value from the sensor
  Serial.print("tick");
  motor.run(FORWARD);      // turn it on going forward
  delay(500);
}
  else
  {                  // stop the program for some time
  Serial.print("tock");
  motor.run(BACKWARD);     // the other way
  delay(500);     

}
}

Moderator edit: code tags

Is this a question or a demo of something?
If so what?
Please post any code correctly.

sorry, i edited wrong , thank you

You have no code to stop the motor.
You are using the else for the >500 test that means it will always run backwards or forwards.

You need an if condition for the stop state. ( do you actually get 0 from the sensor? )

My situation

-First : my motor stop

-if sensor have signal (ex valuea >500)
+motor turn left in 10s then stop and wait next signal

-if sensor no signal (ex: valuae =0)

+motor turn right then stop and wait next signal

my project is : -If have rain , my motor will close windows , else my motor will open windows automaticaly

can you write the code for my project

two more things. temperature and time since it rained.

the tutorials in the software should have enough code for you to put something together.

if no water and temp is above x and below y, then open windows
if water, close windows
if water, start to count,
if > ____ minutes, open windows

can i dont care about time ???

if water , close windows and my motor working in 1 minute and stop until not water, my motor backward and still working in 1 minute for open the door

i think code simple but my knowledge about program arduino very limited, i'm just start learn about arduino

please help me , i don't know how stop my motor

quangphuc91:
please help me , i don't know how stop my motor

Since you're using the AFMotor library to control the motor, you need to look at the documentation for that library and identify the method that stops the motor - and then call it, in the appropriate place in your code.

code for stop motor is :

Serial.print("tack");
  motor.run(RELEASE);      // stopped
  delay(1000);

but it just stop motor in 1 second and continue run and stop ..., i want the motor stop until the sensor change signal

i want the motor stop until the sensor change signal

Then write your code like that.
You have been offered a lot of advice, you now have new code, it is time to post your code again so we can see where you are up to.

i'm rewrite my code but if i use code :

Serial.print("tack");
motor.run(RELEASE);
delay(1000);

my motor just stop in 1 second

can you help me ?

Post your code.
Use code tags, please.

i want the motor stop until the sensor change signal

So, remember the state when you last read it, and only change the output when there has been a significant change to the input.

my motor just stop in 1 second

This is because you have some other code that turns it on.
We don't know what this code is because you have not posted your rewrite.
Unless you cooperate you can not get help.