soil moisture sensor question analog question

Hello,

A while back i asked a question how to make a soil sensor. I made a level control and the whole project and everything worked as planned.

I knew of the corroding part but my question is.

I set a interval of 3 hours to read the soil moisture.

does the analog pin keep sending eletricity to the sensor constantly, or only in my loop?

can anyone check out my code?

If it is sending power constantly to the sensor is there a way to stop it?

thx in advance

int moisture = analogRead(A0); // Analoge ingang 0 VOCHTMETING
int levelValue = analogRead(A1); // Analoge ingang 1 LEVELMETING
int stayON = 15000; // AANTAL SECONDEN DAT DE RELAIS AAN MOET STAAN

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); //RELAIS WERKING
pinMode (8,OUTPUT); //OUTPUT 8 IS RODE LED
pinMode (9,OUTPUT); //OUTPUT 9 IS ORANJE LED
pinMode (10,OUTPUT); //OUTPUT 10 IS GROENE LED

pinMode (11,OUTPUT); //LEVEL GOED: GROENE LED
pinMode (12,OUTPUT); //LEVEL SLECHT : RODE LED
}

void loop() // Hier begint de volledige 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); // Verwijzing voor verderecodering

if (400>levelValue ) // ONDER DE 400 GAAT DIT IN WERKING
{
digitalWrite (11, LOW); //GROENE LED AAN
digitalWrite (12, HIGH); //RODE LED UIT
}
else
{
digitalWrite (6, HIGH); // RELAIS UIT
digitalWrite (11, HIGH); // GROENE LED UIT
digitalWrite (12, LOW); // RODE LED AAN
}

{
int moisture = analogRead(A0);
Serial.print("Vochtigheidsmeter : ");
Serial.println(moisture);

if (moisture <=149 && 400>levelValue) // ONDER DE 149 VOCHTIGHEID EN ALS HET LEVEL IN ORDE IS GAAT DIT INWERKING
{
digitalWrite(10, HIGH); // GROENE LED UIT
digitalWrite(8, LOW); // RODE LED AAN
digitalWrite(6, LOW); // Relais AAN
delay(stayON); // AAN GEDURENDE DE AANTAL MS DIE VANBOVEN INGESTELD STAAN
digitalWrite(6, HIGH); // DAN RELAIS UIT
}
else
{
digitalWrite (6, HIGH); // RELAIS UIT
}

if (moisture <=149) // ONDER DE 149 VOCHTIGHEID EN ALS HET LEVEL IN ORDE IS GAAT DIT INWERKING
{
digitalWrite(8, LOW); // RODE LED AAN
digitalWrite(10, HIGH); // GROENE LED UIT
}
else
{
digitalWrite (8, HIGH); // RODE LED UIT
}

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);
}
delay(7200000); //7200000 seconden of 2 uur
}

}

does the analog pin keep sending eletricity to the sensor constantly, or only in my loop?

No current flows into or out of the analog pin.

Presumably, you have a voltage divider made-up of a resistor in series with your moisture sensor. If you are applying power to that voltage divider, current is flowing through the resistor and moisture sensor (with or without the Arduino).

so the code is OK?

Is it just sending power for a couple ms to read and turning it off directly after?

(deleted)

analog read A0

(deleted)

You should only power the soil sensors (I assume you use the cheap standard ones) some milliseconds before the measurement and disengage them in the waiting period.
They can be powered via Arduino pins, so this is not a big deal when you have enougth pins free.