How can i put servo to sleep?

Hello, The case is, i am making a water dispenser for my dog, (with electric servo valve) so when the water level drops, under some level it begins to refill it. The main question is, how can put servo into sleep for somue duration for exaple lets say, The water filling begins (servo position is set to 90 at this time) at 300, then i need it to wait in same position till it wil run up to 700, than the servo goes back to pos 0. What command allows me do do such manipulation?

Have a look at the Blink and BlinkWithoutDelay examples in the IDE. If your code is doing nothing except waiting then the first is applicable but if it must do something else during the waiting period then use the second technique. For more details see Using millis() for timing. A beginners guide, and Several things at the same time

However, I am not sure what you mean by putting the servo to sleep. Do you simply mean that it must not move during the waiting period ? If so, then don't send it any commands and it will not move

Sounds like you have an analog sensor that reads as less than 300 when the bowl needs a refill and reads as 700 when the bowl is full.

void loop()
{
    if (analogRead(WaterSensorPin) < 300)
      servo.write(90);  // Turn on water
    if (analogRead(WaterSensorPin) > 700)
      servo.write(0);  // Turn off water
}

If you need the servo 'turned off' when not in use:

void loop()
{
    if (analogRead(WaterSensorPin) < 300)
    {
      servo.attach(ServoPin);
      servo.write(90);  // Turn on water
      delay(500); // Give the servo plenty of time to move
      servo.detach();  // 'turn off' the servo
    }

    if (analogRead(WaterSensorPin) > 700)
    {
      servo.attach(ServoPin);
      servo.write(0);  // Turn off water
      delay(500); // Give the servo plenty of time to move
      servo.detach();  // 'turn off' the servo
    }
}

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.