Relay moisture sensor issue

So im very very new to programming im trying to build an automatic watering system for my plants, so the moisture sensor works but i dont really know how to trigger with relay to fire the pump when the moisture sensor detects no water.

int msensor = A1;
int msvalue = 0;
int Relay = 8;
int val;
boolean flag = false;
void setup() {
Serial.begin(9600);
pinMode(msensor, INPUT);
pinMode(Relay, OUTPUT);
}

void loop() {
msvalue = analogRead(msensor);
Serial.println(msvalue);

if ( (msvalue >= 500 ) && ( flag == false ) )
{
digitalWrite(Relay, HIGH);
flag = true;
delay(1000);
}

if ( ( msvalue <= 300 ) && ( flag == true ) )
{
digitalWrite(Relay, LOW);
flag = false;
delay(1000);
}

val = analogRead(A1);{
if ( (msvalue <= 300 == LOW) ;
}
digitalWrite(13,LOW);
{
digitalWrite(13,HIGH);
}
delay(800);
{
}

delay(1000){;
}

This forum works best if you explain what results you are getting versus what results you expect.

This code

    if ( (msvalue <= 300 == LOW) ;

does nothing because of the misplaced semicolon.

Comparing to LOW is not so great either.

Please read the sticky post at the top of the forum about how to properly post your code using code tags. It helps people help you.

Doesn’t your code already turn the relay on/off? What part is not working

const int msensor = A1;
const int Relay = 8;

boolean relayOnFlag = false;

void setup() {
  Serial.begin(9600);
  pinMode(msensor, INPUT);
  pinMode(Relay, OUTPUT);
}

void loop() {
  int msvalue = analogRead(msensor);
  Serial.println(msvalue);

  if ( (msvalue >= 500 ) && ( relayOnFlag == false ) )
  {
    // turn relay on
    digitalWrite(Relay, HIGH);
    digitalWrite(13, HIGH);
    relayOnFlag = true;
    delay(1000);
  }

  if ( ( msvalue <= 300 ) && ( relayOnFlag == true ) )
  {
    // turn relay off
    digitalWrite(Relay, LOW);
    digitalWrite(13, LOW);
    relayOnFlag = false;
    delay(1000);
  }
}