Rich Noordam
Published © GPL3+

Plant Moisture Monitoring and Watering with LED Indicator

Monitor your plants and let them water themselves when they are thirsty.

BeginnerShowcase (no instructions)8 hours5,904
Plant Moisture Monitoring and Watering with LED Indicator

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
×1
Analog Moisture Sensor
×2
Resistor 330 ohm
Resistor 330 ohm
×3
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×2
watering pump
×2
fish tank tubing
10 ft. for water transfer
×1
2 gallon bucket
2 gallon bucket from Ace Hareward
×2
Jumper wires (generic)
Jumper wires (generic)
×1
Perma-Proto Breadboard Half Size
Perma-Proto Breadboard Half Size
×1
16 MHz Crystal
16 MHz Crystal
×1
Capacitor 22 pF
Capacitor 22 pF
×2
5v relay shield
×2
Dual Row 4 Position Covered Screw Terminal Strip
you could certainly use a less rated Amp one, i had one from previous project.
×1
28 Pin DIP IC Sockets Adaptor Solder Type Socket
×1
ElecFreaks solid hookup wire
×1
9V 1A Switching Wall Power Supply
9V 1A Switching Wall Power Supply
×1
5v 2A power supply
old phone charger (samsung)
×1
3 mm LED: Red
3 mm LED: Red
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Hand Drill
3/16'' drill bit
Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Schematics

watering and monitoring schematic

Code

Monitoring and watering code.

Arduino
Install on Arduino and hook up appropriately.
// Define LED's
const int sensor1redPin = 2;  // R petal on RGB LED module connected to digital pin 2
const int sensor1greenPin = 3;  // G petal on RGB LED module connected to digital pin 3
const int sensor1bluePin = 4;  // B petal on RGB LED module connected to digital pin 4
const int sensor2redPin = 7;  // R petal on RGB LED module connected to digital pin 5
const int sensor2greenPin = 6;  // G petal on RGB LED module connected to digital pin 6
const int sensor2bluePin = 5;  // B petal on RGB LED module connected to digital pin 7

// Define Motors
int motor1 = 9;
int motor2 = 10;

// declare sensors
int sensorValue1;
int sensorValue2;

// declare rates and delay.
int serialRate = 9600;
int loopDelay = 5000;

void setup() {
// set LED's
  pinMode(sensor1redPin, OUTPUT); // sets the redPin to be an output
  pinMode(sensor1greenPin, OUTPUT); // sets the greenPin to be an output
  pinMode(sensor1bluePin, OUTPUT); // sets the bluePin to be an output
  pinMode(sensor2redPin, OUTPUT); // sets the redPin to be an output
  pinMode(sensor2greenPin, OUTPUT); // sets the greenPin to be an output
  pinMode(sensor2bluePin, OUTPUT); // sets the bluePin to be an output
  
  pinMode(motor1, OUTPUT); // motor1
  pinMode(motor2, OUTPUT); // motor2
  
  Serial.begin(serialRate);  // initialize serial communication at 9600 bits per second:
}

void loop() {
// read the input on analog pin 0:
sensorValue1 = analogRead(A0); 
sensorValue2 = analogRead(A1);
Serial.print ("Sensor 1: ");
Serial.print(sensorValue1);
Serial.print("  Sensor 2: ");
Serial.println(sensorValue2);
if (sensorValue1 >= 400){
  // RED LIGHT SOLID
  Serial.println("Sensor 1 - Red");
  setLED1Color(255, 0, 0);
  digitalWrite(motor1, HIGH); // turn on Watering Motor
  delay(10000); // leave pump on for 5 seconds
  digitalWrite(motor1, LOW); // turn off motor.
}
if (sensorValue1 < 400){
  // GREEN LIGHT SOLID
  Serial.println("Sensor 1 - Green");
  setLED1Color(0,200, 0);
  // no motor activation
}
if (sensorValue2 >= 400){
  // RED LIGHT SOLID
  Serial.println("Sensor 2 - Red");
  setLED2Color(255, 0, 0);
  digitalWrite(motor2, HIGH); // turn on Watering Motor
  delay(10000); // leave pump on for 5 seconds
  digitalWrite(motor2, LOW); // turn off motor.
}
if (sensorValue2 < 400){
  // GREEN LIGHT SOLID
  Serial.println("Sensor 2 - Green");
  setLED2Color(0,200, 0);
  // no motor activation
}
delay(loopDelay);
}

void setLED1Color (unsigned char red, unsigned char green, unsigned char blue)     // the color generating function 
{   
  //Serial.println("LED1");
  analogWrite(sensor1redPin, red);  
  analogWrite(sensor1bluePin, blue);
  analogWrite(sensor1greenPin, green);
}
void setLED2Color (unsigned char red, unsigned char green, unsigned char blue)     // the color generating function 
{   
  //Serial.println("LED2");
  analogWrite(sensor2redPin, red);  
  analogWrite(sensor2bluePin, blue);
  analogWrite(sensor2greenPin, green);
}

// Basic colors: 
//color(255, 0, 0); // turn the RGB LED red
/*color(0,255, 255); // turn the RGB LED green 
color(0, 0, 255); // turn the RGB LED blue 
color(255,0,0); // turn the RGB LED red 
color(237,109,0); // turn the RGB LED orange 
color(255,215,0); // turn the RGB LED yellow 
color(34,139,34); // turn the RGB LED green 
color(0,0,255); // turn the RGB LED blue 
color(0,46,90); // turn the RGB LED  indigo
color(128,0,128); // turn the RGB LED purple 
*/

Updated (Better) Code

Arduino
// Define LED's
const int sensor1redPin = 2;  // R petal on RGB LED module connected to digital pin 2
const int sensor1greenPin = 3;  // G petal on RGB LED module connected to digital pin 3
const int sensor1bluePin = 4;  // B petal on RGB LED module connected to digital pin 4
const int sensor2redPin = 7;  // R petal on RGB LED module connected to digital pin 5
const int sensor2greenPin = 6;  // G petal on RGB LED module connected to digital pin 6
const int sensor2bluePin = 5;  // B petal on RGB LED module connected to digital pin 7

// Define Motors
int motor1 = 9;
int motor2 = 10;

// declare sensors
int sensorValue1;
int sensorValue2;

// declare rates and delay.
int serialRate = 9600;
unsigned long loopDelay = 3600000;
int wateringDuration = 20000;

void setup() {
// set LED's
  pinMode(sensor1redPin, OUTPUT); // sets the redPin to be an output
  pinMode(sensor1greenPin, OUTPUT); // sets the greenPin to be an output
  pinMode(sensor1bluePin, OUTPUT); // sets the bluePin to be an output
  pinMode(sensor2redPin, OUTPUT); // sets the redPin to be an output
  pinMode(sensor2greenPin, OUTPUT); // sets the greenPin to be an output
  pinMode(sensor2bluePin, OUTPUT); // sets the bluePin to be an output
  
  pinMode(motor1, OUTPUT); // motor1
  digitalWrite(motor1, LOW);
  pinMode(motor2, OUTPUT); // motor2
  digitalWrite(motor2, LOW);
  
  Serial.begin(serialRate);  // initialize serial communication at 9600 bits per second:
}

void loop() {
  Serial.println("Top of Loop");
  // safety measure turn motors off every loop  
  digitalWrite(motor1, LOW); // turn off Watering Motor
  digitalWrite(motor2, LOW); // turn off Watering Motor
  // DO Reads of Sensors
  Serial.println("Read Sensor 1");
  sensorValue1 = analogRead(1); 
  Serial.print ("Sensor 1: ");
  Serial.println(sensorValue1);
  if (sensorValue1 != 0 ) {
    setSensorColorAndRunMotor(1,sensorValue1);
  }
  Serial.println("Read Sensor 2");
  sensorValue2 = analogRead(2);
  Serial.print("  Sensor 2: ");
  Serial.println(sensorValue2);
  if (sensorValue2 != 0 ) {
    setSensorColorAndRunMotor(2,sensorValue2);
  }
  delay(loopDelay);
  Serial.println("Loop End");
}

String setSensorColorAndRunMotor(int intSensor, int intSensorValue){
  if (intSensorValue >= 400){
    // RED LIGHT SOLID
    if (intSensor == 1){
      analogWrite(sensor1redPin, 255);  
      analogWrite(sensor1bluePin, 0);
      analogWrite(sensor1greenPin, 0);
      digitalWrite(motor1, HIGH); // turn on Watering Motor
      Serial.println("Turning on Motor1");
      delay(wateringDuration);
      digitalWrite(motor1, LOW); // turn on Watering Motor
      Serial.println("Turning off Motor1");
    }
    if (intSensor == 2){
      analogWrite(sensor2redPin, 255);  
      analogWrite(sensor2bluePin, 0);
      analogWrite(sensor2greenPin, 0);
      digitalWrite(motor2, HIGH); // turn on Watering Motor
      Serial.println("Turning on Motor2");
      delay(wateringDuration);
      digitalWrite(motor2, LOW); // turn on Watering Motor
      Serial.println("Turning off Motor2");
    }
  }
  if (intSensorValue < 400){
    // GREEN LIGHT SOLID
    if (intSensor == 1){
      analogWrite(sensor1redPin, 0);  
      analogWrite(sensor1bluePin, 200);
      analogWrite(sensor1greenPin, 0);
      digitalWrite(motor1, LOW); // turn on Watering Motor
    }
    if (intSensor == 2){
      analogWrite(sensor2redPin, 0);  
      analogWrite(sensor2bluePin, 200);
      analogWrite(sensor2greenPin, 0);
      digitalWrite(motor2, LOW); // turn on Watering Motor
    }
  }
}

Credits

Rich Noordam

Rich Noordam

8 projects • 24 followers
Many interests, computing obviously being one of them.

Comments