Servo washing line

Hello everybody,

I want to program a sketch in Arduino Uno to turn a micro servo 9g 180° when the rain sensor resistance Drops, and it must stay at that Position.

But the Loop function makes the Motor turn to 180° and again to 0°. I want it only one time, so long the resistance of the sensor under a threshold

Can someone help me and find the failure in the code........ Thanks in advance

#include <Servo.h>

Servo myservo;

int pos = 0;
int RainSensor = A0;

void setup() 
{
  RainValue = analogRead(RainSensor);
  myservo.attach(9);
}

void loop() 
{
 if(RainValue < 400)
{
  for (pos = 0; pos <= 180; pos += 1)
{
    myservo.write(pos);             
    delay(15);                       
  }}

else{
  for (pos = 180; pos >= 0; pos -= 1)
{
    myservo.write(pos);              
    delay(15);                       
 }   
}
}

Please edit your post to include code tags. See How to use the forum.

But it does what you want it to. Assuming correct hardware because you can't actually measure resistance directly. But you probably want a time out when rain is detected so it does not go back the moment the rain drop left the sensor but it's still raining.

You only read RainSensor once in setup() as the program starts. In loop() you keep checking the value but it will never change because you never read the sensor again. That's probably not what you wanted.

Steve

Wow :o I missed that!