Does my code work? Please help

@van_der_decken is suggesting that you're storing a big number inappropriately. Changing to a smaller number is just a lazy way to avoid learning something that is fundamental to programming.

It's your call.

Alright, yeah. I will take your word for it if that is a fundamental concept. In my defense, I might have to repeat a school year if I don't get this thing working

If period = 3600000 won't millis always be < time_now + period? Except for when time_now + period rolls over before millis?

I see some other delays in the code, but I don't see anything that would slow it down enough to allow millis to catch up to time_now + period?

I got that from somewhere else. Changed it now

How about showing us your updated code? Perhaps there are further problems someone can point out.

No one's being tough on you - at the same time, no one wants to do your work for you. It's your coursework, and you should understand the changes that are being made - otherwise, we should get the credit, no?

I will, but I'm going to be moving onto other stuff. I don't know what was up with the values since they keep coming out as 300 and lower for some reason, and the println commands don't show up on my serial monitor

/*
 */
const int Pin_D1 = 8;
const int Hydro_D1 = 7; //hydro pump connect to plant of sensor 1

//Measure Soil Moisture Levels
int Value_D1;
int readPin = A0;

//Measure time
int delayTime = 100;
unsigned long period = 3600000;
unsigned long time_now = 0;

//Measure Water Level
int waterSensorPin = A1;
int waterValue;

//Water parameter
const int waterThreshold = 320; //value for low water

//Soil parameters
const int dryWall = 330; //value for dry soil
const int wetWall = 335; //value for wet soil

void setup() {
  Serial.begin(9600); //serial monitor
  pinMode(Pin_D1,OUTPUT); //soil moisture sensor 1
  pinMode(readPin,INPUT); //analog input pin
  pinMode(waterSensorPin,INPUT); //monitor water level
}

void loop(){
  time_now = millis ();
  
  nourishment();
  
  while(millis() - time_now < period){
   //wait approx. [period] ms
  }
}

void nourishment() {
  //PLANT ONE
  digitalWrite(Pin_D1,HIGH); //soil moisture sensor 1 ON
  delay(2000); //wait for voltage to settle
  Value_D1 = analogRead(readPin); //Read analog pin as sensor 1
  Serial.print(Value_D1);
  waterCheck();
  
  if (Value_D1 < dryWall) {
    digitalWrite(Hydro_D1,HIGH); //hydro pump 1 ON
    Value_D1 = analogRead(readPin);
    delay(delayTime);
    Serial.println("D1 =");
    Serial.print(Value_D1);
    waterCheck();
      } else if (Value_D1 < wetWall) {
          Value_D1 = analogRead(readPin);
          delay(delayTime);
          Serial.println("D1 =");
          Serial.print(Value_D1);
          waterCheck();
    }
  if (Value_D1 > wetWall) {
    digitalWrite(Hydro_D1,LOW);
      }
waterCheck();
delay(1000);
}

void waterCheck() {
  waterValue = analogRead(waterSensorPin);
  Serial.println("Water =");
  Serial.print(waterValue);
  if (waterValue < waterThreshold) {
    lowWater();
  }
}
  
void lowWater() {
  digitalWrite(Pin_D1,LOW);
  digitalWrite(Hydro_D1,LOW);
}

Looks like they should. Try putting one in setup() just in case the reason is the flow never passes through them as you code runs…

Did you select the baud rate in the serial monitor to match what you used in the Serial.begin() call?

a7

Yeah, I also changed the rate to see if anything would change, which it didn't. Unfortunately, I can't go test that out because it's late for that now, and next week is just final exams for me. Thank you for the suggestion though

Are you using IDE 2.3.9? I had strange struggles with getting Serial.print(); to work unless it was called after one second of delay. After I got Serial.println(); to work, I could call it immediately. Just saying... tinker with 'Serial.print();` It will eventually work (although it should work immediately).

Are you giving up? Did you turn anything in or just take the big goose egg for a grade?

Arduino cloud

Not really. I can't do any further testing since there isn't anymore time (my school year is ending next week, and its just final exams and graduation). Now I have to do a follow-up on my project

You do not give this pin a pinMode();... not saying it solves the print problem, but when I do not declare pinMode(); I can't accurately read from pins or write to pins...

watercheck() is called three times in the nourishment() function. You only need one.

Value_D1 = analogRead(readPin); is called three times in the nourishment() function. You only need one.

delay(delayTime); is called twice, but seems to not be of use, waiting 100ms between setting a pin and printing to the serial monitor.

On a scale of 0 to 1023, this is a very narrow window between "dry" and "wet."

//Soil parameters
const int dryWall = 330; //value for dry soil
const int wetWall = 335; //value for wet soil

This is a clever way to re-write delay(period)...

  time_now = millis ();
  nourishment();

  while (millis() - time_now < period) {
    //wait approx. [period] ms
  }

But using millis() like this might allow for expanding this sketch to read other devices or write to other devices while waiting for the next "period" to expire...

  if (millis() - time_now >= period) {
    time_now = millis();
    nourishment();
  }

I know, but that was what my serial monitor kept showing