Arduino SA
Search…
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.
1
//Original Code: https://www.instructables.com/Arduino-Plant-Watering-System/
2
//Amended by Armandus Basson
3
//For Arduino UNO
4
//Components / Kit: https://www.robofactory.co.za/home/232-automatic-smart-plant-watering-kit.html
5
6
int waterPump = 5; //Relay Pin = 5
7
8
void setup() {
9
Serial.begin(9600);
10
pinMode(waterPump, OUTPUT);
11
}
12
13
void loop() {
14
int humidityRaw = analogRead(A2);
15
int humidityReal = map(humidityRaw, 1023, 0 ,0, 100); //Convert raw sensor data to percentage
16
17
//Print converted moisture sensor data (percentage) to the serial console
18
Serial.print("Soil Moisture = ");
19
Serial.print(humidityReal);
20
Serial.println("%");
21
22
delay(4000); //Delay before next sensor reading. Current set as 4 seconds
23
24
if (humidityReal > 30) //Set threshold when relay must open for pump to feed water
25
{
26
digitalWrite(waterPump, HIGH);
27
delay(5000); //Pump need to run for 5 seconds before the next sensor reading
28
}else{
29
digitalWrite(waterPump, LOW);
30
}
31
}
Copied!

Credits

Last modified 14d ago
Copy link
Contents
Credits