Will my code work if I use a nested millis statement?

For my project, I wanted to make an automatic valve that can also display the moisture level of the garden, so to open the valve, I used a millis statement, but I also used a millis statement to let the arduino know when the valve should open, would this work?

#include <LiquidCrystal.h>
const int Uno_to_relay = 8;
const int Sensor_to_Uno = A0;
const int Button_Pin = 6;
const int LED_Pin = 7;
int Relay_boi = LOW;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

int value_to_the_MAX = 1023;
int value_to_the_MIN = 0;
int value_of_sensor = 0;
int sensor_val = 0;

unsigned long Timebefore = 0;
long time_in_between = 7200000;
int Preactivated_water = 0;
unsigned long time_for_delay = 0;
long mrbean_waters = 10000;

void setup() {
  Serial.begin (9600);

  lcd.begin(16, 2);
  lcd.clear();

  pinMode(Sensor_to_Uno, INPUT);
  pinMode(Uno_to_relay, OUTPUT);
}
void loop() {
  while (digitalRead(Button_Pin) == HIGH) {
    calibrate();
  }
  digitalWrite(LED_Pin, LOW);
  value_of_sensor = analogRead(Sensor_to_Uno);
  value_of_sensor = map(value_of_sensor, value_to_the_MIN, value_to_the_MAX, 0, 255);
  value_of_sensor = constrain(value_of_sensor, 0, 255);
  analogWrite(LED_Pin, value_of_sensor);

  lcd.setCursor(0, 0);
  lcd.print("Water_level: ");
  lcd.print(analogRead(value_of_sensor));

  Serial.print("Water level: ");
  Serial.println(value_of_sensor);

  unsigned long Time = millis();
  unsigned long Activated_water = millis();
  unsigned long Time_now_for_delay = millis();
  if (Time - Timebefore >= time_in_between) {
    Timebefore = Time;
    if (Activated_water - Preactivated_water >= mrbean_waters) {
      Preactivated_water = Activated_water;
      if (Relay_boi == LOW) {
        Relay_boi == HIGH;
      }
      else {
        Relay_boi == LOW;
      }
    }
  }

}
void calibrate() {
  digitalWrite(LED_Pin, HIGH);
  value_of_sensor = analogRead(Sensor_to_Uno);
  if (value_of_sensor > value_to_the_MAX) {
    value_of_sensor = value_to_the_MAX;
  }
  if (value_of_sensor < value_to_the_MIN) {
    value_of_sensor = value_to_the_MIN;
  }
}

edit: I changed the code a bit

“would this work?”

What result did you get when you tested this?

Good point let me do that

The result I got was that the valve wouldn't open, I got the smell of something burning, the lcd wouldn't print the sensor values, and the relay did work, I heard a click, but that was also about the same time I smelled something burning, so either I messed up the code, or the valve is broken, and I shouldn't use 12v to power it.

Or a wiring problem, or a design problem.

Show us a good schematic of your circuit.
Show us a good image of your wiring.
Give links to components.
Posting images:

I am sorry but I didn't make a schematic, and this project is already due tomorrow, so there really isn't too much hope of completing it on time. I will attempt to make a schematic anyways since I still want to complete this project. I hope to get the schematic finished by tomorrow if this post doesn't get lost.

The smell of something burning is indicative of a wiring/circuit error, and should be the first thing you look into.

Get your display to work first - in a separate sketch.

I see a very large "timeinbetween" value - reduce that for testing to something you can sensibly wait out (1-2 minutes or so).

I am sorry but I didn't make a schematic, and this project is already due tomorrow, so there really isn't too much hope of completing it on time. I will attempt to make a schematic anyways since I still want to complete this project. I hope to get the schematic finished by tomorrow if this post doesn't get lost.

Just draw your circuit diagram on a piece of paper, then take a picture of it.

There is a link to all your posts on your profile page, so they will never get lost.

Getting millis() wrong will not cause a burning smell.

And please don't go back and change code (or text) after people have read it. Just put the changes in a new Reply in the proper chronological order so the Thread makes sense when read from top to bottom.

...R

Robin2:
Getting millis() wrong will not cause a burning smell.

well, there are ways to can accieve this :wink:

Idkicecream:
The result I got was that the valve wouldn't open, I got the smell of something burning, the lcd wouldn't print the sensor values, and the relay did work, I heard a click, but that was also about the same time I smelled something burning, so either I messed up the code, or the valve is broken, and I shouldn't use 12v to power it.

the 12 volts to power a relay is not a problem. but you must make sure the power supplies are not connected on the power side. they may be connected on the grounds if they need to be.
a simple hand sketch works miracles
a photo of your project can sometimes work as well.
however at this late hour, it would appear you are committed to the path you are on.
I hope you figured it out and all goes well.