I'm having a problem connecting multiple soil moisture to turn on relay

///
#define WP_PIN 2 // Arduino pin that connects to

#define SM1_PIN A0 // Arduino pin that connects to AOUT pin of moisture sensor
#define SM2_PIN A1
#define SM3_PIN A2

#define WPTHRESHOLD 500 // Soil Moisture Sensor Threshold

void setup() {
Serial.begin(9600);
pinMode(WP_PIN, OUTPUT);

}

void loop() {
int val1 = analogRead(SM1_PIN); // read the analog value from sensor
int val2 = analogRead(SM2_PIN); // read the analog value from sensor
int val3 = analogRead(SM3_PIN); // read the analog value from sensor

if ((val1 > WPTHRESHOLD) && (val2 > WPTHRESHOLD) && (val3 > WPTHRESHOLD)) {
Serial.print("The soil is DRY => turn pump ON");
digitalWrite(WP_PIN, HIGH);
} else {
Serial.print("The soil is WET => turn pump OFF");
digitalWrite(WP_PIN, LOW);
}

delay(5000);
}

Hello
Add some Serial.println() to check the current values of the sensors.

Welcome to the forum.
The sketch is good, what is the problem ?

Please read this:

We will need to knoew:
which ardiuino you are using
what sensors you are using (with links)
how they are connected

Please edit your post, select all code and click the </> button to apply so-called code tags and next save your post. It makes it easier to read, easier to copy and the forum software will display it correctly.

Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advice on) your project :wink: See About the Installation & Troubleshooting category.

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the </> icon above the compose window) to make it easier to read and copy for examination

Use the IDE autoformat tool (ctrl-t or Tools, Auto format) before posting code in code tags.

Please include the entire error message. It is easy to do. There is a button (lower right of the IDE window) called "copy error message". Copy the error and paste into a post in code tags. Paraphrasing the error message leaves out important information.

Post a schematic.
Post an image of your project.

What kind of soil moisture sensors is the OP using? Post an image. Did the OP take calibration readings of each sensor to be used in detecting wetness?

Hi, @ahavah
What model Arduino controller are you using?

Thanks.. Tom.. :smiley: :+1: :coffee: :australia:

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