In this simple Arduino project, a specified volume of water is supplied daily to indoor plants using a hose pump.
The timer, which would allow setting when to water the plants, is not used here. Instead, the device measures the intensity of daylight, and watering occurs as soon as it starts to darken.
Project scheme
The schematic diagram of this project is shown in the figure below. The MР8А14 transistor is used by Arduino to turn the pump motor on and off. The diode DI provides protection against negative voltage spikes.
In the left part of the diagram, we see a photoresistor and a fixed resistor that form a voltage divider for measuring light intensity on the A0 analog pin of the Arduino board. The more light hits the photoresistor, the lower its resistance, so the voltage at pin A0 increases up to 5V.
Assembling such a project is very simple. It is unlikely that wires will already be attached to the motor of your pump to the output contacts, so all the soldering that needs to be done here will involve soldering the corresponding mounting wires to the pump motor.
Components
In this Arduino project, you will need the following components:
Arduino Uno
Q1 - Composite transistor MР8А14 R1, R3 - 1 kOhm resistor
R2 - 1 kOhm photoresistor
D1 - 1N4001 diode
Hose pump 12V
400-point solderless breadboard
Jumper wires "male to male" (for Arduino only)
Tube for insertion into the pump, 1m
Power supply 12V 1A
Large water container
Mounting wires, soldered to the pump motor
A variety of hose pump used in this project is designed for aquarium use and can be purchased for a very small amount of money.
The tube I used here came with a watering kit I bought at a hardware store. Along with it, I also acquired small plastic connecting sleeves, which are used to connect sections of the tube together. The connections of the tubes must be sealed, otherwise the pump will not work.
Project Assembly
To assemble this project, you will need to work a bit with the breadboard and securely attach the water container manually.
Step 1. Solder wires to the motor
Solder mounting wires to the pump motor contacts, if they are not already there. The wires should be long enough to reach from the pump to the breadboard and Arduino. Half-meter wires will be sufficient.
Step 2. Assemble the breadboard
Place the project components on the breadboard as shown in the diagram. Make sure the transistor and diode are installed correctly.
Step 3. Attach the tube to the pump
You will need two pieces of tubing. One should submerge into the water container to its full depth, reaching from the pump mounting hole located at the top of the container to the bottom. The second one should run from the pump's outlet hole to the plant you intend to water. The pump and tubes are shown in close-up in the image.
The input and output of the pump are usually not marked, but hose pumps can move liquid in both directions. Therefore, if you notice that the pump is sucking in water instead of pumping it, it is better to resolder the mounting wires on the motor rather than rearranging the tubes.
I decided that it would be convenient to insert the pump into the water container from the top and glue the motor to the pump. The input tube then goes straight into the container, while the output tube protrudes from the side and is directed towards the plant. To insert the pump, I had to trim the neck of the milk bottle I used a bit.
The image shows the design I ended up with, but you can certainly install the pump at the bottom, next to the breadboard. However, in that case, you will need a longer tube.
Program
The Sketch with which I calibrated the light sensor:
Code: Select all
const int lightPin = A0;
void setup() {
Serial.begin(9600);
}
void loop() {
int lightReading = analogRead(lightPin);
Serial.println(lightReading);
delay(500);
}
Arduino Sketch for this project:
Code: Select all
const int motorPin = 9; // (1)
const int lightPin = A0;
const long onTime = 10 * 1000; // 60 seconds (2)
const int dayThreshold = 200; // (3)
const int nightThreshold = 70;
boolean isDay = true; // (4)
void setup() {
pinMode(motorPin, OUTPUT);
}
void loop() { // (5)
int lightReading = analogRead(lightPin);
if (isDay && lightReading < nightThreshold) { // it went dark (6)
pump();
isDay = false;
}
if (!isDay && lightReading > dayThreshold) { // (7)
isDay = true;
}
}
void pump() { // (8)
digitalWrite(motorPin, HIGH);
delay(onTime);
digitalWrite(motorPin, LOW);
}
Let's clarify some points in the sketch using the line markings provided in the comments:
1. The sketch starts by defining constants for the two Arduino pins used: the pin for controlling the motor and the analog input pin (
lightPin) where a photoresistor is used to measure light intensity.
2. The constant onTime specifies how long the pump should remain on each night. When testing the project, a brief period, such as 10 seconds, can be set here to avoid long waiting times.
The most interesting part of the sketch is where we determine that it has become dark outside. Since the Arduino board does not have built-in clocks, it cannot determine the time unless an RTC (real-time clock) is added to the project. In this project, I plan to water the plant once a day, so the onset of dusk is the most suitable factor for triggering the pump. After watering, you do not intend to water the plant until the next dusk, i.e., until the day ends.
3. To make it easier to distinguish between night and day, two constants,
dayThreshold and
nightThreshold, are defined. These values may need to be adjusted depending on the placement of the plant pot and the sensitivity of your photoresistor. The fundamental idea is this: if the current light value is above
dayThreshold, it is daytime, and if it is below
nightThreshold, it is nighttime. You may wonder why there are two constants instead of just one. The reason is that during dusk, when it is just starting to get dark, the light level may fluctuate around the threshold value for some time, causing the device to trigger multiple times.
4. The boolean variable
isDay holds the answer to whether it is currently day or not. If
isDay is
true, then from the watering setup's perspective, it is daytime.
5. The logic for determining whether it is time to water the plants is encapsulated in the
loop function. It takes the light intensity value as an input.
6. If it is currently day but the light intensity value is below
nightThreshold, it indicates that dusk has just fallen - triggering the watering function. Subsequently, the
isDay variable is set to
false, signifying that night has arrived, and watering should be stopped for now.
7. The second
if statement in the
loop checks if it is currently night (
isDay) and if the light intensity value does not exceed the
dayThreshold. If both conditions are met,
isDayis set to
true.
8. Finally, the
pumpfunction turns on the pump, waits for the period specified in
onTime, and then turns off the pump.
Download and run the program
Before starting the main part of the project, it is necessary to upload a test program to the Arduino - this will help to adjust suitable values for
dayThreshold and
nightThreshold. So, upload this sketch to the Arduino and open the serial monitor.
A series of values corresponding to the current light intensity should appear on the serial monitor every half a second. Note the light intensity value during a very cloudy day. Approximately half of this value should match the
dayThreshold- this way, our device will work correctly even on the cloudiest days.
Next, wait for dusk near the plant pot, and again take readings. You can try to guess or simply cover the light sensor with your finger.
Double the obtained value and set the result as the
nightThreshold. Note:
nightThresholdshould be significantly lower than
dayThreshold. Some compromises may be needed when evaluating these two values.
Now you can adjust the values of
dayThresholdand
nightThresholdin the actual sketch and upload it to the Arduino.
To simulate the onset of dusk, cover the photoresistor with your finger again - the pump should activate and operate for the specified period.
The pump I worked with delivered around 90 ml/min. To determine the duration of watering, use a stopwatch and measuring cup. This will help you determine the volumetric flow rate of your pump and adjust the
onTimevalue so that the plant receives the right amount of water.