Automatic Watering System for Plants

by allaine_sioson in Living > Gardening

48 Views, 0 Favorites, 0 Comments

Automatic Watering System for Plants

IMG_2522.jpeg

This is an automatic plant watering system, it detects when the soil is too dry for the plant and refills the water. It also has an ultrasonic sensor to detect the level of the water in the tank if it needs to be refilled and a TMP sensor to detect the temperature of the surroundings and if it's too hot or cold for the plant.

Supplies

Materials:

  1. Arduino UNO
  2. 1x Breadboard
  3. 1x Soil Moisture Sensor
  4. 1x Ultrasonic Sensor
  5. 1x TMP Sensor
  6. 1x 330Ω Resistor
  7. 1x RGB LED
  8. 1x I2C LED
  9. 1x Micro Servo
  10. 1x Plant Pot
  11. 1x Water/Soda Bottle
  12. 1x Straw (Metal)
  13. 12x Wooden Blocks (3in x 1in x 1in)


Materials for Construction:

  1. Hot Glue
  2. Duct Tape
  3. Electrical Tape
  4. Masking Tape
  5. String


Tools Required:

  1. Hot Glue Gun
  2. Box Cutter
  3. Scissors
  4. Paint (design purposes)

Wiring the Ground/Power

Screenshot 2025-01-15 032833.png

Wiring the breadboard to the Arduino UNO:

  1. To connect the breadboard to the power, insert a robot wire pin into the 5V port in the Arduino. The opposite end pin goes into the positive spot in the breadboard. (Please view red wire connected to the Arduino for reference)
  2. To connect the breadboard to the ground, insert a robot wire pin into the GRD port in the Arduino. The opposite end pin goes into the negative spot in the breadboard. (Please view black wire connected to the Arduino for reference)


Connecting both sides of the breadboard:

  1. Since we will be using the other half of the breadboard too, we will connect both sides with wires. Plug a wire into the positive spot on the breadboard and the other end of the wire into the opposing positive spot on the breadboard. (Please view red wire on the right side for reference)
  2. Then, plug a wire into the negative spot on the breadboard and the other end of the wire into the opposing negative spot on the breadboard. (Please view black wire on the right side for reference)
  3. This will allow anything plugged into the other half of the breadboard to reach the Arduino.

Create a Lantern (Status Indicator)

unpainted lantern.jpg
lantern w paint.jpg

Creating the Base:

  1. Glue 3 wooden blocks together with hot glue to act as the base of the lantern.
  2. Attach 1 wooden block standing vertically on each corner of the base with hot glue, these will act as the pillars of the lantern.
  3. Then, repeat step one and hot glue it to the top of the pillar blocks.
  4. Glue the final 2 pieces of wood on top, placing it in the centre.


Attaching the RGB LED:

  1. Place the RGB LED inside the lantern, bend the wires so that it sticks out of the lantern while the LED stands upright inside.
  2. Attach robot wires to the LED pins and tape them together with electrical tape.
  3. Hot glue the electrical taped section onto the base.


Designing (OPTIONAL):

  1. Paint the "pillar blocks" with brown paint and the base and top sections with dark grey paint.
  2. Place masking tape on top of each gap to mimic the tinted window of the lantern, allowing the light to pass through but hides the RGB LED.

Wiring the Lantern

Screenshot 2025-01-15 034343.png

Wiring the LED to the breadboard:

  1. Attach the red pin of your LED with a wire into the i3 spot of the breadboard.
  2. Attach the blue pin of your LED with a wire into the i5 spot of the breadboard.
  3. Attach the green pin of your LED with a wire into the i6 spot of the breadboard.


(NOTE: If your LED appears to be cloudy / translucent, you most likely have a common anode, if it's clear, then it's a common cathode.)

If you have a common CATHODE:

  1. If you have a cathode LED plug your one of your resistor pins into the negative spot and the other in j4.
  2. Attach the GRD pin of the LED with a wire into the i4 spot of the breadboard.

If you have a common ANODE:

  1. If you have an anode LED, plug your one of your resistor pins into the positive spot and the other in i4.
  2. Attach the POWER pin of the LED with a wire into the h4 spot of the breadboard.


Wiring to the Arduino:

  1. To connect the red pin of the LED to the Arduino, insert a wire into digital pin 4 and the other end of the wire into the h3 spot of the breadboard.
  2. To connect the blue pin of the LED to the Arduino, insert a wire into digital pin 3 and the other end of the wire into the h5 spot of the breadboard.
  3. To connect the green pin of the LED to the Arduino, insert a wire into digital pin 2 and the other end of the wire into the h6 spot of the breadboard.

Creating the Water Tank / Dispenser

unnamed.jpg

Building the Tank / Dispenser:

  1. Cut 1/2in to 1in off either the top or the bottom of the bottle with a cutter. (I cut off the bottom)
  2. Attach a micro servo onto the side of the bottle where the dispenser would be located, hot glue it 1/2in below the top of the tank.
  3. Create a small hole wherever you'd like the "dispenser" part of the water tank to be and put a straw through the hole.
  4. Hot glue or tape the straw to one end of a string and the other end to the servo. (please make sure that when you attach it, the servo horn is standing upright and the string is glued to the bottom end of the horn.)
  5. Place hot glue in the gaps between the straw and the bottle to prevent leakage.
  6. Attach an ultrasonic sensor to the very top of the tank, facing inside the tank to monitor the water level. Tape it with electrical tape.


Designing (OPTIONAL):

  1. Place masking tape around the bottle.
  2. Paint the bottle brown.
  3. Paint dark brown lines vertically across the bottle.
  4. Paint on 2 black horizontal lines / place 2 black tapes horizontally around the bottle.

Wiring the Water Tank / Dispenser

Screenshot 2025-01-15 043812.png

Wiring the Ultrasonic Sensor to breadboard:

  1. Attach the Ultrasonic sensor's POWER pin to the breadboard with a wire into the positive spot on the breadboard.
  2. Attach the Ultrasonic sensor's GRD pin to the breadboard with a wire into the negative spot on the breadboard.
  3. Attach the Ultrasonic sensor's TRIG (Trigger) pin to the breadboard with a wire into the j10 spot on the breadboard.
  4. Attach the Ultrasonic sensor's ECHO pin to the breadboard with a wire into the j11 spot on the breadboard.


Wiring the Micro Servo to breadboard:

  1. Attach the Micro servo's POWER pin to the breadboard with a wire into the positive spot on the breadboard.
  2. Attach the Micro servo's GRD pin to the breadboard with a wire into the negative spot on the breadboard.
  3. Attach the Micro servo's SIGNAL pin to the breadboard with a wire into the j23 spot on the breadboard.


Wiring to the Arduino:

  1. To connect the Ultrasonic sensor's TRIG pin, insert one end of a wire to the digital 9 pin on the Arduino and the other end into the i10 spot on the breadboard.
  2. To connect the Ultrasonic sensor's ECHO pin, insert one end of a wire to the digital 8 pin on the Arduino and the other end into the i11 spot on the breadboard.
  3. To connect the Micro servo's SIGNAL pin, insert one end of a wire to the digital 11 pin on the Arduino and the other end into the i23 spot on the breadboard.

Wiring the TMP Sensor

Screenshot 2025-01-15 045146.png

Wiring the TMP Sensor :

  1. Attach the TMP sensor's POWER pin to the breadboard with a wire into the positive spot on the breadboard.
  2. Attach the TMP sensor's GRD pin to the breadboard with a wire into the negative spot on the breadboard.
  3. Attach the TMP sensor's Centre pin to the Arduino with one end of the wire into the analog input pin 0 (A0) port on the Arduino and the other end into the a4 spot on the breadboard.

Wiring the Button

Screenshot 2025-01-15 045537.png

Wiring the Button :

  1. Attach each pin of the button to the breadboard in spots f13, f15, e13 and e15.
  2. Connect one of the button's "a" terminal pins to the Arduino with one end of the wire into the digital pin 5 port on the Arduino and the other end into the g15 spot on the breadboard.
  3. Connect the diagonal opposing pin of the previous "a" pin to the breadboard with one end of the wire into the negative spot on the breadboard for GRD and the other end into the d13 spot.

Wiring the Soil Moisture Sensor

Screenshot 2025-01-15 075416.png

Wiring the Soil Moisture Sensor:

  1. Attach the sensor's POWER pin to the breadboard with a wire into the c20 spot on the breadboard.
  2. Attach the sensor's GRD pin to the breadboard with a wire into the negative spot on the breadboard.
  3. Connect the Arduino to the sensor's power with one end of the wire into the digital pin 10 port on the Arduino and the other end into the d20 spot on the breadboard.
  4. Connect the Arduino to the sensor's signal pin with one end of the wire into the analog input pin 1 (A1) port on the Arduino and the other end into the signal pin of the sensor.

Wiring the I2C LCD

Screenshot 2025-01-15 050429.png

Wiring the Display:

  1. Attach the display's POWER pin to the breadboard with a wire into a positive spot on the breadboard.
  2. Attach the sensor's GRD pin to the breadboard with a wire into a negative spot on the breadboard.
  3. Connect the Arduino to the sensor's SDA pin with one end of the wire into the analog input pin 4 (A4) port on the Arduino and the other end into the SDA pin of the sensor.
  4. Connect the Arduino to the sensor's SCL pin with one end of the wire into the analog input pin 5 (A5) port on the Arduino and the other end into the SCL pin of the sensor.

Coding the Project

Copy paste this code into the Arduino IDE.

#include <LiquidCrystal_I2C.h>
#define ANALOGREFVOLTAGE 5.555
#include <Wire.h>
#include <Servo.h>

LiquidCrystal_I2C lcd(32, 16, 2);

Servo servo;

int tmp = A0;

int red = 4;
int blue = 3;
int green = 2;

int moistSensor = A1;
int moistPower = 10;

int moisture;

int trig = 9;
int echo = 8;

int pingTravelTime;
float pingTravelDistance;
float distanceToTarget;

int button = 5;
String mode = "C";


int lastState = HIGH; // previous state from the input pin
int currentState; // current reading from the input pin

void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
servo.attach(11);
pinMode(trig,OUTPUT);
pinMode(echo,INPUT);
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(green, OUTPUT);
pinMode(moistPower, OUTPUT);
pinMode(button, INPUT_PULLUP);
}

void loop() {
// power on sensor and wait briefly
digitalWrite(moistPower, HIGH);
delay(10);
// take reading from sensor
moisture = analogRead(moistSensor);
// turn sensor off to help prevent corrosion
digitalWrite(moistPower, LOW);
currentState = digitalRead(button);

if (lastState == HIGH && currentState == LOW) {
if (mode == "C") {
mode = "F";
} else {
mode = "C";
}
}
// save the last state
lastState = currentState;
digitalWrite(trig,LOW);
delayMicroseconds(10);
digitalWrite(trig,HIGH);
delayMicroseconds(10);
digitalWrite(trig,LOW);
pingTravelTime=pulseIn(echo,HIGH);
delay(25);
pingTravelDistance=(pingTravelTime*765.*5280.*12)/(3600.*1000000);
distanceToTarget=pingTravelDistance/2;
if (distanceToTarget <= 3.5) {
lcd.clear();
lcd.print("REFILL WATER");
color(red, blue, green, "yellow");
delay(1000);
} else {
float currentTemp = 0;
currentTemp = getVoltage(tmp);
float temp = getTemp(currentTemp, mode);

display(temp,mode,moisture);
Serial.print(mode);
Serial.print(" , ");
Serial.println(temp);
delay(1000);
}
}
float getVoltage(int pin) {
return(float(analogRead(pin))* float(ANALOGREFVOLTAGE/1023.000));
}

float getTemp(float temp, String mode) {
float c = (temp-.5808)*100;
if (mode == "C") {
return c;
} else if (mode =="F") {
return (c * 9/5) + 32;
}
}

void color(int red, int blue, int green, String color) {
if (color == "red"){
analogWrite(red, 255);
analogWrite(blue, 0);
analogWrite(green, 0);
} else if (color == "blue") {
analogWrite(red, 0);
analogWrite(blue, 255);
analogWrite(green, 0);
} else if (color == "green") {
analogWrite(red, 0);
analogWrite(blue, 0);
analogWrite(green, 255);
} else if (color == "yellow") {
analogWrite(red, 255);
analogWrite(blue, 0);
analogWrite(green, 255);
}
}

void moistureLevel(int lvl) {
// "wet" and "dry" thresholds - these require calibration
int wet = 800;
int dry = 500;
if (lvl >= wet) {
lcd.setCursor(0,1);
lcd.print("TOO WET");
} else if (lvl <= dry) {
lcd.setCursor(0,1);
lcd.print("TOO DRY");
}
if (moisture < wet-100) {
servo.write(0);
} else {
servo.write(180);
}
}

void display(float temp, String mode, int lvl) {
// "hot" and "cold" thresholds
float hot = 26.00;
float cold = 4.44;
lcd.clear();
// too hot
// add more water
if (temp > hot) {
color(red, blue, green, "red");
lcd.print(mode);
lcd.print(": ");
lcd.print(temp);
lcd.print(" | ");
lcd.print("HOT");
moistureLevel(lvl);
// too cold
// do not give water if too cold
} else if (temp < cold) {
color(red, blue, green, "blue");
lcd.print(mode);
lcd.print(": ");
lcd.print(temp);
lcd.print(" | ");
lcd.print("COLD");
moistureLevel(lvl);
} else {
color(red, blue, green, "green");
lcd.print(mode);
lcd.print(": ");
lcd.print(temp);
moistureLevel(lvl);
}
}