As you’re already aware from the title of this post, it isn’t like most of my other ones. This is more of my engineering side. I have some plants around my apartment and while we were prepping for vacation to the Philippines I thought, “how will my plants get watered?”, and immediately started to do some searching around on the internet for a solution. I knew I could do something with an Arduino micro-controller, but wasn’t sure exactly what I had to get to make it happen.

After multiple attempts at the setup, I have finally got it figured out. Now I just need to tweak the settings a bit to make sure that I don’t water my Jade Plant too often and eventually kill it.

Basically what the setup does, is this.

Check the moisture level using a (digital and analog sensor) in the soil of the plant every 30 minutes (timeframe easily changeable in the code) Based on a calibrated reading of a “moist” sensor vs a “dry” sensor, the analog reading gets measured and then reports out 0-100% of moisture The code then divides that number by 10 and blinks a blue LED that number of times. (example, if the moisture level is at 50%, the LED blinks 5 times) I did this just as a way to know what the moisture level is without having to use an LCD display or my computer hooked up all the time Based on a digital reading from the sensor (output is either “dry” or “wet”), a counter will start to increment. If the reading is “dry”, the counter will increment by 1. Once the counter reaches a value of 5, it will water the plant for a specified duration, from a gravity fed water source. The water source is controlled using a servo motor to pinch off a clear plastic tubing line and stop the flow of water, or relieve it to start the flow of water.

To accomplish this task, clearly there is some equipment to purchase and some code work to be done. I have the code pasted below my list of items I used.

The wiring of the sensor, motor, and LED are all somewhat intuitive based on the code and can be modified to your liking.

I had to use a pen to sturdy the hose initially, but I will likely cut it out of the equation as it isn’t needed anymore. I had to have the hose end in a position higher than the water level of the container at first because the hose was not kinking properly to fully seal off the water flow. Now it seals with some better adjustment of the hose placement using a paperclip through the box to secure it.

If you have any questions about the setup or troubleshooting, don’t hesitate to get in touch.

Item list:

Bottle, Hose, Servo, and box I used as a fixture Moisture sensor controller Moisture sensor in my jade plant side view of the box I used to hold everything top of the box where I have my LED setup for blinking the number of moisture

Arduino Code:

//———–Start All Code Here————-

#include <Servo.h>

Servo waterServo; //creates the name of servo

int val = 0; //holds the value of the digital sensor reading

int val2 = 0; //used to activate the watering after 5 loops of being “dry”

int servoPin = 3; //sets servo pin, must be a PWM pin for activating servo position

int waterPosition = 110; //watering position of the servo, in degrees from vertical

int waterHold = 0; //holding position to return to when done watering

int output_value; //this is the output value used in the analog sensor measurement of moisture

int sensor_pin = A0; //this is the analog input on the board from the sensor

//———————————

void setup() {

pinMode(4,INPUT); //enable digital pin 4 for sensor input readings

pinMode(7,OUTPUT); //enable digital pin 7 output for sensor power

pinMode(13,OUTPUT); //enable on-board LED

Serial.begin(9600); //start serial output at 9600 bitrate – for readings

delay(50);

Serial.println(“Starting Code”); //notes in serial monitor

waterServo.attach(servoPin); //sets the servo pin as output

delay(50);

waterServo.write(waterHold); //sets the servo to the holding position specified at start

digitalWrite(7,HIGH); //set PIN 7 high to power the moisture sensor

}

//———————————

void loop() {

//digital

delay(1800*1000);

/*include commented out “000);” in order to include the

30 minute delay between readings*/

//analog reading of moisture levels from sensor

output_value= analogRead(sensor_pin);//read analog values from sensor

output_value = map(output_value,980,250,0,100);//map analog raw values to the scale of the sensor

Serial.print(“Moisture: “); //print in serial monitor

Serial.print(output_value);

Serial.println(“%”);

output_value = output_value/10; //divide output_value by 10 for LED blinking purposes

for (int led=0;led<=output_value;led++){

digitalWrite(13,1);//turn on the on-board LED (and the wired LED if using one)

delay(250);

digitalWrite(13,0);//turn off the on-board LED (and the wired LED if using one)

delay(250);

}

val = digitalRead(4); //read soil moisture sensor digital output

//Serial.println(val);

if(val == 1){ // if soil is dry, increment val2 in order to keep from watering too often

val2++;// = val2 + 1;

}

if(val2 == 5){ //if soil is dry for 5 consecutive readings, add water

waterServo.write(waterPosition); //start watering

delay(2*1000); //allow watering to occur for 2 seconds

val2 = 0;

//——

//this is used to make the servo less jerky

//when returning to original position to stop water flow

for (int s=waterPosition; s>=waterHold; s–){

waterServo.write(s);

delay(10);

} //end of for loop to control servo return speed

//——

}// end of if statement to check for 5 consecutive readings of “dry” condition

}//end of loop

//———–End All Code Here————-