Simple Automatic Watering System With Arduino

| Comments

Summer is comming and we may need to water our plants almost everyday, but we should take advantage of technology and let machines water our plants for us.

Today we will show you how to build a simple and smart watering system using Arduino.

DescriptionMaterials
In this tutorial we will create a simple watering system using basic Arduino code, with sensors and some digital outputs.
  • A water pump
  • A humidity sensor (optional)
  • Arduino (Mini, Nano, UNO, etc)
  • An NPN transistor
  • Water
  • Plants (optional)
Links
Difficulty

First you need to enable your water pump from Arduino. Some of them may have different current requirements, mine works on current: 0.05A~0.12A. However, Arduino I/O pins have some current limitations (up to 40.0 mA), therefore we will use a transistor as a switching device, connected directly to VCC.

You can see all the details in the schema below.

Another thing to mention is that we want our automatic watering system to have two different functions:

  • Time-based: Water the plants every x seconds during y seconds.
  • Humidity-based: Water the plants everytime it hits a threshold.

To pick either of the methods we will use a normal switch that we will read inside the loop in our code.

Here’s the Arduino sketch, also available on github

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#define HUMIDITY_SENSOR 10
#define WATER_PUMP 9
#define MODE 4 
#define LED 13  //For notification

#define HUMIDITY_THRESHOLD 50
#define PUMP_FREQUENCY 1000
#define PUMP_ENABLE_TIME 1000 // Time to be enabled (in ms)

int mode;
int humidityRead;
long lastTimeActive;
bool pumpEnabled;

void setup(){
  pinMode(HUMIDITY_SENSOR, INPUT);
  pinMode(WATER_PUMP, OUTPUT); 
  pinMode(LED, OUTPUT); 

  pinMode(MODE, INPUT); digitalWrite(MODE,HIGH);
  
  disablePump();
}

void loop(){
  mode = digitalRead(MODE);
  
  if (mode == HIGH) { //time mode
    if (!pumpEnabled && millis() > lastTimeActive + PUMP_FREQUENCY) {
      enablePump();
      lastTimeActive = millis();
    } 
    if (pumpEnabled && millis() > lastTimeActive + PUMP_ENABLE_TIME) {
      disablePump();
      lastTimeActive = millis();
    }
  } else { //Humidity mode

    humidityRead = analogRead(A0);
    
    if (humidityRead < HUMIDITY_THRESHOLD) {
      if (!pumpEnabled) enablePump();
    } else {
      if (pumpEnabled) disablePump();
    }
  }
  
  delay(1000);
}

void enablePump() {

    digitalWrite(WATER_PUMP, HIGH); 
    digitalWrite(LED, HIGH); 

    pumpEnabled = true;
}


void disablePump() {

  digitalWrite(WATER_PUMP, LOW); 
  digitalWrite(LED, LOW); 

  pumpEnabled = false;
}

If you don’t have a humidity sensor (or don’t want to use one), you can remove both (the switch and the sensor) from the schema.

But also, you can use this for watering multiple plants, or you could use this project for your pets or to wake up in the morning covered by water in your bed.

Comments