DIY Plant Moisture Sensor With Automatic Watering System

Introduction: DIY Plant Moisture Sensor With Automatic Watering System

Hi everyone,

Today I'm going to share my first Arduino project with you. I'm a Belgian multimedia student and for the course physical computing and digital making, we had to experiment at home with a project of our choice. I'm a huge plant lover, so why not do something to keep them happy?

This project consists of:

- A DIY soil moisture sensor with RGB led

- A liquid crystal display to indicate the status of your plant

- A way to automate the watering of your plant, based on the readings.

I learned a lot from this project and I hope I can help you with your challenges.

These projects gave me inspiration and helped me a lot:

- https://millermansprojects.blogspot.com/2018/11/di...

- https://www.makerguides.com/character-lcd-arduino-...

- https://www.instructables.com/id/DIY-SOIL-MOISTURE...

- https://www.instructables.com/id/No-Pump-Automatic...

Cheers!

Supplies

What you'll need for this project:

- An Arduino UNO

- Breadboard (I used two small ones)

- Nuts and bolts

- A lot of jumper wires

- 1x RGB led

- 4x 330 ohm resistor (220 ohm is also fine)

- 1x 10k ohm resistor

- 1x potentiometer

- 1x liquid crystal display

- 1x Servo Motor

- USB cable

- hard plastic you put holes through to keep your nuts and bolts about 2.5 centimetres apart.

Step 1: Start to Build Your DIY Moisture Sensor

Did you know that you could build a reliable moisture sensor with nuts and bolts? Current is passed through the probes and the resistance level is read to measure the moisture of the sensor. More water makes the soil conduct electricity more easily (less resistance), while dry soil conducts electricity more poorly (more resistance). Read more about this type of sensor: https://gardenbot.org/howTo/soilMoisture/

Now, these sensors are built very easily:

1. Take your jumper wire and slide the end between the nut and head of the bolt.

2. Tighten the nut until you are unable to pull the jumper wire.

3. You have to repeat this step twice. In the end, you should have two prongs.

4. Use a hard piece of plastic and poke two holes through it that are about 2.5 centimetres apart (1 inch). This is important for the readings.

Step 2: Build the Circuit and Calibrate the Sensor

Here we are going to wire the first layer of our project. Build the circuit and add the code. Here you'll need a 10k ohm resistor.

int moistPin = 0;

int moistVal = 0;

void setup()

{

Serial.begin(9600);

}

void loop()

{

MoistVal = analogRead(moistPin);

Serial.println(moistVal);

delay(250); //for stability

}

In this step, we are going to calibrate the moisture sensor. Open the terminal and take a look at the readings. If you put the prongs in the air you should see 0 or 1. Now submerge your prongs in water, this reading should be your maximum moisture value. Use these values to determine your dry level, ideal level and moist level.

Now you can implement these values in your code:

int moistPin = 0;
int moistVal = 0;
int tooDry = 176.6; // 20% of my maximum value 883. Your value can be different.

int tooWet = 706.4 // 80% of my maximum value 883. Your value can be different.

void setup()

{

Serial.begin(9600);

}

void loop()

{

MoistVal = analogRead(moistPin);

Serial.println(moistVal);

if (moistVal <= tooDry){

Serial.print("this plant needs water");

}

else if (moistVal >= tooWet) {

Serial.print("This plant is overwatered");

}

else {

Serial.print("this plant is not thirsty");

}

delay(250); //for stability

}

And always... test test test! On different plants, in water, in the air and look if the readings are accurate.

Step 3: Add the RGB Led to the Circuit

After we calibrated our sensor, we can connect an RGB led to indicate the status of the plant. Here you'll need 3x 330 ohm resistors (or 220 ohm, depends on how bright you want the LED light to be)

Here is the addition to the code:

int moistPin = 0;
int moistVal = 0;
int tooDry = 176.6; // 20% of my maximum value 883. Your value can be different.
int tooWet = 706.4 // 80% of my maximum value 883. Your value can be different.

int redPin = 13;
int greenPin = 11;
Int bluePin = 12;

void setup()

{

Serial.begin(9600);
pinMode(redPin, OUTPUT); //declare your digital pin
pinMode(greenPin, OUTPUT); //declare your digital pin
pinMode(bluePin, OUTPUT); //declare your digital pin

}

void loop()

{

MoistVal = analogRead(moistPin);
Serial.println(moistVal);

if (moistVal <= tooDry){

Serial.print("this plant needs water");
digitalWrite(redPin,HIGH); // red LED will light up
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,LOW);

}

else if (moistVal >= tooWet) {

Serial.print("This plant is overwatered");
digitalWrite(redPin,LOW);
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,HIGH); // blue LED will light up

}

else {

Serial.print("this plant is not thirsty");
digitalWrite(redPin,LOW);
digitalWrite(greenPin,HIGH); // green LED will light up
digitalWrite(bluePin,LOW);

}

delay(250); //for stability

}

Step 4: Connect a Liquid Crystal Display

Having the RGB LED turned on is fun and all... But wouldn't it be nicer if the user could read the status from the screen? In this step, we are going to connect an LCD screen that indicates if the plant is happy or not.

You'll need a lot of jumper wires, 330 ohm resistor (or a 220 ohm resistor) and a potentiometer to manage te contrast. Take a look at the circuit and add it to your breadboard. (note: you need to add the knob on the potentiometer, as it's not shown on the schematic of the circuit).

First things first: try to evaluate if your LED works. This tutorial helped me with this: https://www.makerguides.com/character-lcd-arduino-...

Let's include the liquid crystal library. It makes the coding so much easier.

Time to add some more lines to our code:

#include < LiquidCrystal.h >

int moistPin = 0;
int moistVal = 0;
int tooDry = 176.6; // 20% of my maximum value 883. Your value can be different.
int tooWet = 706.4 // 80% of my maximum value 883. Your value can be different.

int redPin = 13;
int greenPin = 11;
Int bluePin = 12;

LiquidCrystal lcd = LiquidCrystal(2, 3, 4, 5, 6, 7); //declare the LCD object

void setup()

{

Serial.begin(9600);
pinMode(redPin, OUTPUT); //declare your digital pin
pinMode(greenPin, OUTPUT); //declare your digital pin
pinMode(bluePin, OUTPUT); //declare your digital pin
lcd.begin(16,2); //dimensions of the LCD

}

void loop()

{

MoistVal = analogRead(moistPin);
Serial.println(moistVal);

if (moistVal <= tooDry){

Serial.print("this plant needs water");
digitalWrite(redPin,HIGH); // red LED will light up
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,LOW);
lcd.setCursor(2, 0);
lcd.print("this plant");
lcd.setCursor(2, 1);
lcd.print("is thirsty");
delay(10000);
lcd.clear();

}

else if (moistVal >= tooWet) {

Serial.print("This plant is overwatered");
digitalWrite(redPin,LOW);
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,HIGH); // blue LED will light up
lcd.setCursor(2, 0);
lcd.print("this plant");
lcd.setCursor(2, 1);
lcd.print("is drowning");
delay(10000);
lcd.clear();

}

else {

Serial.print("this plant is not thirsty");
digitalWrite(redPin,LOW);
digitalWrite(greenPin,HIGH); // green LED will light up
digitalWrite(bluePin,LOW);
lcd.setCursor(2, 0);
lcd.print("this plant");
lcd.setCursor(2, 1);
lcd.print("is happy");
delay(10000);
lcd.clear();

}

delay(250); //for stability

}

Step 5: Final Step: Add a Servo Motor to Automate Your Watering

If you don't have a water pump laying around in your house, then you could be creative by using a servo motor. This instructable gives you a clear overview of the steps you can take to build your own water reservoir and water tube: https://www.instructables.com/id/No-Pump-Automatic...

I ended my project by only connecting the servo motor to my breadboard. Note that a servo motor can only be connected to a PWN pin. Always test if your servo motor works. I used this tutorial: https://www.arduino.cc/en/Tutorial/Sweep . If you are successful then you can add the last few lines to your code. I included an extra status to the LCD when the plant receives water.

#include < LiquidCrystal.h >

#include < Servo.h >

Servo waterReservoir; //declare the servo object
int servoPin = 9;

int moistPin = 0;
int moistVal = 0;

int tooDry = 176.6; // 20% of my maximum value 883. Your value can be different.
int tooWet = 706.4 // 80% of my maximum value 883. Your value can be different.

int redPin = 13;
int greenPin = 11;
Int bluePin = 12;
LiquidCrystal lcd = LiquidCrystal(2, 3, 4, 5, 6, 7); //declare the LCD object

void setup()

{

Serial.begin(9600);
waterReservoir.attach(servoPin);
pinMode(redPin, OUTPUT); //declare your digital pin

pinMode(greenPin, OUTPUT); //declare your digital pin
pinMode(bluePin, OUTPUT); //declare your digital pin
lcd.begin(16,2); //dimensions of the LCD

}

void loop()

{

MoistVal = analogRead(moistPin);
Serial.println(moistVal);

if (moistVal <= tooDry){

Serial.print("this plant needs water");
digitalWrite(redPin,HIGH); // red LED will light up
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,LOW);
lcd.setCursor(2, 0);
lcd.print("this plant");
lcd.setCursor(2, 1);
lcd.print("is thirsty");
delay(10000);
lcd.clear();
waterReservoir.write(180); // # degrees the servo needs to turn
lcd.print("watering...");
delay(10*1000);
lcd.clear();
waterReservoir.write(10);

}

else if (moistVal >= tooWet) {

Serial.print("This plant is overwatered");
digitalWrite(redPin,LOW);
digitalWrite(greenPin,LOW);
digitalWrite(bluePin,HIGH); // blue LED will light up
lcd.setCursor(2, 0);
lcd.print("this plant");
lcd.setCursor(2, 1);
lcd.print("is drowning");
delay(10000);
lcd.clear();

}

else {

Serial.print("this plant is not thirsty");
digitalWrite(redPin,LOW);
digitalWrite(greenPin,HIGH); // green LED will light up
digitalWrite(bluePin,LOW);
lcd.setCursor(2, 0);
lcd.print("this plant");
lcd.setCursor(2, 1);
lcd.print("is happy");
delay(10000);
lcd.clear();

}

delay(250); //for stability

}

Step 6: Final Results

Don't hesitate to leave a comment for suggestions as it is my first instructable or to let me know you tried it yourself. To me, it was a great introduction to Arduino and I'm looking forward to sharing more.

Be the First to Share

    Recommendations

    • First Time Author Contest

      First Time Author Contest
    • Metal Contest

      Metal Contest
    • Fandom Contest

      Fandom Contest

    Comments

    0
    seamster
    seamster

    1 year ago

    Thank you for sharing : )