The Code

If your UNO drivers aren’t installed automatically when using this kit, I will save you some time searching for the correct drivers by downloading them here__

Open up your Arduino IDE and connect your Arduino board to your PC.

Copy and paste the code below and upload the code.

Once the code is uploaded, disconnect the USB cable and switch on the battery. if you need to make changes to the code, please switch off the battery before you connect the USB cable to your PC.

//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

Credit for this code needs to go to TechStudio

https://www.techstudio.co.za/2021/08/09/arduino-uno-smart-plant-watering-kit-code-driver/

Instructables Orignal Post

https://www.instructables.com/Arduino-Plant-Watering-System/

Last updated