Huge Newb needs help with capacitive soil sensor

So that code was working? Before I wired up the relay switches and pumps, values were going down when wet, and up when dry. reading about 750 when dry, 200 when wet. Then i wired up the relay and now it only reads 650 no matter what. Is it the code? i dont think so


// 4 control pins of the relay
int IN1 = 2;
int IN2 = 3;
int IN3 = 4;
int IN4 = 5;

// detect value from soil sensor
int Pin1 = A0;
int Pin2 = A1;
int Pin3 = A2;
int Pin4 = A3;
//

float sensor1Value = 0;
float sensor2Value = 0;
float sensor3Value = 0;
float sensor4Value = 0;


void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);

  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);

  pinMode(Pin1, INPUT);
  pinMode(Pin2, INPUT);
  pinMode(Pin3, INPUT);
  pinMode(Pin4, INPUT);

  digitalWrite(IN1, HIGH);
  digitalWrite(IN2, HIGH);
  digitalWrite(IN3, HIGH);
  digitalWrite(IN4, HIGH);

  delay(500);

}

void loop() {
  // put your main code here, to run repeatedly:

  Serial.print("Asshole 1 - Moisture Level:");
  sensor1Value = analogRead(Pin1);
  Serial.println(sensor1Value);

  if (sensor1Value > 450) {
    digitalWrite(IN1, HIGH);
  } else {}
  digitalWrite(IN1, LOW);

  delay (500);


  Serial.print("Asshole 2 - Moisture Level:");
  sensor2Value = analogRead(Pin2);
  Serial.println(sensor2Value);

  if (sensor2Value > 450) {
    {
      digitalWrite(IN2, HIGH);
    }
  } else {}
  digitalWrite(IN2, LOW);


delay (500) ; 

Serial.print("Asshole 3 - Moisture Level:");
  sensor3Value = analogRead(Pin3);
  Serial.println (sensor3Value);

  if (sensor3Value > 450) {
    {
      digitalWrite(IN3, HIGH);
    }
  } else {}
  digitalWrite(IN3, LOW);

  delay (500);  

Serial.print("Asshole 4 - Moisture Level:");
  sensor4Value = analogRead(Pin4);
  Serial.println(sensor4Value);

  if (sensor4Value > 450) {
    {
      digitalWrite(IN4, HIGH);
    }
  } else {}
  digitalWrite(IN4, LOW);

  delay (500);
}

Welcome to the forum

Did you have these 4 lines of code in your original sketch ?

  pinMode(Pin1, INPUT);
  pinMode(Pin2, INPUT);
  pinMode(Pin3, INPUT);
  pinMode(Pin4, INPUT);

I ask because by setting them as inputs like this implies that you are going to use them as digital rather than analogue inputs

How are the relays powered ? Is it directly from the Arduino pins and, if so, how much current do they draw when turned on ?

Yea its had that the entire time, including when it worked properly.
I see i have an analogread function, but if my input is digital could that be an issue?

Relays are powered via Arduino pins. I dont know how to read current draw, but when a motor turns on, the read values drop pretty significantly

The moisture sensor is an analogue device otherwise it would output only one of 2 values, ie HIGH or LOW which would be useless

There is no need to set the pins used by analogRead() as inputs because the function handles it

Do you have a multimeter ? If not then I suggest that you get one. Even a cheap one is better than none at all

The fact that the readings change when a motor turns on is significant. Dare I ask what type of motors they are and how they are powered ?

that video uses the same kit that i bought and is what i used to wire up the whole thing. the pumps are pretty small and are powered by an external power source, 2 AA batteries

i dont have a multi meter, its on the list lol

Solution!

That guy outlines a bunch of different issues with the sensors themselves. The timer chip on mine required a 4.5 volt output, and the usb port from my mac didnt provide that. I added a 9v battery to power the arduino and everything worked!

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