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:
//Amended by Armandus Basson
//For Arduino UNO
//Components / Kit:
int waterPump = 5; //Relay Pin = 5
void setup() {
  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 = ");
  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
    digitalWrite(waterPump, LOW);


Credit for this code needs to go to TechStudio

Instructables Orignal Post

Last updated