fbpx

Procedure with Output

Schematic Diagram :

Program :

Open Arduino IDE and paste the following code.

const int AirValue = 616;   //replace the value from calibration in air
const int WaterValue = 335;  //replace the value from calibration in water
int soilMoistureValue = 0;
int soilmoisturepercent=0;
void setup() {
  pinMode(2,OUTPUT); // pin where relay trigger connected
  Serial.begin(9600); // open serial port, set the baud rate to 9600 bps
}
void loop() {
soilMoistureValue = analogRead(A0);  //Mention where the analog pin is connected on arduino
Serial.println(soilMoistureValue);
soilmoisturepercent = map(soilMoistureValue, AirValue, WaterValue, 0, 100);
if(soilmoisturepercent < 10)  // change this at what level the pump turns on
{
  Serial.println(“Nearly dry, Pump turning on”);
  digitalWrite(2,HIGH);  // Low percent high signal to relay to turn on pump
}
else if(soilmoisturepercent >85) // max water level should be
{
  Serial.println(“Nearly wet, Pump turning off”);
  digitalWrite(2,low);  // high percent water high signal to relay to turn on pump
}
 
   delay(400); //Wait for few milliseconds and then continue the loop.
}

Here we used map function to calculate soil moisture percentage the syntax of map function in Arduino  is given below

We added the values according to the plant watering techniques, we add the min percentage as 10% because if the soil becomes completely dry that will effect the plant, and in the same way maximum percentage where pump should be turned off to 85% to maintain the over water issue. You can modify those values according to your needs.

Related Video for reference :