The Code
//Original Code: https://www.instructables.com/Arduino-Plant-Watering-System/
//Amended by Armandus Basson
//For Arduino UNO
//Components / Kit: https://www.robofactory.co.za/home/232-automatic-smart-plant-watering-kit.html
int waterPump = 5; //Relay Pin = 5
void setup() {
Serial.begin(9600);
pinMode(waterPump, OUTPUT);
}
void loop() {
int humidityRaw = analogRead(A2);
int humidityReal = map(humidityRaw, 1023, 0 ,0, 100); //Convert raw sensor data to percentage
//Print converted moisture sensor data (percentage) to the serial console
Serial.print("Soil Moisture = ");
Serial.print(humidityReal);
Serial.println("%");
delay(4000); //Delay before next sensor reading. Current set as 4 seconds
if (humidityReal > 30) //Set threshold when relay must open for pump to feed water
{
digitalWrite(waterPump, HIGH);
delay(5000); //Pump need to run for 5 seconds before the next sensor reading
}else{
digitalWrite(waterPump, LOW);
}
}Credits
Last updated