Agriculture robotics

int rainPin = A0;
int greenLED = 6;
int redLED = 7;
// you can adjust the threshold value
int thresholdValue = 800;

void setup(){
  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
}

void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(rainPin);
  Serial.print(sensorValue);
  if(sensorValue < thresholdValue){
    Serial.println(" - Doesn't need watering");
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, HIGH);
  }
  else {
    Serial.println(" - Time to water your plant");
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
  }
  delay(500);
}

int WATERPUMP = 13; //motor pump connected to pin 13
int sensor = 8; //sensor digital pin vonnected to pin 8
int val; //This variable stores the value received from Soil moisture sensor.

void setup() {
  
  pinMode(13,OUTPUT); //Set pin 13 as OUTPUT pin
  pinMode(8,INPUT); //Set pin 8 as input pin, to receive data from Soil moisture sensor.
  //Initialize serial and wait for port to open:
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  while (! Serial);// wait for serial port to connect. Needed for native USB
  Serial.println("Speed 0 to 255");
}

void loop()
  { 
  if (Serial.available()) //loop to operate motor
  {
    int speed = Serial.parseInt(); // to read the number entered as text in the Serial Monitor 
    if (speed >= 0 && speed <= 255)
    {
      analogWrite(WATERPUMP, speed);// tuns on the motor at specified speed 
    }
  }
  val = digitalRead(8);  //Read data from soil moisture sensor  
  if(val == LOW) 
  {
  digitalWrite(13,LOW); //if soil moisture sensor provides LOW value send LOW value to motor pump and motor pump goes off
  }
  else
  {
  digitalWrite(13,HIGH); //if soil moisture sensor provides HIGH value send HIGH value to motor pump and motor pump get on
  }
  delay(400); //Wait for few second and then continue the loop.
}

int sensor_pin =A0; //Soil Sensor input at Analog PIN A0
int output_value;
void setup() // put your setup code here, to run once
{
pinMode(4,OUTPUT);
Serial.begin(9600);
Serial.println(“Reading From the Sensor…”);
delay(2000);
}borderbr

//put your main code here,to run repeatedly:
void loop()
{
output_value= analogRead(sensor_pin);
output_value=map(output_value,500,10,0,100);
Serial.print(“Moisture :”);
Serial.print(output_value) ;
Serial.println(“%”);

if(output_value<0)
{
digitalWrite(4,HIGH);
}
else
{
digitalWrite(4,LOW);
}
delay(1000);
}

Watering plants with relay
Smart watering system
Article collection on agriculture robotics