Using a TFT to control a valve and display info from hall effect sensor

Okay, so I am COMPLETELY new to the Arduino and microcontrollers in general and have never written code before I took on this project. I’m currently working on having a TFT screen with buttons to open and close the valve and also to adjust the volume of liquid running through the flow sensor before the valve shuts on its own. So essentially the screen will have a start/stop button and a Gal/min live readout of the flow. the start/stop screen just opens and closes a valve. There will be another screen where you set the amount of fluid you want to dispense. So you would punch in like 5 gallons for example. Then, you would hit the start button and the valve would open to allow the water to flow until it hit 5 gallons, then it would automatically shut off. I have a feeling I’ll need to use interrupts, but I’m just unsure of how to write the sketch and research isn’t getting me far. Any help would be appreciated. I’ll include my sketch also.

As far as hardware goes I’m using an arduino uno, a 5v relay cube, a digiten FL-608 3/4" flow meter, and a 3.2" ITEAD Nextion TFT.

The Nextion TFT screens and buttons were programmed with the Nextion Software.

Again, I am a complete amateur, so try not to be too turned off by my code.

#include <SoftwareSerial.h>
#include <Nextion.h>

float value = 0; // value for amount to flow starts at 0
int valve=12;// valve goes on pin 12
int valveState;




SoftwareSerial nextion(2, 3);// Nextion TX to pin 2 and RX to pin 3 of Arduino

Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps


 
 
 void incAmt()
  { 
    value = (value+0.5);//add .5 to the value
    myNextion.setComponentText("t0", String(value));//change the value on Nextion
  }  

  void decAmt()
  {
    value = (value-0.5);//subtract .5 from the value
    myNextion.setComponentText("t0", String(value));//change the value on the Nextion
  }

  void startFlow()
  {
    digitalWrite(valve,HIGH);//set the valve high
    Serial.println(valveState);// and print whether the valve is high or low to the monitor
  }

  void stopFlow()
  {
    digitalWrite(valve,LOW);//set the valve low
    Serial.println(valveState);// and print whether the valve is high or low to the monitor
  }

  void setAmt()
  {
    myNextion.setComponentText("t0", String(value));//display the current value set for the amount
  }

  void backToSetAmtScreen()
  {
    myNextion.setComponentText("t0", String(value));//set the amt value to the current amt
  }

 
void setup() {
 
  pinMode(valve,OUTPUT);//valve pin is an output
  digitalWrite(valve,LOW);//valve pin starts out as low/shut
  Serial.begin(9600);//open communication with serial monitor through usb
  myNextion.init();//initialize connection with nextion screen
  myNextion.setComponentText("t0", String(value));//Set starting value for amt
  

}

void loop() {
 
  String message = myNextion.listen(); //check for message

  valveState=digitalRead(valve);//valveState set to current state of the valve pin(high or low)
  
  if(message !="")//if a message is received from nextion
  {
    Serial.println(message);//print message to serial monitor
  }
  if(message =="65 2 2 0 ffff ffff ffff")//if +.5 gallon button is pushed
  {
    incAmt();
  }
 
  if(message == "65 2 3 0 ffff ffff ffff")//if -.5 gallon button is pushed
  {
    decAmt();
  }

  if(message == "65 0 3 0 ffff ffff ffff" && (valveState==LOW))//if the start/stop button is pressed and the valve is currently low
  {
    startFlow();
  }
  
  if(message == "65 0 3 0 ffff ffff ffff"&& (valveState==HIGH))//if the stop/start button is pressed and the valve is currently high
  {
    stopFlow();
  }
  
  if(message=="65 1 3 0 ffff ffff ffff")// if the set amt button is pressed
  {
    setAmt();
  }
  
  if(message=="65 4 2 0 ffff ffff ffff")// if the back button is pressed from the enter amt screen
  {
    backToSetAmtScreen();
  }
}

I have a feeling I'll need to use interrupts

Maybe. Maybe not. It depends on what else the Arduino is doing while the fluid is flowing and just how accurately you need to meter the fluid.

int valve=12;// valve goes on pin 12

If the name were valvePin, the comment would be unnecessary.

Nextion myNextion(nextion, 9600);

Well, who else's would it be?

   value = (value+0.5);//add .5 to the value

The parentheses are unnecessary, as is the comment.

    Serial.println(valveState);// and print whether the valve is high or low to the monitor

But, god forbid that you should identify what the mysterious 0 or 1 means...

  void setAmt()
  {
    myNextion.setComponentText("t0", String(value));//display the current value set for the amount
  }

That function does NOT set anything.

  void backToSetAmtScreen()
  {
    myNextion.setComponentText("t0", String(value));//set the amt value to the current amt
  }

That function does no go back to a different screen.

  pinMode(valve,OUTPUT);//valve pin is an output
  digitalWrite(valve,LOW);//valve pin starts out as low/shut
  Serial.begin(9600);//open communication with serial monitor through usb
  myNextion.init();//initialize connection with nextion screen

Isurelikehowyouusespacestokeepthingsfromjustalljammingtogethermeaninglessly.

Besides that, what is the problem you need help with?

The comments, however simple they may be, help me remember what I was thinking while writing it. The smart-ass remarks you make are in no way helpful. As I said, I am completely new to this. Also, as I clearly stated in my original post, I am having trouble making the Arduino listen for messages from my Nextion screen while also constantly updating the rate of flow from my flow meter.