HELP

well Im working on a high school project with an arduino uno, its an automatic watering system. Im using two sensors, a soil humidity, and a ultrasonic. the problem is that I want the system to turn on a relay for the water pump only if there is water in a deposit and if the soil is dry. but my code only pays attention to the soil humidity sensor, and doesnt matter if there is or no water. Here is the code.
{
if (SensorValue< moistureThreshold && distance < 10) //10 is the depth of the deposit.
{
digitalWrite(relayPin, HIGH);
Serial.println("Pump off");
}
else
{
digitalWrite(relayPin, LOW);
Serial.println("Pump on"); // wait for a second
}

That's not code, that's a snippet.

Back to you.

Please post your complete program.

To make it easy for people to help you please modify your post and use the code button </> so your code looks like this and is easy to copy to a text editor. See How to use the Forum

Also please use the AutoFormat tool to indent your code for easier reading.

...R

Your logic is reversed. The expression "distance < 10" means "Not Empty". You are saying:

if (the soil is dry AND the water container is not empty)
    turn OFF the pump?!?
else
    // The water container is empty or the water is not dry
    turn on the pump.