Automatic Garden Watering System
by devinglover18 in Circuits > Arduino
397 Views, 8 Favorites, 0 Comments
Automatic Garden Watering System
I am big enthusiast for Plants and Gardening and one day I stumbled upon a video of creating an automatic watering system on youtube. I have a few indoor plants myself that sometimes I neglect with making sure they have water and sun. I did also already have an extra gardening bin that I wasn't using, so this would be the perfect opportunity to gather a few components, and attempt to keep my plants alive.
Luckily the video that I had watched had all the information needed to design and build this project. Huge shoutout to ILyas BK, his Youtube channel is linked here. Throughout this Instructable I have included some screenshots from the video but the whole video is attached for those who want to watch.
The goal of the project was to create an automatic system that would water the plants. I wanted the plant to still look aesthetically pleasing by hiding the circuit and the water reserve under the dirt the best that I could. There would still be one wire coming out
Supplies
The supplies and the links for each component for the project include:
Each Moisture Sensor has three pins. One pin powers the device. Another pin is connected to ground. The last pin sends the data measurements of the moisture levels. The sensor itself acts as a resistor. When moisture touches the sensor the resistance goes down. When there is no moisture detected, the sensor sends a signal to the Arduino telling it to power the pumps and watering the plant.
Any Arduino could be used, it acts as the brain of the circuit.
The Relay is what is used to power each pump and send water to the plant. The Arduino sends a signal to each pump telling it to turn on for a specific amount of time.
To power the Arduino, a 9V wall adapter is used. The Arduino is constantly on taking measurements.
The pumps need to be powered to run. A 9V battery is connected to the relay to power the pumps when the Arduino gets signaled.
The water pumps are what sends the water into the plant bin
For housing purposes and for the project to be completed, these additional pieces were also used and come down to personal preference on what should be acquired.
- Gardening Soil
- Plant Bin
- Jumper Wires
- Water Reserve
- Water Proof Case for the Circuit
Set Up the Workplace
The first thing I did was gather all the components that I would be using to make sure that I wasn't missing anything. Later in the build I realized that I would need more jumper wires than I originally thought. Luckily there was enough ordered so it wasn't a big issue.
Wiring Everything Together
Following the wiring diagram provided by ILyas BK, all of the wires were connected. I did make a few changes however to fulfill the needs of this project.
Two of the sensors are longer than the other two sensor wires. The bin itself was roughly three feet long and about a foot and half wide so to measure the overall moisture two of the sensors can be placed near the ends of the box.
The ground wire to each sensor was soldered together and then connected to ground. The same thing took place for the power wire to each of the sensors as well as the ground and the power wires connected to each of the pumps.
The Code
The Code:
/// creating the water pumps
int Pump1 = 2;
int Pump2 = 3;
int Pump3 = 4;
int Pump4 = 5;
/// creating the pump pins
int PP1 = A0;
int PP2 = A1;
int PP3 = A2;
int PP4 = A3;
///Initialize the sensors
float Sensor1 = 0;
float Sensor2 = 0;
float Sensor3 = 0;
float Sensor4 = 0;
///Calibrate the sensors
int PumpMX = 460;
int PumpMN = 330;
// total system counter
unsigned long MTS = 0;
int interval = 4320; //3 days in minutes
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
///Declare how each pump and pin will act
pinMode(Pump1, OUTPUT);
pinMode(Pump2, OUTPUT);
pinMode(Pump3, OUTPUT);
pinMode(Pump4, OUTPUT);
pinMode(PP1, INPUT);
pinMode(PP2, INPUT);
pinMode(PP3, INPUT);
pinMode(PP4, INPUT);
///start the pumps with a high value
digitalWrite(Pump1, HIGH);
digitalWrite(Pump2, HIGH);
digitalWrite(Pump3, HIGH);
digitalWrite(Pump4, HIGH);
delay(500); ///half a second delay before starting
}
void loop() {
// setting up the watering system
///sending all the information to the relays
Serial.print("Plant 1 - Moisture Level: ");
Sensor1 = analogRead(PP1);
Serial.println(Sensor1);
Serial.print("Plant 2 - Moisture Level: ");
Sensor2 = analogRead(PP2);
Serial.println(Sensor2);
Serial.print("Plant 3 - Moisture Level: ");
Sensor3 = analogRead(PP3);
Serial.println(Sensor3);
Serial.print("Plant 4 - Moisture Level: ");
Sensor4 = analogRead(PP4);
Serial.println(Sensor4);
// The loop to water the system and check the sensors
if (Sensor1 > 450 and Sensor4 > 450) {
if(Sensor2 > 450 or Sensor3 > 450){
// Loop to make sure the plant doesn't get watered more than 1 time every 3 days
if (MTS > interval){
digitalWrite(Pump1, LOW);
digitalWrite(Pump2, LOW);
digitalWrite(Pump3, LOW);
digitalWrite(Pump4, LOW);
Serial.println("Watered");
delay(6000); // water the plants for 6 seconds
MTS = 0;
}}}
else{
digitalWrite(Pump1, HIGH);
digitalWrite(Pump2, HIGH);
digitalWrite(Pump3, HIGH);
digitalWrite(Pump4, HIGH);
}
if (MTS = 0){
digitalWrite(Pump1, HIGH);
digitalWrite(Pump2, HIGH);
digitalWrite(Pump3, HIGH);
digitalWrite(Pump4, HIGH);
}
delay(60000); //delay 1 minute
MTS = (MTS + 1);
}
The code is built to water the plant once each moisture sensor reads a value over a certain amount. Because of all the sensors being in the same box, I decided that the system shouldn't activate unless three of the four sensors noted that plant should be watered. The values of each sensor don't correlate to the units of moisture. They are readings of voltages that have been calibrated. Sensor 1 and Sensor 4 are the two long cabled sensors and near the far ends of the bin while sensors 2 and 3 are near the middle. I inferred that sensors 2 and 3 would be relatively similar being near the center of system so as long as sensors (1, 4, and 2 or 3) read that the the pumps should activate, all of the pumps will turn on.
To calibrate each sensor, the system was ran and the sensors printed out what voltage was measured while being in soil and a glass of water. The soil measurement is noted as the maximum level the sensor could read and the glass of water was the minimum measurement. Each sensor luckily recorded the same measurements so the system has a common variable.
It's not healthy to water plants more than 2 - 3 times a week so a variable called MTS was created to keep track of how long since the last time the system activated the pumps. The code starts MTS at zero and after every loop of reading the sensors MTS increases by 1. There is another variable called interval which represents how many minutes have to pass until the system is allowed to water again. MTS and interval are both measurements of time in minutes since there is a 60 second delay between each loop.
The other thing to calibrate was how long the system should turn the pumps on to sufficiently water the plants. When everything was created, a pump was turned on until it filled a quarter of a cup and then turned off. The time for long it took for the cup to be filled was measured and that determined how long of a delay there should be to keep the pumps on. After the delay, MTS was set back to zero to restart the clock. There is also an additional if statement (MTS = 0) to turn off the pumps since there is a minute delay in between each loop.
Putting It Together
Once everything was calibrated and working together, It was time to give the parts their new home. Each wire was wrapped with electrical tape to secure connections and the Arduino, battery, and relay were placed within a waterproof case.
Like I mentioned before, I wanted the project to look aesthetically pleasing so I cleaned out an old Clorox wipes container and repurposed it to be the hidden water reserve. I put all the pumps inside and closed the lid. The container still had to have access to fill it with water so a hole was punched in the top and a funnel was placed. The container was wrapped with tape to cover all the openings and limit how much soil would be able to mix with the water.
This part of the project is most definitely makes shift, but it all works. It will all also be covered by soil besides the funnel so it's not much of an eye sore, just probably not as efficient as it could be with the space.
The Finished Product
In the end, the project looks good. I don't think I love it yet but it is an amazing prototype. In the pictures I took one of the water pumps out from underneath to show some friends how it worked.
I will be working on this more. Some Improvements that I would make are:
- Find a better water reserve that is longer width wise than height and attach a tube on the end that is less noticeable than the red funnel in the middle.
- Create casing for the top part of the sensors so they can be buried in the soil along with everything else for a cleaner look.
- Clean up the code. I've noticed that there is some repetition in that is unnecessary. I would also switch the Arduino to one that also has wifi capability and program it to work with apple home software. If data could appear on my phone that would be much more convenient.
- Think of a new way to store the Arduino and other components in the pouch. It may require a different designed bin or a better way to store it under the soil but still being able to access it.