soil program with level meter

Hello,

First time user here and am a bit in the dark here about some points.

It exists out 2 parts :
Part 1
I have made a plant watering system which uses 3 LED’s. one for humid soil, one for almost dry and one for dry soil. when the dry soil is reached a relay is switched on and sends power to a pump which sprays water on it.

part 2 :
I want to add a level meter which uses a second soil sensor so when it isnt measuring water, it interacts as a safety to not destroy the pump and should come with 2 LED’s. one for enough water and one for no water.

I have the pump working but am having trouble reading and setting the point where the LED’s schould function for the first part

if (moisture <149)
{
digitalWrite (6, LOW); //Relais off
digitalWrite (8, LOW); // Light OFF

the way i read is when the moisture is below 149 reading the pump schould be turned on. However, when i upload this to the arduino it turns on the pump. Same with LED’s the outputs seem reversed.

AS for part 2 , for which i dont have anything. How do i add it to the system to first check for water or constantly check for water and the let the readings begin.

Sorry for the boatloat of words but i don’t have any experience but really want to learn this.

I really love it

Here’s my code until now

const int VAL_PROBE = 0;
int sensorValue = analogRead(A1);

void setup()
{
Serial.begin(9600);
pinMode (6,OUTPUT);
pinMode (8,OUTPUT);
pinMode (9,OUTPUT);
pinMode (10,OUTPUT);
}

void loop()
{
int moisture = analogRead(VAL_PROBE);
Serial.print("Vochtigheidsmeter : "); /
Serial.println(moisture);
delay(1000);
if (moisture <149)
{
digitalWrite (6, LOW); //Relais aan of uit
digitalWrite (8, LOW); // red lamp uit

}
else
{
digitalWrite (6, HIGH);
digitalWrite (8, HIGH);

}
if (moisture <300)
{

digitalWrite (9, HIGH); // Oranje LED

}
else
{
digitalWrite (9, LOW);

}
if (moisture <301) // Green LED
{

digitalWrite (10, HIGH);

}
else
{
digitalWrite (10, LOW);
}

}

Depending on how the LEDs and relay are wired, they may be “active low” (this is often easier to implement in the hardware), instead of “active high” - does that explain your situation?

Also, your logic is messed up for the LEDs:

You have it turning on the orange LED if moisture is less than 300. Even if moisture is less than 149 too and it’s just turned on the red led and the pump. You want (moisture < 300 && moisture >149)

You have it turning on the green LED if moisture is less than 301. You probably meant greater than 301. But what you actually want is >=300. If you checked for >301, if the moisture was at 300 or 301, it wouldn’t turn on any LEDs.

If you are using a standard cheap Chinese resistive soil sensor, it will be dissolved in a couple of weeks when powered always. You can power such a module via a pin and switch it on a short time before the measurement, which could be done once a minute.

My problem is and it can be a logic problem. When I say digitalwrite LOW the LED goes on...

How should I implement part 2in this code? I honestly have no idea and can't find anything on the web

Thanks for the reply and answers

So what's wrong with digitalWrite(pin,LOW) turning the LED on, and digitalWrite(pin,HIGH) turning the LED off?

It is typically best practice to have the positive side of the LED on Vcc, and drive the other side low to turn it on - You can do it the other way around (negative side of LED to ground), and on Arduino Uno it's just as good (the Atmega328p has symmetric drive), but I say it's good practice because you'll encounter many devices in the course of working with electronics that are much better at driving pins low than driving them high. Some ATTiny chips, and the Arduino Due, have pins that are better at sinking current (pulling low) than sourcing current (pulling high)

its just wrong logic i thing. Setting it to high would mean to me turning it on.

I have this ant it works.

How do i merge these 2 programs so that the level control is the priority and watering is second. I want to have this safety to keep the pump from overheating


Part 1 : safety, the level control

const int VAL_PROBE = 0;
int moisture = analogRead(A0); // Analoge ingang 0 VOCHTMETING
int levelValue = analogRead(A1); // Analoge ingang 1 LEVELMETING

void setup() // Hier begint de installatie
{
Serial.begin(9600); // De communicatie met de seriële poort wordt gestart. Dit vereist dat u de waarde te lezen in de seriële monitor.
pinMode (6,OUTPUT); // GROENE LED LEVEL METING ALLES OK
pinMode (12,OUTPUT);
pinMode (11,OUTPUT); // RODE LED LEVEL METING GEEN WATER

}

void loop()
{
int levelValue = analogRead(A1);
Serial.print("level : "); //Naam die we kunnen zien op de seriele monitor waar we de waarden kunnen aflezen
Serial.println(levelValue);
delay(1000);
if (400>levelValue ) // ONDER DE 149 GAAT DIT IN WERKING
{
digitalWrite (6, LOW); //Relais AAN
digitalWrite (11, LOW); // RED lamp AAN
digitalWrite (12, HIGH);

}
else
{
digitalWrite (6, HIGH);
digitalWrite (11, HIGH);
digitalWrite (12, LOW);

}

}

everything works including the LEDs. I have also set the input 6 as the relay. which is in the same code below

Part 2 : soil meter

const int VAL_PROBE = 0;
int sensorValue = analogRead(A1); //ANALOGE INPUT IS VOCHTSENSOR GROND

void setup()
{
Serial.begin(9600);
pinMode (6,OUTPUT); //OUTPUT 6 IS STURING VAN DE VOCHTMETER
pinMode (8,OUTPUT); //OUTPUT 8 IS GROENE LED
pinMode (9,OUTPUT); //OUTPUT 9 IS ORANJE LED
pinMode (10,OUTPUT); //OUTPUT 10 IS RODE LED
}

void loop()
{
int moisture = analogRead(VAL_PROBE);
Serial.print("Vochtigheidsmeter : ");
Serial.println(moisture);
delay(1000);
if (moisture <=149) // ONDER DE 149 GAAT DIT IN WERKING
{
digitalWrite (6, LOW); //Relais AAN
digitalWrite (8, LOW); // RED lamp AAN

}
else
{
digitalWrite (6, HIGH);
digitalWrite (8, HIGH);

}
if (moisture < 300 && moisture >149) //TUSSEN 149 EN 300 GAAT DIT IN WERKING
{
digitalWrite (9, LOW); // Oranje LED
}
else
{
digitalWrite (9, HIGH);
}
if (moisture >=300) // Green LED
{
digitalWrite (10, LOW);
}
else
{
digitalWrite (10, HIGH);
}

}

thx in advance will updat if its ready to use with pictures

Don't forget to post pictures of the destroyed sensors. ;)

Thanks. It would be kind for someone to help me instead of being sarcastic. This is the first thing I do on an arduino.

And I know the delay must be higher but this was for testing purposes