Code for liquid level sensor

I'm not used to coding alot so wanted to know a code for Non - contact liquid level sensor. I have this code in which the sensor senses the liquid and if liquid is present it shows HIGH and if liquid is not present is shows LOW. I want output like if liquid is present then keep the motor on and if liquid is not present make motor off. Also i want to send this data through mavlink.

This is code:
int Liquid_level=0;
void setup() {
Serial.begin(9600);
pinMode(5,INPUT);
}

void loop() {
Liquid_level=digitalRead(5);
Serial.print("Liquid_level= ");
Serial.println(Liquid_level,DEC);
delay(1000);
}

Thanks in advance.

  if (Liquid_level == HIGH)
    motorOn();
  else
    motorOff();

Thanks! where should i paste this code like in which part.

In loop(), after you measure Liquid_level.

Okay thank u

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.