How to make an automatic watering system for your plant with an Arduino board and a humidity sensor
I don't know about you, but I love plants. I have 3 of them at home that I water every 2 days with no exception. When I live the house for a couple of days or a week, it's always heartbreaking seeing the plant so dried and the ground as well. I think some of you can related to what I'm talking about. So what can be solution for this at good price and how to make a watering system at home.
Humidity sensor
In the electronics world, we have what we call sensors. You have different types (light sensors, pressure sensors, speed sensors, gas sensors and much more). But today we will focus on the the humidity sensor. As the name says it, it can give us the humidity rate in an chosen environment.
Water pump (YL-69)
This done, when we have set a threshold for the exact humidity rate we want, we have to activate a water pump to extract water from a recipient and pour a certain amount of water in our plant or maybe during a certain time.
All this will be a very way to build an automatic watering system for your plant when you are away from home and maybe avoiding the programmed death of your plant.
H-bridge to control the water pump (L-298N)
We could connect the water pump directly the Arduino like we do for the diode, sensors and even inputs. The only issue is that motors in general consume too much currents. Let see it this way, the Arduino board gives the orders and the H-Bridge (L-298N) furnishes the arms (In our case the necessary current for the DC motor for our water pump that feed the watering system). Between 500 and 900 mA for a voltage of 1.5 to 3 Volts.
Materiel to build the automatic watering system with an Arduino board
Your first need to gather all the following materiel (Click on them to buy them online on Amazon):
An Arduino Uno board or Arduino Mega (depending of what you have home, but there is no difference)
Jumper wires
All the links can be found if you want to buy them and make your own watering system with the Arduino board.
Schematic of the automatic watering system
Explanation of the wiring of the automatic water system
The 9V battery is connected to the H-bridge (That furnishes the power to the motor) to the pins "GND" and "+12V".
The power supply for the Arduino is produced by the H-bridge on the "+5V" pin. This pin is connected to the "Vin" on the Arduino Uno board.
The humidity sensor analog pin is connected to the analog pin "A0" of the Arduino board input. This input receives value from 0 to 1023. 0 being the minimum and 1023 the maximum. So We can put a threshold between 0 and 1023 where we want to trigger the detection of the humidity depending of the soil and what we are expecting as a result. It usually triggers around 800 when the tip of the sensor is in water and keep decreasing when we plunge the humidity sensor deeper into water or that we have a more humid sensor. We can try (400, 600, 800, 900, 1000, etc). You can decide and give it some testing as well if you want to test for yourself or learn a little bit.
The motor control pins on he H-bridge are "in1", "in2" and "EnA". These pins are respectively connected like this to the Arduino board (Pin 7, Pin 8 and Pin 9).
Code of the entire watering system (Arduino)
The following code can be inserted into the Arduino IDE then uploaded to the Arduino board
// Soil moisture sensor
int Moisture_pin = A0;
// Motor A
int enA = 9;
int in1 = 7;
int in2 = 8;
// you can adjust the threshold value
int Thresthold_moisture = 700;
void setup(){
pinMode(Moisture_pin, INPUT);
pinMode(in1, OUTPUT);
pinMode(in2, OUTPUT);
pinMode(enA, OUTPUT);
Serial.begin(9600);
}
void loop() {
// read the input on analog pin 0:
int sensorValue = analogRead(Moisture_pin);
Serial.print(sensorValue);
if(sensorValue < Thresthold_moisture)
{
// Turn off motor
digitalWrite(in1, LOW);
digitalWrite(in2, LOW);
// Set speed to zero
analogWrite(enA,0);
}
else
{
// Turn on motor
digitalWrite(in1, HIGH);
digitalWrite(in2, LOW);
// Set speed to to the motor. Test what work better for us
analogWrite(enA, 200);
delay(3000);
}
delay(500);
}
How to test it
To test the the overall schematic, we need to upload the above code to the Arduino Uno board with the Arduino IDE.
Connect all the electronic components (Humidity sensor, battery, motor and others) to the Arduino board.
Keep the Arduino board connected to the computer with a USB cable to see the threshold is reached
Look for a really dry soil. So we can try different thresholds like mentioned before (400, 500, 600, etc).
Look on the Arduino Terminal when the threshold is reached.
When reached, the water pump should be triggered and start pumping water to our plan
The system can be set to work automatically for a quite while with enough water in a small stank
Possible improvement of the project
This project ban be set to work every day at a certain time.
This project can be set to work at a certain threshold of the humidity sensor. The code can be changed in the Arduino IDE
Let me know your suggestions or if you have any details for any improvement of the project.
Video of the water pump in action
Follow on the Facebook and the newsletter for weekly activities
Don't forget to subscribe to the newsletter (at the bottom of the page) and the Facebook group if you want more weekly STEM related activities. Such as: electronics, 3D printing, chemistry, coding, robotics and more. If you want to learn how to make a robot, learn how to code, Learn how to make a video game and how to use electronics, please join the newsletter and the Facebook group(Create and build and learn STEM with fun projects).
See you soon for another STEM related article.
Comments